Class: Eventbox::ThreadPool
- Defined in:
- lib/eventbox/thread_pool.rb
Overview
A pool of reusable threads for actions
By default each call of an action method spawns a new thread and terminates the thread when the action is finished. If there are many short lived action calls, creation and termination of threads can be a bottleneck. In this case it is desireable to reuse threads for multiple actions. This is what a threadpool is made for.
A threadpool creates a fixed number of threads at startup and distributes all action calls to free threads. If no free thread is available, the request in enqueued and processed in order.
It is possible to use one threadpool for several Eventbox derivations and Eventbox instances at the same time. However using a threadpool adds the risk of deadlocks, if actions depend of each other and the threadpool provides too less threads. A threadpool can slow actions down, if too less threads are allocated, so that actions are enqueued. On the other hand a threadpool can also slow processing down, if the threadpool allocates many threads at startup, but doesn’t makes use of them.
An Eventbox with associated ThreadPool can be created per with_options. num_threads
is the number of allocated threads:
EventboxWithThreadpool = Eventbox.(threadpool: Eventbox::ThreadPool.new(num_threads))
Defined Under Namespace
Classes: AbortAction, PoolThread
Constant Summary
Constants inherited from Eventbox
Instance Method Summary collapse
Methods inherited from Eventbox
#async_proc, #call_context, eventbox_options, #init, #new_action_call_context, #shared_object, #shutdown!, #sync_proc, #with_call_context, with_options, #yield_proc, #€
Methods included from Boxable
#action, #async_call, #attr_accessor, #attr_reader, #attr_writer, #sync_call, #yield_call
Instance Method Details
#inspect ⇒ Object
176 177 178 |
# File 'lib/eventbox/thread_pool.rb', line 176 def inspect "#<#{self.class}:#{self.object_id} @requests=#{@requests.length} @jobless=#{@jobless.length} @run_gc_when_busy=#{@run_gc_when_busy.inspect}>" end |