Commit 0ad2e198 authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch 'bvl-correct-thread-count' into 'master'

Correct threadcount in multithreaded environments

See merge request gitlab-org/gitlab!25261
parents bec1642c 65d112fa
---
title: Fix sidekiq jobs not always getting a database connection when running with low concurrency
merge_request: 25261
author:
type: fixed
...@@ -78,12 +78,16 @@ module Gitlab ...@@ -78,12 +78,16 @@ module Gitlab
end end
def max_threads def max_threads
main_thread = 1
if puma? if puma?
Puma.cli_config.options[:max_threads] Puma.cli_config.options[:max_threads] + main_thread
elsif sidekiq? elsif sidekiq?
Sidekiq.options[:concurrency] # An extra thread for the poller in Sidekiq Cron:
# https://github.com/ondrejbartas/sidekiq-cron#under-the-hood
Sidekiq.options[:concurrency] + main_thread + 1
else else
1 main_thread
end end
end end
end end
......
...@@ -50,7 +50,7 @@ describe Gitlab::Runtime do ...@@ -50,7 +50,7 @@ describe Gitlab::Runtime do
allow(puma_type).to receive_message_chain(:cli_config, :options).and_return(max_threads: 2) allow(puma_type).to receive_message_chain(:cli_config, :options).and_return(max_threads: 2)
end end
it_behaves_like "valid runtime", :puma, 2 it_behaves_like "valid runtime", :puma, 3
end end
context "unicorn" do context "unicorn" do
...@@ -71,7 +71,7 @@ describe Gitlab::Runtime do ...@@ -71,7 +71,7 @@ describe Gitlab::Runtime do
allow(sidekiq_type).to receive(:options).and_return(concurrency: 2) allow(sidekiq_type).to receive(:options).and_return(concurrency: 2)
end end
it_behaves_like "valid runtime", :sidekiq, 2 it_behaves_like "valid runtime", :sidekiq, 4
end end
context "console" do context "console" do
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment