Skip to content

Instantly share code, notes, and snippets.

@deepfryed
Created May 16, 2011 02:27
Show Gist options
  • Save deepfryed/973820 to your computer and use it in GitHub Desktop.
Save deepfryed/973820 to your computer and use it in GitHub Desktop.
bean counter
#!/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