HTTP endpoint that counts ready gunicorn workers
Project description
gunicorn_worker_healthcheck
HTTP endpoint that counts ready gunicorn workers
When using the default sync gunicorn worker, using an HTTP endpoint of the application itself
(i.e. that is also handled by the same mechanism, namely the gunicorn workers, as normal application traffic)
to check whether the application is able to handle traffic
(and to e.g. remove it from the load balancing rotation on failure)
can lead to negative feedback loops in high load situations:
The workers may become so backed up with application requests that they are unable to respond to the healthcheck requests in a timely manner. Thus, this application is removed from serving traffic, leaving even less applications to serve the incoming traffic, thus increasing the chance that they, too, will become backed up -- repeat until no applications are available for serving traffic at all.
This package provides an alternative healthcheck endpoint that a) is served by a separate thread, independent of the main application traffic b) only checks whether the application and gunicorn startup process has completed (i.e. any/all gunicorn worker processes have reported to be ready).
Usage
Put this into your config file (usually gunicorn.conf.py):
import gunicorn_worker_healthcheck
healthcheck_bind = '127.0.0.1:8001'
gunicorn_worker_healthcheck.start(globals())
This starts an HTTP server in a thread;
on request it counts the number of workers that have notified they are ready
(using the post_worker_init hook to write a pid file).
If the required number of workers are ready, it returns HTTP 200, else 500.
Configuration
healthcheck_bindhost:port on which to listen for healthcheck requests (default: None, i.e. healthcheck is disabled)healthcheck_require_workerscount of workers that must be ready for the healthcheck to report success (default: 1)healthcheck_directorydirectory in which to store the state files, one per worker (default:'', i.e. the current directory)healthcheck_filenameformat string how to name the state files, must contain one placeholder{}for the pid (default:'.gunicorn.worker.{}')
gunicorn_worker_healthcheck Changes
1.0.0 (2023-05-19)
- Initial release (initial)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gunicorn_worker_healthcheck-1.0.0.tar.gz.
File metadata
- Download URL: gunicorn_worker_healthcheck-1.0.0.tar.gz
- Upload date:
- Size: 4.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a790b0debd57852997aa4004fe25820153f689d1e1fdcf75db9990a8b63b1e7a
|
|
| MD5 |
fcd4cbbe9cebe609476a83e77d05ae76
|
|
| BLAKE2b-256 |
36b2d430afd38117b9f7c2ba834c15b8f0a06dc367bfaa47c38bc99637ab11bf
|
File details
Details for the file gunicorn_worker_healthcheck-1.0.0-py3-none-any.whl.
File metadata
- Download URL: gunicorn_worker_healthcheck-1.0.0-py3-none-any.whl
- Upload date:
- Size: 5.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: python-httpx/0.24.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47cdc976e3f8f4a33f65a6e4458c9753807f16c8139f39402cc4690f55e18fb6
|
|
| MD5 |
08c1ab67102a56bf49754f2c5a00ccc7
|
|
| BLAKE2b-256 |
1fed561f42323df261edb6c84e3ec545813ff9d0c20b67d941c76c6e7278431a
|