Class: RedisClient::Cluster::ConcurrentWorker::Pooled

Inherits:
Object
  • Object
show all
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

Constructor Details

#initialize(size:) ⇒ Pooled

Returns a new instance of Pooled.



13
14
15
16
# File 'lib/redis_client/cluster/concurrent_worker/pooled.rb', line 13

def initialize(size:)
  @size = size
  setup
end

Instance Method Details

#closeObject



32
33
34
35
36
37
38
39
# File 'lib/redis_client/cluster/concurrent_worker/pooled.rb', line 32

def close
  @q.clear
  @workers.each { |t| t&.exit }
  @workers.clear
  @q.close
  @pid = nil
  nil
end

#inspectObject



41
42
43
# File 'lib/redis_client/cluster/concurrent_worker/pooled.rb', line 41

def inspect
  "#<#{self.class.name} tasks: #{@q.size}, workers: #{@size}>"
end

#new_group(size:) ⇒ Object



18
19
20
21
22
23
24
25
26
# File 'lib/redis_client/cluster/concurrent_worker/pooled.rb', line 18

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



28
29
30
# File 'lib/redis_client/cluster/concurrent_worker/pooled.rb', line 28

def push(task)
  @q << task
end