diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d32d04ad..763734e42 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,9 @@ +## Unreleased + +### Internal + +- Use Concurrent.usable_processor_count when it is available ([#2339](https://github.com/getsentry/sentry-ruby/pull/2339)) + ## 5.18.1 ### Bug Fixes diff --git a/sentry-ruby/lib/sentry/configuration.rb b/sentry-ruby/lib/sentry/configuration.rb index 069094bda..8d4564694 100644 --- a/sentry-ruby/lib/sentry/configuration.rb +++ b/sentry-ruby/lib/sentry/configuration.rb @@ -351,7 +351,7 @@ def add_post_initialization_callback(&block) def initialize self.app_dirs_pattern = nil self.debug = false - self.background_worker_threads = (Concurrent.processor_count / 2.0).ceil + self.background_worker_threads = (processor_count / 2.0).ceil self.background_worker_max_queue = BackgroundWorker::DEFAULT_MAX_QUEUE self.backtrace_cleanup_callback = nil self.max_breadcrumbs = BreadcrumbBuffer::DEFAULT_SIZE @@ -654,5 +654,13 @@ def run_post_initialization_callbacks instance_eval(&hook) end end + + def processor_count + if Concurrent.respond_to?(:usable_processor_count) + Concurrent.usable_processor_count + else + Concurrent.processor_count + end + end end end diff --git a/sentry-ruby/spec/sentry/configuration_spec.rb b/sentry-ruby/spec/sentry/configuration_spec.rb index a88559c4e..92926836a 100644 --- a/sentry-ruby/spec/sentry/configuration_spec.rb +++ b/sentry-ruby/spec/sentry/configuration_spec.rb @@ -26,12 +26,12 @@ describe "#background_worker_threads" do it "sets to have of the processors count" do - allow(Concurrent).to receive(:processor_count).and_return(8) + allow_any_instance_of(Sentry::Configuration).to receive(:processor_count).and_return(8) expect(subject.background_worker_threads).to eq(4) end it "sets to 1 with only 1 processor" do - allow(Concurrent).to receive(:processor_count).and_return(1) + allow_any_instance_of(Sentry::Configuration).to receive(:processor_count).and_return(1) expect(subject.background_worker_threads).to eq(1) end end