2020-10-19 20:09:22 -04:00
---
2022-05-29 20:08:35 -04:00
stage: Systems
2020-11-17 10:09:28 -05:00
group: Distribution
2020-11-26 01:09:20 -05:00
info: To determine the technical writer assigned to the Stage/Group associated with this page, see https://about.gitlab.com/handbook/engineering/ux/technical-writing/#assignments
2020-10-19 20:09:22 -04:00
---
2021-01-28 01:08:59 -05:00
# Run multiple Sidekiq processes **(FREE SELF)**
2019-05-28 09:59:17 -04:00
2020-03-31 23:07:57 -04:00
GitLab allows you to start multiple Sidekiq processes.
These processes can be used to consume a dedicated set
2019-05-05 08:25:13 -04:00
of queues. This can be used to ensure certain queues always have dedicated
workers, no matter the number of jobs that need to be processed.
2020-12-04 16:09:29 -05:00
NOTE:
2020-05-06 20:11:11 -04:00
The information in this page applies only to Omnibus GitLab.
2019-05-28 09:59:17 -04:00
## Available Sidekiq queues
2019-05-05 08:25:13 -04:00
2019-05-28 09:59:17 -04:00
For a list of the existing Sidekiq queues, check the following files:
2019-05-05 08:25:13 -04:00
2021-06-08 14:10:23 -04:00
- [Queues for both GitLab Community and Enterprise Editions ](https://gitlab.com/gitlab-org/gitlab/-/blob/master/app/workers/all_queues.yml )
- [Queues for GitLab Enterprise Editions only ](https://gitlab.com/gitlab-org/gitlab/-/blob/master/ee/app/workers/all_queues.yml )
2019-05-05 08:25:13 -04:00
2020-03-31 23:07:57 -04:00
Each entry in the above files represents a queue on which Sidekiq processes
2019-05-28 09:59:17 -04:00
can be started.
2019-05-05 08:25:13 -04:00
2020-05-06 20:11:11 -04:00
## Start multiple processes
> - [Introduced](https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/4006) in GitLab 12.10, starting multiple processes with Sidekiq cluster.
2021-02-10 13:09:02 -05:00
> - [Sidekiq cluster moved](https://gitlab.com/groups/gitlab-com/gl-infra/-/epics/181) to GitLab Free in 12.10.
2020-05-06 20:11:11 -04:00
> - [Sidekiq cluster became default](https://gitlab.com/gitlab-org/omnibus-gitlab/-/merge_requests/4140) in GitLab 13.0.
2019-05-05 08:25:13 -04:00
2021-11-08 22:42:22 -05:00
When starting multiple processes, the number of processes should
equal (and **not** exceed) the number of CPU cores you want to
dedicate to Sidekiq. Each Sidekiq process can use only 1 CPU
core, subject to the available workload and concurrency settings.
2020-05-04 23:09:46 -04:00
To start multiple processes:
2019-05-05 08:25:13 -04:00
2020-05-04 23:09:46 -04:00
1. Using the `sidekiq['queue_groups']` array setting, specify how many processes to
create using `sidekiq-cluster` and which queue they should handle.
Each item in the array equates to one additional Sidekiq
2019-05-28 09:59:17 -04:00
process, and values in each item determine the queues it works on.
2019-05-05 08:25:13 -04:00
2020-05-04 23:09:46 -04:00
For example, the following setting creates three Sidekiq processes, one to run on
2021-05-25 05:10:54 -04:00
`elastic_commit_indexer` , one to run on `mailers` , and one process running on all queues:
2019-05-05 08:25:13 -04:00
2019-05-28 09:59:17 -04:00
```ruby
2020-05-04 23:09:46 -04:00
sidekiq['queue_groups'] = [
2021-05-25 05:10:54 -04:00
"elastic_commit_indexer",
2020-05-04 23:09:46 -04:00
"mailers",
"*"
2019-05-28 09:59:17 -04:00
]
```
To have an additional Sidekiq process handle multiple queues, add multiple
queue names to its item delimited by commas. For example:
```ruby
2020-05-04 23:09:46 -04:00
sidekiq['queue_groups'] = [
2021-05-25 05:10:54 -04:00
"elastic_commit_indexer, elastic_association_indexer",
2020-05-04 23:09:46 -04:00
"mailers",
"*"
2019-05-28 09:59:17 -04:00
]
```
2020-03-06 10:08:05 -05:00
[In GitLab 12.9 ](https://gitlab.com/gitlab-org/gitlab/-/merge_requests/26594 ) and
later, the special queue name `*` means all queues. This starts two
processes, each handling all queues:
```ruby
2020-05-04 23:09:46 -04:00
sidekiq['queue_groups'] = [
2020-03-06 10:08:05 -05:00
"*",
"*"
]
```
2021-06-06 23:09:56 -04:00
`*` cannot be combined with concrete queue names - `*, mailers`
just handles the `mailers` queue.
2020-03-06 10:08:05 -05:00
2020-05-04 23:09:46 -04:00
When `sidekiq-cluster` is only running on a single node, make sure that at least
2021-07-14 23:09:42 -04:00
one process is running on all queues using `*` . This ensures a process
automatically picks up jobs in queues created in the future,
including queues that have dedicated processes.
2020-05-04 23:09:46 -04:00
If `sidekiq-cluster` is running on more than one node, you can also use
2020-05-06 20:11:11 -04:00
[`--negate` ](#negate-settings ) and list all the queues that are already being
2020-05-04 23:09:46 -04:00
processed.
2019-05-28 09:59:17 -04:00
1. Save the file and reconfigure GitLab for the changes to take effect:
2020-01-30 10:09:15 -05:00
```shell
2019-05-28 09:59:17 -04:00
sudo gitlab-ctl reconfigure
```
2021-06-18 11:10:16 -04:00
To view the Sidekiq processes in GitLab:
2019-05-05 08:25:13 -04:00
2021-08-25 20:09:31 -04:00
1. On the top bar, select **Menu > Admin** .
2021-06-18 11:10:16 -04:00
1. On the left sidebar, select **Monitoring > Background Jobs** .
2019-05-05 08:25:13 -04:00
2020-05-06 20:11:11 -04:00
## Negate settings
2019-05-05 08:25:13 -04:00
2021-07-20 08:10:29 -04:00
To have the Sidekiq process work on every queue **except** the ones
2021-07-05 11:07:38 -04:00
you list. In this example, we exclude all import-related jobs from a Sidekiq node:
2019-05-05 08:25:13 -04:00
2021-07-20 08:10:29 -04:00
1. Edit `/etc/gitlab/gitlab.rb` and add:
2019-05-28 09:59:17 -04:00
```ruby
2020-05-04 23:09:46 -04:00
sidekiq['negate'] = true
2021-07-20 08:10:29 -04:00
sidekiq['queue_selector'] = true
2021-07-05 11:07:38 -04:00
sidekiq['queue_groups'] = [
"feature_category=importers"
]
2019-05-28 09:59:17 -04:00
```
1. Save the file and reconfigure GitLab for the changes to take effect:
2020-01-30 10:09:15 -05:00
```shell
2019-05-28 09:59:17 -04:00
sudo gitlab-ctl reconfigure
```
2020-11-03 01:08:58 -05:00
## Queue selector
2020-02-14 04:08:43 -05:00
2021-02-10 13:09:02 -05:00
> - [Introduced](https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/45) in GitLab 12.8.
> - [Sidekiq cluster, including queue selector, moved](https://gitlab.com/groups/gitlab-com/gl-infra/-/epics/181) to GitLab Free in 12.10.
2020-12-28 07:10:13 -05:00
> - [Renamed from `experimental_queue_selector` to `queue_selector`](https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/147) in GitLab 13.6.
2020-02-14 04:08:43 -05:00
2021-05-28 08:10:48 -04:00
In addition to selecting queues by name, as above, the `queue_selector` option
allows queue groups to be selected in a more general way using a [worker matching
query](extra_sidekiq_routing.md#worker-matching-query). After `queue_selector`
is set, all `queue_groups` must follow the aforementioned syntax.
2020-02-14 04:08:43 -05:00
In `/etc/gitlab/gitlab.rb` :
```ruby
2020-05-04 23:09:46 -04:00
sidekiq['enable'] = true
2020-11-03 01:08:58 -05:00
sidekiq['queue_selector'] = true
2020-05-04 23:09:46 -04:00
sidekiq['queue_groups'] = [
2020-03-02 13:07:42 -05:00
# Run all non-CPU-bound queues that are high urgency
2020-03-06 10:08:05 -05:00
'resource_boundary!=cpu& urgency=high',
2020-03-02 13:07:42 -05:00
# Run all continuous integration and pages queues that are not high urgency
2020-03-06 10:08:05 -05:00
'feature_category=continuous_integration,pages& urgency!=high',
# Run all queues
'*'
2020-02-14 04:08:43 -05:00
]
```
2021-07-05 11:07:38 -04:00
## Ignore all import queues
2019-05-28 09:59:17 -04:00
2021-07-05 11:07:38 -04:00
When [importing from GitHub ](../../user/project/import/github.md ) or
other sources, Sidekiq might use all of its resources to perform those
operations. To set up two separate `sidekiq-cluster` processes, where
one only processes imports and the other processes all other queues:
2019-05-28 09:59:17 -04:00
2019-05-05 08:25:13 -04:00
1. Edit `/etc/gitlab/gitlab.rb` and add:
```ruby
2020-05-04 23:09:46 -04:00
sidekiq['enable'] = true
2021-07-05 11:07:38 -04:00
sidekiq['queue_selector'] = true
2020-05-04 23:09:46 -04:00
sidekiq['queue_groups'] = [
2021-07-05 11:07:38 -04:00
"feature_category=importers",
"feature_category!=importers"
2019-05-28 09:59:17 -04:00
]
2019-05-05 08:25:13 -04:00
```
2019-05-28 09:59:17 -04:00
1. Save the file and reconfigure GitLab for the changes to take effect:
2019-05-05 08:25:13 -04:00
2020-01-30 10:09:15 -05:00
```shell
2019-05-28 09:59:17 -04:00
sudo gitlab-ctl reconfigure
```
2019-05-05 08:25:13 -04:00
2019-05-28 09:59:17 -04:00
## Number of threads
2021-11-08 22:42:22 -05:00
By default each process defined under `sidekiq` starts with a
2019-05-28 09:59:17 -04:00
number of threads that equals the number of queues, plus one spare thread.
For example, a process that handles the `process_commit` and `post_receive`
2021-06-06 23:09:56 -04:00
queues uses three threads in total.
2019-05-28 09:59:17 -04:00
2021-11-08 22:42:22 -05:00
These thread run inside a single Ruby process, and each process
can only use a single CPU core. The usefulness of threading depends
on the work having some external dependencies to wait on, like database queries or
HTTP requests. Most Sidekiq deployments benefit from this threading, and when
running fewer queues in a process, increasing the thread count might be
even more desirable to make the most effective use of CPU resources.
### Manage thread counts explicitly
The correct maximum thread count (also called concurrency) depends on the workload.
Typical values range from `1` for highly CPU-bound tasks to `15` or higher for mixed
low-priority work. A reasonable starting range is `15` to `25` for a non-specialized
deployment.
You can find example values used by GitLab.com by searching for `concurrency:` in
[the Helm charts ](https://gitlab.com/gitlab-com/gl-infra/k8s-workloads/gitlab-com/-/blob/master/releases/gitlab/values/gprd.yaml.gotmpl ).
The values vary according to the work each specific deployment of Sidekiq does.
Any other specialized deployments with processes dedicated to specific queues should
have the concurrency tuned according to:
have the concurrency tuned according to:
2019-05-28 09:59:17 -04:00
2021-11-08 22:42:22 -05:00
- The CPU usage of each type of process.
- The throughput achieved.
2020-01-22 10:08:48 -05:00
Each thread requires a Redis connection, so adding threads may increase Redis
latency and potentially cause client timeouts. See the [Sidekiq documentation
about Redis](https://github.com/mperham/sidekiq/wiki/Using-Redis) for more
details.
2021-11-08 22:42:22 -05:00
#### When running Sidekiq cluster (default)
2019-11-22 13:06:00 -05:00
2020-05-06 20:11:11 -04:00
Running Sidekiq cluster is the default in GitLab 13.0 and later.
2019-11-22 13:06:00 -05:00
1. Edit `/etc/gitlab/gitlab.rb` and add:
```ruby
2020-05-04 23:09:46 -04:00
sidekiq['min_concurrency'] = 15
sidekiq['max_concurrency'] = 25
2019-05-05 08:25:13 -04:00
```
2019-05-28 09:59:17 -04:00
1. Save the file and reconfigure GitLab for the changes to take effect:
2019-05-05 08:25:13 -04:00
2020-01-30 10:09:15 -05:00
```shell
2019-05-28 09:59:17 -04:00
sudo gitlab-ctl reconfigure
```
2019-05-05 08:25:13 -04:00
2020-01-22 10:08:48 -05:00
`min_concurrency` and `max_concurrency` are independent; one can be set without
2021-06-06 23:09:56 -04:00
the other. Setting `min_concurrency` to `0` disables the limit.
2020-01-22 10:08:48 -05:00
2020-10-29 05:08:38 -04:00
For each queue group, let `N` be one more than the number of queues. The
2021-11-08 22:42:22 -05:00
concurrency is set to:
2020-01-22 10:08:48 -05:00
1. `N` , if it's between `min_concurrency` and `max_concurrency` .
1. `max_concurrency` , if `N` exceeds this value.
1. `min_concurrency` , if `N` is less than this value.
2021-06-06 23:09:56 -04:00
If `min_concurrency` is equal to `max_concurrency` , then this value is used
2020-01-22 10:08:48 -05:00
regardless of the number of queues.
2019-05-28 09:59:17 -04:00
2020-01-22 10:08:48 -05:00
When `min_concurrency` is greater than `max_concurrency` , it is treated as
being equal to `max_concurrency` .
2019-05-28 09:59:17 -04:00
2021-11-08 22:42:22 -05:00
#### When running a single Sidekiq process
2020-05-06 20:11:11 -04:00
Running a single Sidekiq process is the default in GitLab 12.10 and earlier.
2020-12-04 16:09:29 -05:00
WARNING:
2021-07-20 08:10:29 -04:00
Running Sidekiq directly was removed in GitLab
2020-05-06 20:11:11 -04:00
[14.0 ](https://gitlab.com/gitlab-com/gl-infra/scalability/-/issues/240 ).
1. Edit `/etc/gitlab/gitlab.rb` and add:
```ruby
sidekiq['cluster'] = false
sidekiq['concurrency'] = 25
```
1. Save the file and reconfigure GitLab for the changes to take effect:
```shell
sudo gitlab-ctl reconfigure
```
2021-06-06 23:09:56 -04:00
This sets the concurrency (number of threads) for the Sidekiq process.
2020-05-06 20:11:11 -04:00
## Modify the check interval
2019-05-05 08:25:13 -04:00
2021-12-01 13:15:19 -05:00
To modify `sidekiq-cluster` 's health check interval for the additional Sidekiq processes:
2019-05-05 08:25:13 -04:00
2021-12-01 13:15:19 -05:00
1. Edit `/etc/gitlab/gitlab.rb` and add (the value can be any integer number of seconds):
2019-05-05 08:25:13 -04:00
```ruby
2020-05-04 23:09:46 -04:00
sidekiq['interval'] = 5
2019-05-05 08:25:13 -04:00
```
1. Save the file and [reconfigure GitLab ](../restart_gitlab.md#omnibus-gitlab-reconfigure ) for the changes to take effect.
2020-05-06 20:11:11 -04:00
## Troubleshoot using the CLI
2019-05-05 08:25:13 -04:00
2020-12-04 16:09:29 -05:00
WARNING:
2019-05-28 09:59:17 -04:00
It's recommended to use `/etc/gitlab/gitlab.rb` to configure the Sidekiq processes.
If you experience a problem, you should contact GitLab support. Use the command
line at your own risk.
For debugging purposes, you can start extra Sidekiq processes by using the command
2020-03-11 20:09:34 -04:00
`/opt/gitlab/embedded/service/gitlab-rails/bin/sidekiq-cluster` . This command
2019-05-05 08:25:13 -04:00
takes arguments using the following syntax:
2020-01-30 10:09:15 -05:00
```shell
2020-03-11 20:09:34 -04:00
/opt/gitlab/embedded/service/gitlab-rails/bin/sidekiq-cluster [QUEUE,QUEUE,...] [QUEUE, ...]
2019-05-05 08:25:13 -04:00
```
Each separate argument denotes a group of queues that have to be processed by a
Sidekiq process. Multiple queues can be processed by the same process by
separating them with a comma instead of a space.
Instead of a queue, a queue namespace can also be provided, to have the process
automatically listen on all queues in that namespace without needing to
explicitly list all the queue names. For more information about queue namespaces,
see the relevant section in the
2022-01-20 10:11:58 -05:00
[Sidekiq development documentation ](../../development/sidekiq/index.md#queue-namespaces ).
2019-05-05 08:25:13 -04:00
For example, say you want to start 2 extra processes: one to process the
2019-05-28 09:59:17 -04:00
`process_commit` queue, and one to process the `post_receive` queue. This can be
2019-05-05 08:25:13 -04:00
done as follows:
2020-01-30 10:09:15 -05:00
```shell
2020-03-11 20:09:34 -04:00
/opt/gitlab/embedded/service/gitlab-rails/bin/sidekiq-cluster process_commit post_receive
2019-05-05 08:25:13 -04:00
```
2019-05-28 09:59:17 -04:00
If you instead want to start one process processing both queues, you'd use the
2019-05-05 08:25:13 -04:00
following syntax:
2020-01-30 10:09:15 -05:00
```shell
2020-03-11 20:09:34 -04:00
/opt/gitlab/embedded/service/gitlab-rails/bin/sidekiq-cluster process_commit,post_receive
2019-05-05 08:25:13 -04:00
```
2019-05-28 09:59:17 -04:00
If you want to have one Sidekiq process dealing with the `process_commit` and
`post_receive` queues, and one process to process the `gitlab_shell` queue,
2019-05-05 08:25:13 -04:00
you'd use the following:
2020-01-30 10:09:15 -05:00
```shell
2020-03-11 20:09:34 -04:00
/opt/gitlab/embedded/service/gitlab-rails/bin/sidekiq-cluster process_commit,post_receive gitlab_shell
2019-05-05 08:25:13 -04:00
```
2020-05-06 20:11:11 -04:00
### Monitor the `sidekiq-cluster` command
2019-05-05 08:25:13 -04:00
2021-06-06 23:09:56 -04:00
The `sidekiq-cluster` command does not terminate once it has started the desired
amount of Sidekiq processes. Instead, the process continues running and
2019-05-05 08:25:13 -04:00
forward any signals to the child processes. This makes it easy to stop all
Sidekiq processes as you simply send a signal to the `sidekiq-cluster` process,
instead of having to send it to the individual processes.
If the `sidekiq-cluster` process crashes or receives a `SIGKILL` , the child
2021-06-06 23:09:56 -04:00
processes terminate themselves after a few seconds. This ensures you don't
2019-05-05 08:25:13 -04:00
end up with zombie Sidekiq processes.
All of this makes monitoring the processes fairly easy. Simply hook up
2020-05-06 20:11:11 -04:00
`sidekiq-cluster` to your supervisor of choice (for example, runit) and you're good to
2019-05-05 08:25:13 -04:00
go.
2021-06-06 23:09:56 -04:00
If a child process died the `sidekiq-cluster` command signals all remaining
2019-05-05 08:25:13 -04:00
process to terminate, then terminate itself. This removes the need for
`sidekiq-cluster` to re-implement complex process monitoring/restarting code.
Instead you should make sure your supervisor restarts the `sidekiq-cluster`
process whenever necessary.
### PID files
The `sidekiq-cluster` command can store its PID in a file. By default no PID
file is written, but this can be changed by passing the `--pidfile` option to
`sidekiq-cluster` . For example:
2020-01-30 10:09:15 -05:00
```shell
2020-03-11 20:09:34 -04:00
/opt/gitlab/embedded/service/gitlab-rails/bin/sidekiq-cluster --pidfile /var/run/gitlab/sidekiq_cluster.pid process_commit
2019-05-05 08:25:13 -04:00
```
2021-06-06 23:09:56 -04:00
Keep in mind that the PID file contains the PID of the `sidekiq-cluster`
2022-05-13 11:07:43 -04:00
command and not the PIDs of the started Sidekiq processes.
2019-05-05 08:25:13 -04:00
### Environment
The Rails environment can be set by passing the `--environment` flag to the
`sidekiq-cluster` command, or by setting `RAILS_ENV` to a non-empty value. The
2019-05-28 09:59:17 -04:00
default value can be found in `/opt/gitlab/etc/gitlab-rails/env/RAILS_ENV` .