Add Sidekiq concurrency limit multiplier env var

What does this MR do and why?

Adds the GITLAB_SIDEKIQ_CONCURRENCY_LIMIT_MULTIPLIER environment variable. It scales every explicit Sidekiq worker concurrency limit.

Explicit limits (concurrency_limit -> { 300 }) are sized for GitLab.com. On a smaller instance a limit can be higher than the number of Sidekiq threads, so it caps nothing. During a security-policy sync fan-out on a large instance, the limits of the policy workers added up to about 1,200 while the instance had about 240 Sidekiq threads. Every thread ended up querying the database.

Semantics

  • Each explicit limit becomes ceil(limit * multiplier). The value is parsed as a rational, so 300 * 0.1 is exactly 30, not 31.
  • Only positive explicit limits are scaled, and they never drop below 1. Unlimited (0) and paused (negative) limits are not changed.
  • Operator overrides, limits calculated from shard capacity, and ConcurrencyLimit::ResumeWorker are not scaled.
  • Adaptive throttling uses the scaled limit as its maximum, because it reads get_concurrency_limit.
  • A missing, empty, non-numeric, or non-positive value means 1, with no error and no log line. The default of 1 keeps the defined limits, so nothing changes until an administrator sets the variable. That is why there is no feature flag.
  • Values above 1 are accepted but not recommended in the docs.
  • The value is parsed once per process. Specs reset it with WorkerAttributes.reset_concurrency_limit_multiplier!.

How to set it

Set the variable on every process that enqueues or runs jobs (Puma and Sidekiq), because enqueue-side checks also use the limit, and restart GitLab.

  • Linux package: gitlab_rails['env'] = { 'GITLAB_SIDEKIQ_CONCURRENCY_LIMIT_MULTIPLIER' => '0.1' }
  • Helm chart: extraEnv under gitlab.webservice and gitlab.sidekiq

The docs are in doc/administration/settings/sidekiq.md.

Commits

  1. The multiplier in WorkerAttributes#get_concurrency_limit, its specs, and the docs. This is the part to backport.
  2. Scales the explicit limit in two places that read it without get_concurrency_limit: the enqueue fallback in LimitManager and the admin concurrency limit API. These only exist in the newer enqueue-side code.

Backport

This is intended for backport to 19.4, 19.5, and 19.6. It is an environment variable, not a new application setting, so it needs no UI, API, or migration changes.

References

  • Related to !276877, which adds the same multiplier as an application setting. That MR could later build on this one, or be dropped.

How to set up and validate locally

  1. Start GDK with GITLAB_SIDEKIQ_CONCURRENCY_LIMIT_MULTIPLIER=0.1 set for Rails and Sidekiq.
  2. In a Rails console, call get_concurrency_limit on a worker with an explicit concurrency_limit and compare with the value without the variable.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist.

Merge request reports

Loading
Loading