Created
May 16, 2011 02:27
-
-
Save deepfryed/973820 to your computer and use it in GitHub Desktop.
bean counter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/ruby | |
require 'bundler' | |
Bundler.setup(:default) | |
require 'yajl' | |
require 'beanstalk-client' | |
jobs = 100_000 | |
prod = Thread.new do | |
client = Beanstalk::Pool.new(['127.0.0.1:11300']) | |
client.use(:test) | |
n = jobs | |
while n > 0 | |
client.put(Yajl.dump({job: n})) | |
n -= 1 | |
end | |
end | |
cons = Thread.new do | |
client = Beanstalk::Pool.new(['127.0.0.1:11300']) | |
client.watch(:test) | |
while job = client.reserve | |
Yajl.load(job.body).inspect | |
end | |
end | |
now = Time.now | |
while prod.alive? | |
sleep 1 | |
end | |
elapsed = Time.now.to_f - now.to_f | |
puts 'elapsed: %.4f, rate: %.2f' % [elapsed, jobs/elapsed] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment