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,17 @@ 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. Alternatively, 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
+
## Configuration
194
203
195
204
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
205
@@ -254,7 +263,7 @@ Here's an overview of the different options:
254
263
255
264
- `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
265
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.
266
+
- `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
267
- `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
268
260
269
@@ -334,7 +343,7 @@ queues: back*
334
343
335
344
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
345
337
-
The supervisor is in charge of managing these processes, and it responds to the following signals:
346
+
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
347
- `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
348
- `QUIT`: starts immediate termination. The supervisor will send a `QUIT` signal to its supervised processes, causing them to exit immediately.
340
349
@@ -603,6 +612,20 @@ that you set in production only. This is what Rails 8's default Puma config look
603
612
604
613
**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
614
615
+
### Running as a fork or asynchronously
616
+
617
+
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.
618
+
619
+
Alternatively, workers and dispatchers can be run within the same Puma process(s). To do so just configure the plugin as:
620
+
621
+
```ruby
622
+
plugin :solid_queue
623
+
solid_queue_mode :async
624
+
```
625
+
626
+
Note that in this case, the `processes` configuration option will be ignored. See also [Fork vs. async mode](#fork-vs-async-mode).
627
+
628
+
606
629
## Jobs and transactional integrity
607
630
: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.
Copy file name to clipboardExpand all lines: lib/solid_queue/cli.rb
+3-1Lines changed: 3 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,9 @@ class Cli < Thor
8
8
desc: "Path to config file (default: #{Configuration::DEFAULT_CONFIG_FILE_PATH}).",
9
9
banner: "SOLID_QUEUE_CONFIG"
10
10
11
-
class_option:mode,type: :string,default: "fork",enum: %w[forkasync],desc: "Whether to fork processes for workers and dispatchers (fork) or to run these in the same process as the supervisor (async)"
0 commit comments