Class: Concurrent::Configuration
- Inherits:
-
Object
- Object
- Concurrent::Configuration
- Defined in:
- lib/concurrent/configuration.rb
Overview
A gem-level configuration object.
Instance Attribute Summary collapse
-
#auto_terminate ⇒ Object
defines if executors should be auto-terminated in at_exit callback.
-
#logger ⇒ Object
a proc defining how to log messages, its interface has to be: lambda { |level, progname, message = nil, &block| _ }.
Instance Method Summary collapse
-
#global_operation_pool ⇒ ThreadPoolExecutor
Global thread pool optimized for long operations.
-
#global_operation_pool=(executor) ⇒ ThreadPoolExecutor
Global thread pool optimized for long operations.
-
#global_task_pool ⇒ ThreadPoolExecutor
Global thread pool optimized for short tasks.
-
#global_task_pool=(executor) ⇒ ThreadPoolExecutor
Global thread pool optimized for short tasks.
-
#global_timer_set ⇒ ThreadPoolExecutor
Global thread pool optimized for timers.
-
#initialize ⇒ Configuration
constructor
Create a new configuration object.
- #new_operation_pool ⇒ Object
- #new_task_pool ⇒ Object
-
#no_logger ⇒ Object
if assigned to #logger, it will log nothing.
Constructor Details
#initialize ⇒ Configuration
Create a new configuration object.
24 25 26 27 28 29 30 31 |
# File 'lib/concurrent/configuration.rb', line 24 def initialize immediate_executor = ImmediateExecutor.new @global_task_pool = Delay.new(executor: immediate_executor) { new_task_pool } @global_operation_pool = Delay.new(executor: immediate_executor) { new_operation_pool } @global_timer_set = Delay.new(executor: immediate_executor) { Concurrent::TimerSet.new } @logger = no_logger @auto_terminate = true end |
Instance Attribute Details
#auto_terminate ⇒ Object
defines if executors should be auto-terminated in at_exit callback
21 22 23 |
# File 'lib/concurrent/configuration.rb', line 21 def auto_terminate @auto_terminate end |
#logger ⇒ Object
a proc defining how to log messages, its interface has to be:
lambda { |level, progname, = nil, &block| _ }
18 19 20 |
# File 'lib/concurrent/configuration.rb', line 18 def logger @logger end |
Instance Method Details
#global_operation_pool ⇒ ThreadPoolExecutor
Global thread pool optimized for long operations.
48 49 50 |
# File 'lib/concurrent/configuration.rb', line 48 def global_operation_pool @global_operation_pool.value end |
#global_operation_pool=(executor) ⇒ ThreadPoolExecutor
Global thread pool optimized for long operations.
A global thread pool must be set as soon as the gem is loaded. Setting a new thread pool once tasks and operations have been post can lead to unpredictable results. The first time a task/operation is post a new thread pool will be created using the default configuration. Once set the thread pool cannot be changed. Thus, explicitly setting the thread pool must occur before any tasks/operations are post else an exception will be raised.
94 95 96 97 |
# File 'lib/concurrent/configuration.rb', line 94 def global_operation_pool=(executor) @global_operation_pool.reconfigure { executor } or raise ConfigurationError.new('global operation pool was already set') end |
#global_task_pool ⇒ ThreadPoolExecutor
Global thread pool optimized for short tasks.
41 42 43 |
# File 'lib/concurrent/configuration.rb', line 41 def global_task_pool @global_task_pool.value end |
#global_task_pool=(executor) ⇒ ThreadPoolExecutor
Global thread pool optimized for short tasks.
A global thread pool must be set as soon as the gem is loaded. Setting a new thread pool once tasks and operations have been post can lead to unpredictable results. The first time a task/operation is post a new thread pool will be created using the default configuration. Once set the thread pool cannot be changed. Thus, explicitly setting the thread pool must occur before any tasks/operations are post else an exception will be raised.
75 76 77 78 |
# File 'lib/concurrent/configuration.rb', line 75 def global_task_pool=(executor) @global_task_pool.reconfigure { executor } or raise ConfigurationError.new('global task pool was already set') end |
#global_timer_set ⇒ ThreadPoolExecutor
Global thread pool optimized for timers
57 58 59 |
# File 'lib/concurrent/configuration.rb', line 57 def global_timer_set @global_timer_set.value end |
#new_operation_pool ⇒ Object
109 110 111 112 113 114 115 116 117 |
# File 'lib/concurrent/configuration.rb', line 109 def new_operation_pool Concurrent::ThreadPoolExecutor.new( min_threads: [2, Concurrent.processor_count].max, max_threads: [2, Concurrent.processor_count].max, idletime: 10 * 60, # 10 minutes max_queue: [20, Concurrent.processor_count * 15].max, overflow_policy: :abort # raise an exception ) end |
#new_task_pool ⇒ Object
99 100 101 102 103 104 105 106 107 |
# File 'lib/concurrent/configuration.rb', line 99 def new_task_pool Concurrent::ThreadPoolExecutor.new( min_threads: [2, Concurrent.processor_count].max, max_threads: [20, Concurrent.processor_count * 15].max, idletime: 2 * 60, # 2 minutes max_queue: 0, # unlimited overflow_policy: :abort # raise an exception ) end |
#no_logger ⇒ Object
if assigned to #logger, it will log nothing.
34 35 36 |
# File 'lib/concurrent/configuration.rb', line 34 def no_logger lambda { |level, progname, = nil, &block| } end |