|
10 | 10 | module Concurrent |
11 | 11 | extend Concern::Logging |
12 | 12 |
|
13 | | - autoload :Options, 'concurrent/options' |
14 | | - autoload :TimerSet, 'concurrent/executor/timer_set' |
| 13 | + autoload :Options, 'concurrent/options' |
| 14 | + autoload :TimerSet, 'concurrent/executor/timer_set' |
15 | 15 | autoload :ThreadPoolExecutor, 'concurrent/executor/thread_pool_executor' |
16 | 16 |
|
17 | 17 | # @return [Logger] Logger with provided level and output. |
18 | | - def self.create_stdlib_logger(level = Logger::FATAL, output = $stderr) |
19 | | - logger = Logger.new(output) |
20 | | - logger.level = level |
21 | | - logger.formatter = lambda do |severity, datetime, progname, msg| |
22 | | - formatted_message = case msg |
| 18 | + def self.create_simple_logger(level = Logger::FATAL, output = $stderr) |
| 19 | + # TODO (pitr-ch 24-Dec-2016): figure out why it had to be replaced, stdlogger was deadlocking |
| 20 | + lambda do |severity, progname, message = nil, &block| |
| 21 | + return false if severity < level |
| 22 | + |
| 23 | + message = block ? block.call : message |
| 24 | + formatted_message = case message |
23 | 25 | when String |
24 | | - msg |
| 26 | + message |
25 | 27 | when Exception |
26 | 28 | format "%s (%s)\n%s", |
27 | | - msg.message, msg.class, (msg.backtrace || []).join("\n") |
| 29 | + message.message, message.class, (message.backtrace || []).join("\n") |
28 | 30 | else |
29 | | - msg.inspect |
| 31 | + message.inspect |
30 | 32 | end |
31 | | - format "[%s] %5s -- %s: %s\n", |
32 | | - datetime.strftime('%Y-%m-%d %H:%M:%S.%L'), |
33 | | - severity, |
34 | | - progname, |
35 | | - formatted_message |
36 | | - end |
37 | 33 |
|
38 | | - lambda do |loglevel, progname, message = nil, &block| |
39 | | - logger.add loglevel, message, progname, &block |
| 34 | + output.print format "[%s] %5s -- %s: %s\n", |
| 35 | + Time.now.strftime('%Y-%m-%d %H:%M:%S.%L'), |
| 36 | + Logger::SEV_LABEL[severity], |
| 37 | + progname, |
| 38 | + formatted_message |
| 39 | + true |
40 | 40 | end |
41 | 41 | end |
42 | 42 |
|
43 | | - # Use logger created by #create_stdlib_logger to log concurrent-ruby messages. |
44 | | - def self.use_stdlib_logger(level = Logger::FATAL, output = $stderr) |
45 | | - Concurrent.global_logger = create_stdlib_logger level, output |
| 43 | + # Use logger created by #create_simple_logger to log concurrent-ruby messages. |
| 44 | + def self.use_simple_logger(level = Logger::FATAL, output = $stderr) |
| 45 | + Concurrent.global_logger = create_simple_logger level, output |
46 | 46 | end |
47 | 47 |
|
48 | 48 | # Suppresses all output when used for logging. |
49 | 49 | NULL_LOGGER = lambda { |level, progname, message = nil, &block| } |
50 | 50 |
|
51 | 51 | # @!visibility private |
52 | | - GLOBAL_LOGGER = AtomicReference.new(create_stdlib_logger(Logger::WARN)) |
| 52 | + GLOBAL_LOGGER = AtomicReference.new(create_simple_logger(Logger::WARN)) |
53 | 53 | private_constant :GLOBAL_LOGGER |
54 | 54 |
|
55 | 55 | def self.global_logger |
@@ -131,23 +131,23 @@ def self.executor(executor_identifier) |
131 | 131 |
|
132 | 132 | def self.new_fast_executor(opts = {}) |
133 | 133 | FixedThreadPool.new( |
134 | | - [2, Concurrent.processor_count].max, |
135 | | - auto_terminate: opts.fetch(:auto_terminate, true), |
136 | | - idletime: 60, # 1 minute |
137 | | - max_queue: 0, # unlimited |
138 | | - fallback_policy: :abort # shouldn't matter -- 0 max queue |
| 134 | + [2, Concurrent.processor_count].max, |
| 135 | + auto_terminate: opts.fetch(:auto_terminate, true), |
| 136 | + idletime: 60, # 1 minute |
| 137 | + max_queue: 0, # unlimited |
| 138 | + fallback_policy: :abort # shouldn't matter -- 0 max queue |
139 | 139 | ) |
140 | 140 | end |
141 | 141 |
|
142 | 142 | def self.new_io_executor(opts = {}) |
143 | 143 | ThreadPoolExecutor.new( |
144 | | - min_threads: [2, Concurrent.processor_count].max, |
145 | | - max_threads: ThreadPoolExecutor::DEFAULT_MAX_POOL_SIZE, |
146 | | - # max_threads: 1000, |
147 | | - auto_terminate: opts.fetch(:auto_terminate, true), |
148 | | - idletime: 60, # 1 minute |
149 | | - max_queue: 0, # unlimited |
150 | | - fallback_policy: :abort # shouldn't matter -- 0 max queue |
| 144 | + min_threads: [2, Concurrent.processor_count].max, |
| 145 | + max_threads: ThreadPoolExecutor::DEFAULT_MAX_POOL_SIZE, |
| 146 | + # max_threads: 1000, |
| 147 | + auto_terminate: opts.fetch(:auto_terminate, true), |
| 148 | + idletime: 60, # 1 minute |
| 149 | + max_queue: 0, # unlimited |
| 150 | + fallback_policy: :abort # shouldn't matter -- 0 max queue |
151 | 151 | ) |
152 | 152 | end |
153 | 153 | end |
0 commit comments