Skip to content

Commit f1e610e

Browse files
authored
Merge pull request rails#54354 from joshuay03/name-all-thread-pool-executors
Add names to all `Concurrent::ThreadPoolExecutor`s
2 parents 2ca006f + 7629dd1 commit f1e610e

File tree

6 files changed

+21
-4
lines changed

6 files changed

+21
-4
lines changed

actioncable/lib/action_cable/connection/stream_event_loop.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ def spawn
6868
@nio ||= NIO::Selector.new
6969

7070
@executor ||= Concurrent::ThreadPoolExecutor.new(
71+
name: "ActionCable-streamer",
7172
min_threads: 1,
7273
max_threads: 10,
7374
max_queue: 0,

actioncable/lib/action_cable/server/worker.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ class Worker # :nodoc:
2020

2121
def initialize(max_size: 5)
2222
@executor = Concurrent::ThreadPoolExecutor.new(
23-
name: "ActionCable",
23+
name: "ActionCable-server",
2424
min_threads: 1,
2525
max_threads: max_size,
2626
max_queue: 0,

activejob/lib/active_job/queue_adapters/async_adapter.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,11 @@ class Scheduler # :nodoc:
8686
def initialize(**options)
8787
self.immediate = false
8888
@immediate_executor = Concurrent::ImmediateExecutor.new
89-
@async_executor = Concurrent::ThreadPoolExecutor.new(DEFAULT_EXECUTOR_OPTIONS.merge(options))
89+
@async_executor = Concurrent::ThreadPoolExecutor.new(
90+
name: "ActiveJob-async-scheduler",
91+
**DEFAULT_EXECUTOR_OPTIONS,
92+
**options
93+
)
9094
end
9195

9296
def enqueue(job, queue_name:)

activerecord/lib/active_record.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -288,6 +288,7 @@ def self.db_warnings_action=(action)
288288
def self.global_thread_pool_async_query_executor # :nodoc:
289289
concurrency = global_executor_concurrency || 4
290290
@global_thread_pool_async_query_executor ||= Concurrent::ThreadPoolExecutor.new(
291+
name: "ActiveRecord-global-async-query-executor",
291292
min_threads: 0,
292293
max_threads: concurrency,
293294
max_queue: concurrency * 4,

activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,8 +276,8 @@ def initialize(pool_config)
276276
end
277277

278278
def inspect # :nodoc:
279-
name_field = " name=#{db_config.name.inspect}" unless db_config.name == "primary"
280-
shard_field = " shard=#{@shard.inspect}" unless @shard == :default
279+
name_field = " name=#{name_inspect}" if name_inspect
280+
shard_field = " shard=#{shard_inspect}" if shard_inspect
281281

282282
"#<#{self.class.name} env_name=#{db_config.env_name.inspect}#{name_field} role=#{role.inspect}#{shard_field}>"
283283
end
@@ -715,7 +715,9 @@ def build_async_executor
715715
case ActiveRecord.async_query_executor
716716
when :multi_thread_pool
717717
if @db_config.max_threads > 0
718+
name_with_shard = [name_inspect, shard_inspect].join("-").tr("_", "-")
718719
Concurrent::ThreadPoolExecutor.new(
720+
name: "ActiveRecord-#{name_with_shard}-async-query-executor",
719721
min_threads: @db_config.min_threads,
720722
max_threads: @db_config.max_threads,
721723
max_queue: @db_config.max_queue,
@@ -949,6 +951,14 @@ def checkout_and_verify(c)
949951
c.disconnect!
950952
raise
951953
end
954+
955+
def name_inspect
956+
db_config.name.inspect unless db_config.name == "primary"
957+
end
958+
959+
def shard_inspect
960+
shard.inspect unless shard == :default
961+
end
952962
end
953963
end
954964
end

activestorage/lib/active_storage/service/mirror_service.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ def self.build(primary:, mirrors:, name:, configurator:, **options) # :nodoc:
3030
def initialize(primary:, mirrors:)
3131
@primary, @mirrors = primary, mirrors
3232
@executor = Concurrent::ThreadPoolExecutor.new(
33+
name: "ActiveStorage-mirror-service",
3334
min_threads: 1,
3435
max_threads: mirrors.size,
3536
max_queue: 0,

0 commit comments

Comments
 (0)