Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

headslap. am in Ruby.

  • Loading branch information...
commit 167feb6a1b68d9cf678fd6c410ad495cf652c361 1 parent d0041b1
@benzenwen benzenwen authored
Showing with 8 additions and 2 deletions.
  1. +8 −2 writer.rb
View
10 writer.rb
@@ -79,12 +79,18 @@
{'messagetype' => 'complex', 'ordinal' =>0, 'subdocument' => {'fname' => 'George', 'lname' => 'Washington', 'subproperty' => 'US-president'}}]
# Run until killed
-i = 0
+i = 1
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
+ print i
coll.insert(doc, :safe => true)
debug ? pp(doc) : puts("Inserting #{doc['messagetype']} message")
sleep(rate)
+ if i == 2**30 -1 then # Not like we'll ever hit this at 1/sec, but someone could crank up the speed.
+ i = 1 else
+ i = i + 1
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.