Skip to content

Commit

Permalink
Set default thread count to 8
Browse files Browse the repository at this point in the history
Set thread count to 8 as per dramatiq default
  • Loading branch information
andrewgy8 authored Dec 27, 2024
2 parents e005c31 + 17e4314 commit 02e849a
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 10 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,25 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## Unreleased
### Changed
- Set thread count to 8 as per dramatiq default. Fix [#153]. ([@andrewgy8], [#170])

[@andrewgy8]: https://github.com/andrewgy8
[#153]: https://github.com/Bogdanp/django_dramatiq/issues/153
[#170]: https://github.com/Bogdanp/django_dramatiq/pull/170

### Added
- Display task details in the admin when JSONEncoder is not used. Fix [#135]. ([@huubbouma], [#136])
- Support for Python 3.13
- Support for Django 5.1

[@huubbouma]: https://github.com/huubbouma
[#135]: https://github.com/Bogdanp/django_dramatiq/issues/135
[#136]: https://github.com/Bogdanp/django_dramatiq/pull/136

### Dropped
- Support for Python 3.8
- Support for Django 3.2

## [0.11.6] - 2023-12-12
### Added
Expand Down
5 changes: 3 additions & 2 deletions django_dramatiq/management/commands/rundramatiq.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

#: The number of available CPUs.
CPU_COUNT = multiprocessing.cpu_count()
THREAD_COUNT = 8


class Command(BaseCommand):
Expand Down Expand Up @@ -52,9 +53,9 @@ def add_arguments(self, parser):
)
parser.add_argument(
"--threads", "-t",
default=CPU_COUNT,
default=THREAD_COUNT,
type=int,
help="The number of threads per process to use (default: %d)." % CPU_COUNT,
help="The number of threads per process to use (default: %d)." % THREAD_COUNT,
)
parser.add_argument(
"--path", "-P",
Expand Down
24 changes: 16 additions & 8 deletions tests/test_rundramatiq_command.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,15 @@ def test_rundramatiq_can_run_dramatiq(execvp_mock):

# And execvp should be called with the appropriate arguments
cores = str(rundramatiq.CPU_COUNT)
threads = str(rundramatiq.THREAD_COUNT)
expected_exec_name = "dramatiq"
expected_exec_path = os.path.join(
os.path.dirname(sys.executable),
expected_exec_name,
)

execvp_mock.assert_called_once_with(expected_exec_path, [
expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores,
expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads,
"--worker-shutdown-timeout", "600000",
"django_dramatiq.setup",
"django_dramatiq.tasks",
Expand All @@ -67,14 +68,15 @@ def test_rundramatiq_can_run_dramatiq_reload(execvp_mock):

# Then execvp should be called with the appropriate arguments
cores = str(rundramatiq.CPU_COUNT)
threads = str(rundramatiq.THREAD_COUNT)
expected_exec_name = "dramatiq"
expected_exec_path = os.path.join(
os.path.dirname(sys.executable),
expected_exec_name,
)

execvp_mock.assert_called_once_with(expected_exec_path, [
expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores,
expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads,
"--worker-shutdown-timeout", "600000",
"--watch", ".",
"django_dramatiq.setup",
Expand All @@ -98,14 +100,15 @@ def test_rundramatiq_can_run_dramatiq_with_polling(execvp_mock):

# Then execvp should be called with the appropriate arguments
cores = str(rundramatiq.CPU_COUNT)
threads = str(rundramatiq.THREAD_COUNT)
expected_exec_name = "dramatiq"
expected_exec_path = os.path.join(
os.path.dirname(sys.executable),
expected_exec_name,
)

execvp_mock.assert_called_once_with(expected_exec_path, [
expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores,
expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads,
"--worker-shutdown-timeout", "600000",
"--watch", ".",
"--watch-use-polling",
Expand All @@ -130,14 +133,15 @@ def test_rundramatiq_can_run_dramatiq_with_only_some_queues(execvp_mock):

# Then execvp should be called with the appropriate arguments
cores = str(rundramatiq.CPU_COUNT)
threads = str(rundramatiq.THREAD_COUNT)
expected_exec_name = "dramatiq"
expected_exec_path = os.path.join(
os.path.dirname(sys.executable),
expected_exec_name,
)

execvp_mock.assert_called_once_with(expected_exec_path, [
expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores,
expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads,
"--worker-shutdown-timeout", "600000",
"django_dramatiq.setup",
"django_dramatiq.tasks",
Expand All @@ -161,14 +165,15 @@ def test_rundramatiq_can_run_dramatiq_with_specified_pid_file(execvp_mock):

# Then execvp should be called with the appropriate arguments
cores = str(rundramatiq.CPU_COUNT)
threads = str(rundramatiq.THREAD_COUNT)
expected_exec_name = "dramatiq"
expected_exec_path = os.path.join(
os.path.dirname(sys.executable),
expected_exec_name,
)

execvp_mock.assert_called_once_with(expected_exec_path, [
expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores,
expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads,
"--worker-shutdown-timeout", "600000",
"django_dramatiq.setup",
"django_dramatiq.tasks",
Expand All @@ -192,14 +197,15 @@ def test_rundramatiq_can_run_dramatiq_with_specified_log_file(execvp_mock):

# Then execvp should be called with the appropriate arguments
cores = str(rundramatiq.CPU_COUNT)
threads = str(rundramatiq.THREAD_COUNT)
expected_exec_name = "dramatiq"
expected_exec_path = os.path.join(
os.path.dirname(sys.executable),
expected_exec_name,
)

execvp_mock.assert_called_once_with(expected_exec_path, [
expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores,
expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads,
"--worker-shutdown-timeout", "600000",
"django_dramatiq.setup",
"django_dramatiq.tasks",
Expand Down Expand Up @@ -239,14 +245,15 @@ def test_rundramatiq_can_ignore_modules(execvp_mock, settings):

# And execvp should be called with the appropriate arguments
cores = str(rundramatiq.CPU_COUNT)
threads = str(rundramatiq.THREAD_COUNT)
expected_exec_name = "dramatiq"
expected_exec_path = os.path.join(
os.path.dirname(sys.executable),
expected_exec_name,
)

execvp_mock.assert_called_once_with(expected_exec_path, [
expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores,
expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads,
"--worker-shutdown-timeout", "600000",
"django_dramatiq.setup",
"django_dramatiq.tasks",
Expand All @@ -266,14 +273,15 @@ def test_rundramatiq_can_fork(execvp_mock, settings):

# Then execvp should be called with the appropriate arguments
cores = str(rundramatiq.CPU_COUNT)
threads = str(rundramatiq.THREAD_COUNT)
expected_exec_name = "dramatiq"
expected_exec_path = os.path.join(
os.path.dirname(sys.executable),
expected_exec_name,
)

execvp_mock.assert_called_once_with(expected_exec_path, [
expected_exec_name, "--path", ".", "--processes", cores, "--threads", cores,
expected_exec_name, "--path", ".", "--processes", cores, "--threads", threads,
"--worker-shutdown-timeout", "600000",
"--fork-function", "a",
"--fork-function", "b",
Expand Down

0 comments on commit 02e849a

Please sign in to comment.