Created
November 3, 2012 18:10
-
-
Save pjb3/4008160 to your computer and use it in GitHub Desktop.
I'm wondering why Celluloid/Sidekiq is more efficient than just doing this, having one Thread per worker
This file contains hidden or 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
require 'json' | |
require 'redis' | |
redis = Redis.new | |
60.times do | |
redis.rpush "queue", ["Kernel", "sleep", 1].to_json | |
end |
This file contains hidden or 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
require 'json' | |
require 'redis' | |
ARGV[0].to_i.times.map do |n| | |
Thread.new do | |
redis = Redis.new | |
while payload = redis.blpop("queue") | |
queue, job = payload | |
class_name, message, *args = JSON.parse(job) | |
object = Object.const_get(class_name) | |
puts "Thread #{n}: #{object}.#{message}(#{args.map(&:inspect).join(', ')})" | |
object.send(message, *args) | |
end | |
end | |
end.each(&:join) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment