Skip to content

Commit fd7bf4d

Browse files
committed
feat: replace gunicorn with granian
- Doesn't fail requests when the worker needs to be restarted in multi-threaded environment (issue #3507). - Supports limiting RSS usage reducing number of restarts. - The WSGI core should perform way better (I don't expect visible impact on Weblate here, but still it heavily reduces the overhead). Fixes #3507
1 parent c76b9d2 commit fd7bf4d

File tree

4 files changed

+17
-19
lines changed

4 files changed

+17
-19
lines changed

etc/nginx/default.tpl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ server {
7676

7777
{% if WEBLATE_ANUBIS_URL %}
7878
location ~ ^{{ WEBLATE_URL_PREFIX }}(/widget/|/exports/rss/|/healthz/|/hooks/|/accounts/complete/) {
79-
proxy_pass http://unix:/run/gunicorn/app/weblate/socket;
79+
proxy_pass http://unix:/run/granian/weblate.socket;
8080
}
8181
{% endif %}
8282

@@ -85,7 +85,7 @@ server {
8585
auth_request /.within.website/x/cmd/anubis/api/check;
8686
error_page 401 = @redirectToAnubis;
8787
{% endif %}
88-
proxy_pass http://unix:/run/gunicorn/app/weblate/socket;
88+
proxy_pass http://unix:/run/granian/weblate.socket;
8989
}
9090
}
9191

etc/supervisor/conf.d/web.conf

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,19 @@
1-
[program:gunicorn]
2-
command = /app/venv/bin/gunicorn
1+
[program:granian]
2+
command = /app/venv/bin/granian
3+
--no-ws
4+
--workers-max-rss 350
5+
--runtime-mode mt
6+
--interface wsgi
7+
--workers 2
8+
--backpressure %(ENV_WEB_WORKERS)s
9+
--runtime-threads %(ENV_WEB_RUNTIME_THREADS)s
10+
--uds /run/granian/weblate.socket
311
weblate.wsgi:application
4-
--preload
5-
--timeout 3600
6-
--graceful-timeout 3600
7-
--max-requests 7000
8-
--max-requests-jitter 1000
9-
--workers=2
10-
--threads=%(ENV_WEB_WORKERS)s
11-
--access-logfile='-'
12-
--error-logfile='-'
13-
--forwarded-allow-ips="*"
14-
--bind unix:///run/gunicorn/app/weblate/socket
1512
stdout_logfile=/dev/fd/1
1613
stdout_logfile_maxbytes=0
1714
redirect_stderr=true
1815
autorestart = true
1916

20-
2117
[program:nginx]
2218
command = /usr/sbin/nginx -g "daemon off;"
2319
stdout_logfile=/dev/fd/1

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ djangorestframework==3.16.0
2626
gevent==25.5.1
2727
git-review==2.5.0
2828
google-cloud-translate==3.21.1
29-
gunicorn==23.0.0
29+
granian==2.5.0
3030
hiredis==3.2.1
3131
html2text==2025.4.15
3232
iniparse==0.5

start

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -253,8 +253,8 @@ if [ "$1" = "runserver" ]; then
253253
# Compress js and css
254254
run_weblate compress --force --traceback
255255

256-
# uswgi dir
257-
mkdir -p /run/gunicorn/app/weblate
256+
# wsgi socket dir
257+
mkdir -p /run/granian/
258258

259259
# Celery pid, remove possible stale PID file
260260
mkdir -p /run/celery
@@ -308,6 +308,7 @@ set_real_ip_from 0.0.0.0/0;
308308
: "${CELERY_BEAT_OPTIONS:=""}"
309309
: "${CELERY_SINGLE_OPTIONS:="--concurrency $WEBLATE_WORKERS"}"
310310
: "${WEB_WORKERS:="$WEBLATE_WORKERS"}"
311+
: "${WEB_RUNTIME_THREADS:="$((WEB_WORKERS / 2))"}"
311312
# This is for legacy configurations, should be removed in the future
312313
if [ -n "$UWSGI_WORKERS" ]; then
313314
echo "Configuration using UWSGI_WORKERS is deprecated, please use WEB_WORKERS instead!"
@@ -322,6 +323,7 @@ set_real_ip_from 0.0.0.0/0;
322323
export CELERY_BEAT_OPTIONS
323324
export CELERY_SINGLE_OPTIONS
324325
export WEB_WORKERS
326+
export WEB_RUNTIME_THREADS
325327

326328
# Execute supervisor
327329
exec supervisord \

0 commit comments

Comments
 (0)