Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Run in continuous loop. Write messages 1/sec by default

  • Loading branch information...
commit 98675111e6930069edccc059e2616fea5cfd4991 1 parent 2909ce7
@rwdaigle rwdaigle authored
Showing with 12 additions and 15 deletions.
  1. +1 −0  .rvmrc
  2. +11 −15 writer.rb
View
1  .rvmrc
@@ -0,0 +1 @@
+rvm use ruby-1.9.2@demo.tractorpush-writer --create
View
26 writer.rb
@@ -37,11 +37,11 @@
require 'mongo'
require 'pp'
-uristring = ENV['MONGOLAB_URI'] || 'mongodb://localhost/testdatabase'
-debug = ENV['WRITER_DEBUG'] || "false"
-rate = ENV['WRITER_RATE'].to_f
-if (rate = 0.0) then rate = 10.0 end
+STDOUT.sync = true # Write in real-time
+uristring = ENV['MONGOLAB_URI'] || 'mongodb://localhost/testdatabase'
+debug = ENV['WRITER_DEBUG'] ? ENV['WRITER_DEBUG'] == "true" : false
+rate = ENV['WRITER_RATE'] ? ENV['WRITER_RATE'].to_i : 1 # Every second, write a message
uri = URI.parse(uristring)
conn = Mongo::Connection.from_uri(uristring)
@@ -53,17 +53,13 @@
{'messagetype' => 'array', 'ordinal' => 0, 'somearray' => ['a', 'b', 'c', 'd']},
{'messagetype' => 'complex', 'ordinal' =>0, 'subdocument' => {'fname' => 'George', 'lname' => 'Washington', 'subproperty' => 'US-president'}}]
-
-count = 500
-print("starting insertion of ", count, " documents into ", uri.scheme, "://", uri.host, uri.path, "\n")
-for i in 1..count
+# Run until killed
+i = 0
+while(true)
doc = docs[rand(3)].dup # MongoDB collection.insert mutates document, editing the _id key; we need a deep dup (copy).
doc['time'] = Time.now().to_f * 1000 # Switch to Javascript's convention
- doc['ordinal'] = i
+ doc['ordinal'] = i + 1
coll.insert(doc, :safe => true)
- if (debug == "true") then pp (doc) end
- sleep(1.0/rate)
-end
-
-print("Finished. Inserted ", count, " messages.\n")
-
+ debug ? pp(doc) : puts("Inserting #{doc['messagetype']} message")
+ sleep(rate)
+end
Please sign in to comment.
Something went wrong with that request. Please try again.