Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

alter defaults for workers and threads to allow more parallel tasks #446

jonaswinklerab04817bea12
diff --git a/docs/configuration.rst b/docs/configuration.rst
index 5edc003f6..36b124350 100644
--- a/docs/configuration.rst
+++ b/docs/configuration.rst
@@ -376,25 +376,24 @@ PAPERLESS_THREADS_PER_WORKER=<num>
use a higher thread per worker count.
The default is a balance between the two, according to your CPU core count,
- with a slight favor towards threads per worker, and leaving at least one core
- free for other tasks:
+ with a slight favor towards threads per worker:
+----------------+---------+---------+
| CPU core count | Workers | Threads |
+----------------+---------+---------+
| 1 | 1 | 1 |
+----------------+---------+---------+
- | 2 | 1 | 1 |
+ | 2 | 2 | 1 |
+----------------+---------+---------+
- | 4 | 1 | 3 |
+ | 4 | 2 | 2 |
+----------------+---------+---------+
- | 6 | 2 | 2 |
+ | 6 | 2 | 3 |
+----------------+---------+---------+
- | 8 | 2 | 3 |
+ | 8 | 2 | 4 |
+----------------+---------+---------+
- | 12 | 3 | 3 |
+ | 12 | 3 | 4 |
+----------------+---------+---------+
- | 16 | 3 | 5 |
+ | 16 | 4 | 4 |
+----------------+---------+---------+
If you only specify PAPERLESS_TASK_WORKERS, paperless will adjust
diff --git a/src/documents/tests/test_settings.py b/src/documents/tests/test_settings.py
index 21f29b4d9..0036daee7 100644
--- a/src/documents/tests/test_settings.py
+++ b/src/documents/tests/test_settings.py
@@ -20,7 +20,7 @@ class TestSettings(TestCase):
self.assertEqual(default_threads, 1)
def test_workers_threads(self):
- for i in range(2, 64):
+ for i in range(1, 64):
with mock.patch("paperless.settings.multiprocessing.cpu_count") as cpu_count:
cpu_count.return_value = i
@@ -31,4 +31,4 @@ class TestSettings(TestCase):
self.assertTrue(default_workers >= 1)
self.assertTrue(default_threads >= 1)
- self.assertTrue(default_workers * default_threads < i, f"{i}")
+ self.assertTrue(default_workers * default_threads <= i, f"{i}")
diff --git a/src/paperless/settings.py b/src/paperless/settings.py
index 894ecb60b..bc70cb331 100644
--- a/src/paperless/settings.py
+++ b/src/paperless/settings.py
@@ -354,8 +354,10 @@ LOGGING = {
def default_task_workers():
# always leave one core open
- available_cores = max(multiprocessing.cpu_count() - 1, 1)
+ available_cores = max(multiprocessing.cpu_count(), 1)
try:
+ if available_cores < 4:
+ return available_cores
return max(
math.floor(math.sqrt(available_cores)),
1
@@ -376,7 +378,7 @@ Q_CLUSTER = {
def default_threads_per_worker(task_workers):
# always leave one core open
- available_cores = max(multiprocessing.cpu_count() - 1, 1)
+ available_cores = max(multiprocessing.cpu_count(), 1)
try:
return max(
math.floor(available_cores / task_workers),