Class: Concurrent::Configuration
- Inherits:
-
Object
- Object
- Concurrent::Configuration
- Defined in:
- lib/concurrent/configuration.rb
Overview
A gem-level configuration object.
Instance Attribute Summary collapse
-
#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.
19 20 21 22 23 24 |
# File 'lib/concurrent/configuration.rb', line 19 def initialize @global_task_pool = Delay.new { new_task_pool } @global_operation_pool = Delay.new { new_operation_pool } @global_timer_set = Delay.new { Concurrent::TimerSet.new } @logger = no_logger end |
Instance Attribute Details
#logger ⇒ Object
a proc defining how to log messages, its interface has to be:
lambda { |level, progname, = nil, &block| _ }
16 17 18 |
# File 'lib/concurrent/configuration.rb', line 16 def logger @logger end |
Instance Method Details
#global_operation_pool ⇒ ThreadPoolExecutor
Global thread pool optimized for long operations.
41 42 43 |
# File 'lib/concurrent/configuration.rb', line 41 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.
87 88 89 90 |
# File 'lib/concurrent/configuration.rb', line 87 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.
34 35 36 |
# File 'lib/concurrent/configuration.rb', line 34 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.
68 69 70 71 |
# File 'lib/concurrent/configuration.rb', line 68 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
50 51 52 |
# File 'lib/concurrent/configuration.rb', line 50 def global_timer_set @global_timer_set.value end |
#new_operation_pool ⇒ Object
102 103 104 105 106 107 108 109 110 |
# File 'lib/concurrent/configuration.rb', line 102 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
92 93 94 95 96 97 98 99 100 |
# File 'lib/concurrent/configuration.rb', line 92 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.
27 28 29 |
# File 'lib/concurrent/configuration.rb', line 27 def no_logger lambda { |level, progname, = nil, &block| } end |