Skip to content

Commit d068b4f

Browse files
committed
Use Concurrent.usable_processor_count when it is available
It's a new API introduced in concurrent-ruby 1.3.1, which works better in the container environment. ruby-concurrency/concurrent-ruby#1038 Since there are gems like sorbet-runtime that still use older versions of concurrent-ruby, we can't directly bump concurrent-ruby's requirement, but need to check if the method is available before calling it.
1 parent 8e62859 commit d068b4f

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

sentry-ruby/lib/sentry/configuration.rb

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ def add_post_initialization_callback(&block)
351351
def initialize
352352
self.app_dirs_pattern = nil
353353
self.debug = false
354-
self.background_worker_threads = (Concurrent.processor_count / 2.0).ceil
354+
self.background_worker_threads = (processor_count / 2.0).ceil
355355
self.background_worker_max_queue = BackgroundWorker::DEFAULT_MAX_QUEUE
356356
self.backtrace_cleanup_callback = nil
357357
self.max_breadcrumbs = BreadcrumbBuffer::DEFAULT_SIZE
@@ -654,5 +654,13 @@ def run_post_initialization_callbacks
654654
instance_eval(&hook)
655655
end
656656
end
657+
658+
def processor_count
659+
if Concurrent.respond_to?(:usable_processor_count)
660+
Concurrent.usable_processor_count
661+
else
662+
Concurrent.processor_count
663+
end
664+
end
657665
end
658666
end

sentry-ruby/spec/sentry/configuration_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,12 @@
2626

2727
describe "#background_worker_threads" do
2828
it "sets to have of the processors count" do
29-
allow(Concurrent).to receive(:processor_count).and_return(8)
29+
allow_any_instance_of(Sentry::Configuration).to receive(:processor_count).and_return(8)
3030
expect(subject.background_worker_threads).to eq(4)
3131
end
3232

3333
it "sets to 1 with only 1 processor" do
34-
allow(Concurrent).to receive(:processor_count).and_return(1)
34+
allow_any_instance_of(Sentry::Configuration).to receive(:processor_count).and_return(1)
3535
expect(subject.background_worker_threads).to eq(1)
3636
end
3737
end

0 commit comments

Comments
 (0)