You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
-[Workers, dispatchers, and scheduler](#workers-dispatchers-and-scheduler)
18
+
-[Fork vs. async mode](#fork-vs-async-mode)
17
19
-[Configuration](#configuration)
18
-
-[Workers, dispatchers, and scheduler](#workers-dispatchers-and-scheduler)
19
20
-[Queue order and priorities](#queue-order-and-priorities)
20
21
-[Queues specification and performance](#queues-specification-and-performance)
21
22
-[Threads, processes, and signals](#threads-processes-and-signals)
@@ -179,9 +180,7 @@ end
179
180
180
181
Solid Queue was designed for the highest throughput when used with MySQL 8+, MariaDB 10.6+, or PostgreSQL 9.5+, as they support `FOR UPDATE SKIP LOCKED`. You can use it with older versions, but in that case, you might run into lock waits if you run multiple workers for the same queue. You can also use it with SQLite on smaller applications.
181
182
182
-
## Configuration
183
-
184
-
### Workers, dispatchers, and scheduler
183
+
## Workers, dispatchers, and scheduler
185
184
186
185
We have several types of actors in Solid Queue:
187
186
@@ -190,7 +189,19 @@ We have several types of actors in Solid Queue:
190
189
- The _scheduler_ manages [recurring tasks](#recurring-tasks), enqueuing jobs for them when they're due.
191
190
- The _supervisor_ runs workers and dispatchers according to the configuration, controls their heartbeats, and stops and starts them when needed.
192
191
193
-
Solid Queue's supervisor will fork a separate process for each supervised worker/dispatcher/scheduler.
192
+
### Fork vs. async mode
193
+
194
+
By default, Solid Queue runs in `fork` mode. This means the supervisor will fork a separate process for each supervised worker/dispatcher/scheduler. This provides the best isolation and performance, but can have additional memory usage and might not work with some Ruby implementations. As an alternative, you can run all workers, dispatchers and schedulers in the same process as the supervisor, in different threads, with an `async` mode. You can choose this mode by running `bin/jobs` as:
195
+
196
+
```
197
+
bin/jobs --mode async
198
+
```
199
+
200
+
Or you can also set the environment variable `SOLID_QUEUE_SUPERVISOR_MODE` to `async`. If you use the `async` mode, the `processes` option in the configuration described below will be ignored.
201
+
202
+
**The recommended and default mode is `fork`. Only use `async` if you know what you're doing and have strong reasons to**
203
+
204
+
## Configuration
194
205
195
206
By default, Solid Queue will try to find your configuration under `config/queue.yml`, but you can set a different path using the environment variable `SOLID_QUEUE_CONFIG` or by using the `-c/--config_file` option with `bin/jobs`, like this:
196
207
@@ -254,7 +265,7 @@ Here's an overview of the different options:
254
265
255
266
- `threads`: this is the max size of the thread pool that each worker will have to run jobs. Each worker will fetch this number of jobs from their queue(s), at most and will post them to the thread pool to be run. By default, this is `3`. Only workers have this setting.
256
267
It is recommended to set this value less than or equal to the queue database's connection pool size minus 2, as each worker thread uses one connection, and two additional connections are reserved for polling and heartbeat.
257
-
- `processes`: this is the number of worker processes that will be forked by the supervisor with the settings given. By default, this is `1`, just a single process. This setting is useful if you want to dedicate more than one CPU core to a queue or queues with the same configuration. Only workers have this setting.
268
+
- `processes`: this is the number of worker processes that will be forked by the supervisor with the settings given. By default, this is `1`, just a single process. This setting is useful if you want to dedicate more than one CPU core to a queue or queues with the same configuration. Only workers have this setting. **Note**: this option will be ignored if [running in `async` mode](#fork-vs-async-mode).
258
269
- `concurrency_maintenance`: whether the dispatcher will perform the concurrency maintenance work. This is `true` by default, and it's useful if you don't use any [concurrency controls](#concurrency-controls) and want to disable it or if you run multiple dispatchers and want some of them to just dispatch jobs without doing anything else.
259
270
260
271
@@ -334,7 +345,7 @@ queues: back*
334
345
335
346
Workers in Solid Queue use a thread pool to run work in multiple threads, configurable via the `threads` parameter above. Besides this, parallelism can be achieved via multiple processes on one machine (configurable via different workers or the `processes` parameter above) or by horizontal scaling.
336
347
337
-
The supervisor is in charge of managing these processes, and it responds to the following signals:
348
+
The supervisor is in charge of managing these processes, and it responds to the following signals when running in its own process via `bin/jobs` or with [the Puma plugin](#puma-plugin) with the default `fork` mode:
338
349
- `TERM`, `INT`: starts graceful termination. The supervisor will send a `TERM` signal to its supervised processes, and it'll wait up to `SolidQueue.shutdown_timeout` time until they're done. If any supervised processes are still around by then, it'll send a `QUIT` signal to them to indicate they must exit.
339
350
- `QUIT`: starts immediate termination. The supervisor will send a `QUIT` signal to its supervised processes, causing them to exit immediately.
340
351
@@ -603,6 +614,22 @@ that you set in production only. This is what Rails 8's default Puma config look
603
614
604
615
**Note**: phased restarts are not supported currently because the plugin requires [app preloading](https://github.com/puma/puma?tab=readme-ov-file#cluster-mode) to work.
605
616
617
+
### Running as a fork or asynchronously
618
+
619
+
By default, the Puma plugin will fork additional processes for each worker and dispatcher so that they run in different processes. This provides the best isolation and performance, but can have additional memory usage.
620
+
621
+
Alternatively, workers and dispatchers can be run within the same Puma process(s). To do so just configure the plugin as:
622
+
623
+
```ruby
624
+
plugin :solid_queue
625
+
solid_queue_mode :async
626
+
```
627
+
628
+
Note that in this case, the `processes` configuration option will be ignored. See also [Fork vs. async mode](#fork-vs-async-mode).
629
+
630
+
**The recommended and default mode is `fork`. Only use `async` if you know what you're doing and have strong reasons to**
631
+
632
+
606
633
## Jobs and transactional integrity
607
634
:warning: Having your jobs in the same ACID-compliant database as your application data enables a powerful yet sharp tool: taking advantage of transactional integrity to ensure some action in your app is not committed unless your job is also committed and vice versa, and ensuring that your job won't be enqueued until the transaction within which you're enqueuing it is committed. This can be very powerful and useful, but it can also backfire if you base some of your logic on this behaviour, and in the future, you move to another active job backend, or if you simply move Solid Queue to its own database, and suddenly the behaviour changes under you. Because this can be quite tricky and many people shouldn't need to worry about it, by default Solid Queue is configured in a different database as the main app.
0 commit comments