Class: RedisClient::Cluster::ConcurrentWorker::Pooled
- Inherits:
-
Object
- Object
- RedisClient::Cluster::ConcurrentWorker::Pooled
- Defined in:
- lib/redis_client/cluster/concurrent_worker/pooled.rb
Overview
This class is just an experimental implementation. Ruby VM allocates 1 MB memory as a stack for a thread. It is a fixed size but we can modify the size with some environment variables. So it consumes memory 1 MB multiplied a number of workers.
Instance Method Summary collapse
- #close ⇒ Object
-
#initialize(size:) ⇒ Pooled
constructor
A new instance of Pooled.
- #inspect ⇒ Object
- #new_group(size:) ⇒ Object
- #push(task) ⇒ Object
Constructor Details
#initialize(size:) ⇒ Pooled
Returns a new instance of Pooled.
17 18 19 20 21 22 |
# File 'lib/redis_client/cluster/concurrent_worker/pooled.rb', line 17 def initialize(size:) raise ArgumentError, "size must be positive: #{size}" unless size.positive? @size = size setup end |
Instance Method Details
#close ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/redis_client/cluster/concurrent_worker/pooled.rb', line 38 def close @q.clear workers = @workers.compact workers.each(&:exit) workers.each(&:join) @workers.clear @q.close @pid = nil nil end |
#inspect ⇒ Object
49 50 51 |
# File 'lib/redis_client/cluster/concurrent_worker/pooled.rb', line 49 def inspect "#<#{self.class.name} tasks: #{@q.size}, workers: #{@size}>" end |
#new_group(size:) ⇒ Object
24 25 26 27 28 29 30 31 32 |
# File 'lib/redis_client/cluster/concurrent_worker/pooled.rb', line 24 def new_group(size:) reset if @pid != ::RedisClient::PIDCache.pid ensure_workers if @workers.first.nil? ::RedisClient::Cluster::ConcurrentWorker::Group.new( worker: self, queue: SizedQueue.new(size), size: size ) end |
#push(task) ⇒ Object
34 35 36 |
# File 'lib/redis_client/cluster/concurrent_worker/pooled.rb', line 34 def push(task) @q << task end |