Skip to content

Commit

Permalink
Decrease the default number of background worker threads by half (#2305)
Browse files Browse the repository at this point in the history
* Decrease the default number of background worker threads by half

See #2297 for the discussion.

* Update changelog
  • Loading branch information
st0012 authored May 6, 2024
1 parent 09fa602 commit d0c9897
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 2 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@

- Don't throw error on arbitrary arguments being passed to `capture_event` options [#2301](https://github.com/getsentry/sentry-ruby/pull/2301)
- Fixes [#2299](https://github.com/getsentry/sentry-ruby/issues/2299)
- Decrease the default number of background worker threads by half ([#2305](https://github.com/getsentry/sentry-ruby/pull/2305))
- Fixes [#2297](https://github.com/getsentry/sentry-ruby/issues/2297)

## 5.17.3

Expand Down
2 changes: 1 addition & 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 add_post_initialization_callback(&block)
def initialize
self.app_dirs_pattern = nil
self.debug = false
self.background_worker_threads = Concurrent.processor_count
self.background_worker_threads = (Concurrent.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
3 changes: 2 additions & 1 deletion sentry-ruby/spec/sentry/background_worker_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,11 @@

context "when config.background_worker_threads is set" do
it "initializes a background worker with correct number of threads and queue size" do
configuration.background_worker_threads = 4
worker = described_class.new(configuration)

expect(worker.max_queue).to eq(30)
expect(worker.number_of_threads).to eq(Concurrent.processor_count)
expect(worker.number_of_threads).to eq(4)
end
end

Expand Down
12 changes: 12 additions & 0 deletions sentry-ruby/spec/sentry/configuration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@
end
end

describe "#background_worker_threads" do
it "sets to have of the processors count" do
allow(Concurrent).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)
expect(subject.background_worker_threads).to eq(1)
end
end

describe "#csp_report_uri" do
it "returns nil if the dsn is not present" do
expect(subject.csp_report_uri).to eq(nil)
Expand Down

0 comments on commit d0c9897

Please sign in to comment.