Skip to content

Instantly share code, notes, and snippets.

@pangloss
Created April 9, 2012 09:36
Show Gist options
  • Save pangloss/2342518 to your computer and use it in GitHub Desktop.
Save pangloss/2342518 to your computer and use it in GitHub Desktop.
Worker pool does not limit the number of workers created
require 'celluloid'
class Counter
include Celluloid::Worker
def count
len = rand(1000)
Celluloid::Actor[:min].result len
len
end
end
class Min
include Celluloid
attr_reader :min
def result(n)
@min ||= n
@min = n if n < @min
end
end
pool = Counter.pool
min = Min.new
Celluloid::Actor[:min] = min
Celluloid::Actor[:pool] = pool
puts "Number of actors: #{ Celluloid::Actor.all.length }"
50.times {
pool.count!
}
sleep 1
puts "Number of actors: #{ Celluloid::Actor.all.length }"
100.times {
pool.count!
}
sleep 3
puts "Number of actors: #{ Celluloid::Actor.all.length }"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment