Bogdanp / django_dramatiq

A Django app that integrates with Dramatiq.
https://dramatiq.io
Other
347 stars 77 forks source link

Supervisord #84

Closed tarsil closed 3 years ago

tarsil commented 3 years ago

I'm trying to deploy using supervisord but it always gives me an error

Nov 1 07:54:49 PM  [2020-11-01 19:54:49,875] [PID 236] [MainThread] [dramatiq.ForkProcess(0)] [INFO] Fork process 'dramatiq.middleware.prometheus:_run_exposition_server' is ready for action.
Nov 1 07:54:50 PM  [2020-11-01 19:54:50,877] [PID 12] [MainThread] [dramatiq.MainProcess] [CRITICAL] Worker with PID 53 exited unexpectedly (code -9). Shutting down...
Nov 1 07:54:50 PM  [2020-11-01 19:54:50,877] [PID 52] [MainThread] [dramatiq.WorkerProcess(0)] [INFO] Stopping worker process...
Nov 1 07:54:50 PM  [2020-11-01 19:54:50,877] [PID 54] [MainThread] [dramatiq.WorkerProcess(2)] [INFO] Stopping worker process...
Nov 1 07:54:50 PM  [2020-11-01 19:54:50,877] [PID 55] [MainThread] [dramatiq.WorkerProcess(3)] [INFO] Stopping worker process...
Nov 1 07:54:50 PM  [2020-11-01 19:54:50,877] [PID 56] [MainThread] [dramatiq.WorkerProcess(4)] [INFO] Stopping worker process...
Nov 1 07:54:50 PM  [2020-11-01 19:54:50,877] [PID 59] [MainThread] [dramatiq.WorkerProcess(7)] [INFO] Stopping worker process...
Nov 1 07:54:50 PM  [2020-11-01 19:54:50,877] [PID 236] [MainThread] [dramatiq.ForkProcess(0)] [INFO] Stopping fork process...
Nov 1 07:54:50 PM  [2020-11-01 19:54:50,885] [PID 56] [MainThread] [dramatiq.worker.Worker] [INFO] Shutting down...
Nov 1 07:54:50 PM  [2020-11-01 19:54:50,887] [PID 55] [MainThread] [dramatiq.worker.Worker] [INFO] Shutting down...
Nov 1 07:54:50 PM  [2020-11-01 19:54:50,901] [PID 52] [MainThread] [dramatiq.worker.Worker] [INFO] Shutting down...
Nov 1 07:54:51 PM  [2020-11-01 19:54:51,497] [PID 54] [MainThread] [dramatiq.worker.Worker] [INFO] Shutting down...
Nov 1 07:54:51 PM  [2020-11-01 19:54:51,688] [PID 59] [MainThread] [dramatiq.worker.Worker] [INFO] Shutting down...

Any suggestion here? I'm triggering the command by running rundramatiq that was provided but it doesn't work

Bogdanp commented 3 years ago

Looks like something is killing your processes. I'm not familiar with supervisord so I'm not sure what could be causing that. Does your system have enough memory? It could be that the process is being killed by the OOM killer. What happens if you run the app without supervisord?

tarsil commented 3 years ago

But I need supervisord to make sure ai can control the auto restarts and so on, this is for production

tarsil commented 3 years ago

I have a more powerful app running that uses the same memory, so might not be that

Bogdanp commented 3 years ago

But I need supervisord to make sure ai can control the auto restarts and so on, this is for production

Right, I understand that, but the reason I asked you to run it without was to see if the issue still occurs. I'd like to determine if it's supervisord that's killing it or if it's something else.

tarsil commented 3 years ago

Apologies, I didn't mention that. I've tried and still happens the same

cchacholiades commented 3 years ago

I am as well trying to figure out on how to use rundramatiq in production. @tarsil I thought of using supervisord to make sure it always runs, but in my case I think I need to use systemd. What is the recommended way to deploy django dramatiq in a production environment @Bogdanp, how can it be daemonized?

jcass77 commented 3 years ago

We use supervisord to monitor dramatiq - no issues.

Configuring with systemd should also not present any special challenges.

vangale commented 3 years ago

We use systemd. Our service file looks something like:

Description=Dramatiq Task Queue Workers
After=syslog.target

[Service]
Type=simple
Environment=DJANGO_SETTINGS_MODULE=app.settings
WorkingDirectory=/srv/app
User=someone
Group=someone
ExecStart=/srv/app/bin/python3 manage.py rundq --log-file /srv/app/log/dramatiq.log --processes 2 --threads 2
Restart=always
KillSignal=SIGQUIT

[Install]
WantedBy=multi-user.target

Save that in /etc/systemd/system with a name like dramatiq.service then run systemctl daemon-reload and then systemctl start dramatiq.

In the above case, /srv/app is a virtualenv so we run python3 from that bin directory to "activate" the venv.

This is probably a better approach now than using supervisord, unless you are running dramatiq tasks in a container.

mangelozzi commented 2 years ago

We use systemd. Our service file looks something like:

Description=Dramatiq Task Queue Workers
After=syslog.target

[Service]
Type=simple
Environment=DJANGO_SETTINGS_MODULE=app.settings
WorkingDirectory=/srv/app
User=someone
Group=someone
ExecStart=/srv/app/bin/python3 manage.py rundq --log-file /srv/app/log/dramatiq.log --processes 2 --threads 2
Restart=always
KillSignal=SIGQUIT

[Install]
WantedBy=multi-user.target

Refering to http://supervisord.org/configuration.html#fcgi-program-x-section-settings: Trying to understand your config, but can't find help on some of the options, e.g. .After, Type, WorkingDirectory, KillSignal, ExecStart. Where did these parameters come from? Should ExecStart not be command? And KillSignal should be stopsignal?

mangelozzi commented 2 years ago

I had the same issue. Adding the directory parameter solved it, as when it start in the wrong dir, import were failing. Heres my config before its rendered:

; SYM LINK FILE INTO -> {{ SUPERVISOR_CONF_DRAMATIQ }}

[program:dramatiq]
command={{ PYTHON_VENV_BIN }} {{ SRC }}/manage.py rundramatiq --processes {{ CPU_CORES }} --threads 4
priority=3
directory={{ SRC }}

stdout_logfile={{ SUPERVISOR_LOG }}/dramatiq_stdout.log
stderr_logfile={{ SUPERVISOR_LOG }}/dramatiq_stderr.log
stdout_logfile_maxbytes=2MB
stderr_logfile_maxbytes=2MB