-
Notifications
You must be signed in to change notification settings - Fork 849
Replace Gunicorn with Granian to improve pgAdmin 4 performance #9786
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
8f36aa8
dbad9fb
0138ee9
072b937
7dbf8cd
2d40dae
d8e6d0a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -178,25 +178,31 @@ if [ -z "${PGADMIN_DISABLE_POSTFIX}" ]; then | |||||||||||||||||
| sudo /usr/sbin/postfix start | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| # Get the session timeout from the pgAdmin config. We'll use this (in seconds) | ||||||||||||||||||
| # to define the Gunicorn worker timeout | ||||||||||||||||||
| TIMEOUT=$(cd /pgadmin4 && /venv/bin/python3 -c 'import config; print(config.SESSION_EXPIRATION_TIME * 60 * 60 * 24)') | ||||||||||||||||||
|
|
||||||||||||||||||
| # NOTE: currently pgadmin can run only with 1 worker due to sessions implementation | ||||||||||||||||||
| # Using --threads to have multi-threaded single-process worker | ||||||||||||||||||
|
|
||||||||||||||||||
| if [ -n "${PGADMIN_ENABLE_SOCK}" ]; then | ||||||||||||||||||
| BIND_ADDRESS="unix:/run/pgadmin/pgadmin.sock" | ||||||||||||||||||
| BIND_ARGS="--uds /run/pgadmin/pgadmin.sock" | ||||||||||||||||||
| else | ||||||||||||||||||
| BIND_ARGS="--host ${PGADMIN_LISTEN_ADDRESS:-[::]} --port ${PGADMIN_LISTEN_PORT:-80}" | ||||||||||||||||||
| if [ -n "${PGADMIN_ENABLE_TLS}" ]; then | ||||||||||||||||||
| BIND_ADDRESS="${PGADMIN_LISTEN_ADDRESS:-[::]}:${PGADMIN_LISTEN_PORT:-443}" | ||||||||||||||||||
| else | ||||||||||||||||||
| BIND_ADDRESS="${PGADMIN_LISTEN_ADDRESS:-[::]}:${PGADMIN_LISTEN_PORT:-80}" | ||||||||||||||||||
| BIND_ARGS="--host ${PGADMIN_LISTEN_ADDRESS:-[::]} --port ${PGADMIN_LISTEN_PORT:-443}" | ||||||||||||||||||
| fi | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| if [ -n "${PGADMIN_ENABLE_TLS}" ]; then | ||||||||||||||||||
| exec /venv/bin/gunicorn --limit-request-line "${GUNICORN_LIMIT_REQUEST_LINE:-8190}" --timeout "${TIMEOUT}" --bind "${BIND_ADDRESS}" -w 1 --threads "${GUNICORN_THREADS:-25}" --access-logfile "${GUNICORN_ACCESS_LOGFILE:--}" --keyfile /certs/server.key --certfile /certs/server.cert -c gunicorn_config.py run_pgadmin:app | ||||||||||||||||||
| if [ "${GUNICORN_ACCESS_LOGFILE:--}" = "-" ]; then | ||||||||||||||||||
| ACCESS_LOG_ARGS="--access-log" | ||||||||||||||||||
| elif [ -n "${GUNICORN_ACCESS_LOGFILE}" ]; then | ||||||||||||||||||
| echo "Warning: GUNICORN_ACCESS_LOGFILE file paths are not supported with Granian. Access logging disabled." >&2 | ||||||||||||||||||
| ACCESS_LOG_ARGS="--no-access-log" | ||||||||||||||||||
| else | ||||||||||||||||||
| exec /venv/bin/gunicorn --limit-request-line "${GUNICORN_LIMIT_REQUEST_LINE:-8190}" --limit-request-fields "${GUNICORN_LIMIT_REQUEST_FIELDS:-100}" --limit-request-field_size "${GUNICORN_LIMIT_REQUEST_FIELD_SIZE:-8190}" --timeout "${TIMEOUT}" --bind "${BIND_ADDRESS}" -w 1 --threads "${GUNICORN_THREADS:-25}" --access-logfile "${GUNICORN_ACCESS_LOGFILE:--}" -c gunicorn_config.py run_pgadmin:app | ||||||||||||||||||
| ACCESS_LOG_ARGS="--no-access-log" | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| TLS_ARGS="" | ||||||||||||||||||
| if [ -n "${PGADMIN_ENABLE_TLS}" ]; then | ||||||||||||||||||
| TLS_ARGS="--ssl-keyfile /certs/server.key --ssl-certificate /certs/server.cert" | ||||||||||||||||||
| fi | ||||||||||||||||||
|
|
||||||||||||||||||
| # Keep the existing environment variables for backward compatibility. | ||||||||||||||||||
| exec /venv/bin/granian --interface wsgi --workers 1 --blocking-threads "${GUNICORN_THREADS:-25}" ${ACCESS_LOG_ARGS} ${TLS_ARGS} ${BIND_ARGS} run_pgadmin:app | ||||||||||||||||||
|
Comment on lines
+206
to
+207
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: find . -name "entrypoint.sh" -type f | head -20Repository: pgadmin-org/pgadmin4 Length of output: 90 🏁 Script executed: cat -n pkg/docker/entrypoint.sh | sed -n '200,215p'Repository: pgadmin-org/pgadmin4 Length of output: 495 🌐 Web query:
💡 Result: In Granian 2.7.2, nothing changed about backpressure or blocking-threads specifically—the 2.7.2 patch release is about ASGI websocket handling/metrics fixes (e.g., rejection flow, Django Channels hang) and dependency bumps. [1] What “backpressure” is (and why it matters for WSGI)Granian’s backpressure is a per-worker safeguard that stops the worker accept-loop from taking more connections when “too much work” is already queued for Python. Think of it as a server-level secondary backlog (in addition to the OS listen backlog). [2] Key WSGI nuance: because it acts at the connection accept level, it limits connections, not individual HTTP requests; lots of keep-alive connections (common behind reverse proxies) can “consume” backpressure capacity. [2] What “blocking-threads” is (and how it differs)Granian’s blocking threads are the threads in a worker that interact with the Python interpreter (i.e., execute your app and contend for the GIL). [2] Granian explicitly notes:
Practical difference for WSGI
Granian generally recommends not over-tuning the threadpool and instead setting an appropriate backpressure limit for your environment/workload. [2][3] Rule of thumb for WSGI tuning
Sources: GitHub release notes for 2.7.2 [1]; Granian README / docs on workers, blocking threads, and backpressure [2]; PyPI project description mirroring the same guidance [3]. Add explicit Granian backpressure; Granian treats 🛠️ Suggested change # Keep the existing environment variables for backward compatibility.
-exec /venv/bin/granian --interface wsgi --workers 1 --blocking-threads "${GUNICORN_THREADS:-25}" ${ACCESS_LOG_ARGS} ${TLS_ARGS} ${BIND_ARGS} run_pgadmin:app
+GRANIAN_BACKPRESSURE="${GRANIAN_BACKPRESSURE:-${GUNICORN_THREADS:-25}}"
+exec /venv/bin/granian --interface wsgi --workers 1 \
+ --blocking-threads "${GUNICORN_THREADS:-25}" \
+ --backpressure "${GRANIAN_BACKPRESSURE}" \
+ ${ACCESS_LOG_ARGS} ${TLS_ARGS} ${BIND_ARGS} run_pgadmin:app📝 Committable suggestion
Suggested change
🧰 Tools🪛 Shellcheck (0.11.0)[info] 207-207: Double quote to prevent globbing and word splitting. (SC2086) [info] 207-207: Double quote to prevent globbing and word splitting. (SC2086) 🤖 Prompt for AI Agents |
||||||||||||||||||
|
|
||||||||||||||||||
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 90
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 1198
🌐 Web query:
Granian 2.7.2 --ssl-protocol-min default value documentation💡 Result:
In Granian 2.7.2, the CLI option:
--ssl-protocol-min [tls1.2|tls1.3]has a default value of
tls1.3(env varGRANIAN_SSL_PROTOCOL_MIN). [1]🌐 Web query:
Gunicorn SSL certificate keyfile default TLS version💡 Result:
keyfile(private key) default:None(no key configured unless you set it). (docs.gunicorn.org)certfiledefault:None. (docs.gunicorn.org)ssl_version) default:ssl.PROTOCOL_TLS(configured in Gunicorn as_SSLMethod.PROTOCOL_TLS). This means Gunicorn will negotiate the highest protocol version supported by both client and server, with the effective enabled/disabled versions depending on your Python + OpenSSL build and defaults. (docs.gunicorn.org)How to explicitly control it:
ssl_version = "TLSv1_2"(Gunicorn example also notes this as minimum TLS 1.2 for HTTP/2). (gunicorn.org)ssl_contextand setcontext.minimum_version(e.g., TLS 1.3). (docs.gunicorn.org)Citations:
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 46
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 125
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 76
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 46
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 46
🏁 Script executed:
# Examine the Dockerfile to understand the base image and Python version head -30 ./DockerfileRepository: pgadmin-org/pgadmin4
Length of output: 860
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 860
🏁 Script executed:
Repository: pgadmin-org/pgadmin4
Length of output: 769
Don't silently raise the TLS floor to 1.3.
Granian 2.7.2 defaults
--ssl-protocol-mintotls1.3, while Gunicorn'sssl.PROTOCOL_TLSdefaults to negotiating TLS 1.2+. Because this branch only adds--ssl-keyfile/--ssl-certificate, TLS-enabled containers now reject TLS 1.2 clients without any opt-in. If that isn't intentional, set an explicit minimum or surface it as a configurable migration knob.🛠️ Suggested change
TLS_ARGS="" if [ -n "${PGADMIN_ENABLE_TLS}" ]; then - TLS_ARGS="--ssl-keyfile /certs/server.key --ssl-certificate /certs/server.cert" + TLS_ARGS="--ssl-keyfile /certs/server.key --ssl-certificate /certs/server.cert --ssl-protocol-min ${GRANIAN_SSL_PROTOCOL_MIN:-tls1.2}" fi📝 Committable suggestion
🤖 Prompt for AI Agents