Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Concurrent.usable_processor_count when it is available #2339

Merged
merged 2 commits into from
Jul 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
10 changes: 9 additions & 1 deletion sentry-ruby/lib/sentry/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -351,7 +351,7 @@
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
Expand Down Expand Up @@ -654,5 +654,13 @@
instance_eval(&hook)
end
end

def processor_count
if Concurrent.respond_to?(:usable_processor_count)
Concurrent.usable_processor_count

Check warning on line 660 in sentry-ruby/lib/sentry/configuration.rb

View check run for this annotation

Codecov / codecov/patch

sentry-ruby/lib/sentry/configuration.rb#L660

Added line #L660 was not covered by tests
else
Concurrent.processor_count
end
end
end
end
4 changes: 2 additions & 2 deletions sentry-ruby/spec/sentry/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading