mirror of
https://github.com/frappe/gunicorn.git
synced 2026-07-01 18:21:30 +08:00
Replace lock-based request serialization with queue-based approach: - Each worker now has a dedicated asyncio.Queue and consumer task - route_request() submits (request, future) to queue and awaits future - Consumer task processes requests sequentially per worker - No lock contention - pure async queue operations Benefits: - Clearer separation of concerns - Better visibility into request backlog (queue.qsize()) - Eliminates lock contention under high concurrency Changes: - worker_locks dict replaced with worker_queues and worker_consumers - Added _start_worker_consumer() to create queue and consumer per worker - Added _execute_on_worker() for actual worker communication - Updated _cleanup_worker() to cancel consumer tasks - Updated stop() to cancel all consumers before shutdown Benchmark results (4 workers, isolated): - throughput_10ms: 333 req/s, 0 failures - overload_10ms (200 clients): 334 req/s, 0 failures - All tests pass with perfect round-robin distribution
Gunicorn
========
.. image:: https://img.shields.io/pypi/v/gunicorn.svg?style=flat
:alt: PyPI version
:target: https://pypi.python.org/pypi/gunicorn
.. image:: https://img.shields.io/pypi/pyversions/gunicorn.svg
:alt: Supported Python versions
:target: https://pypi.python.org/pypi/gunicorn
.. image:: https://github.com/benoitc/gunicorn/actions/workflows/tox.yml/badge.svg
:alt: Build Status
:target: https://github.com/benoitc/gunicorn/actions/workflows/tox.yml
Gunicorn 'Green Unicorn' is a Python WSGI HTTP Server for UNIX. It's a pre-fork
worker model ported from Ruby's Unicorn_ project. The Gunicorn server is broadly
compatible with various web frameworks, simply implemented, light on server
resource usage, and fairly speedy.
**New in v24**: Native ASGI support (beta) for async frameworks like FastAPI!
Quick Start
-----------
.. code-block:: bash
pip install gunicorn
gunicorn myapp:app --workers 4
For ASGI applications (FastAPI, Starlette):
.. code-block:: bash
gunicorn myapp:app --worker-class asgi
Features
--------
- WSGI support for Django, Flask, Pyramid, and any WSGI framework
- **ASGI support** (beta) for FastAPI, Starlette, Quart
- uWSGI binary protocol for nginx integration
- Multiple worker types: sync, gthread, gevent, eventlet, asgi
- Graceful worker process management
- Compatible with Python 3.12+
Documentation
-------------
Full documentation at https://gunicorn.org
- `Quickstart <https://gunicorn.org/quickstart/>`_
- `Configuration <https://gunicorn.org/configure/>`_
- `Deployment <https://gunicorn.org/deploy/>`_
- `Settings Reference <https://gunicorn.org/reference/settings/>`_
Community
---------
- Report bugs on `GitHub Issues <https://github.com/benoitc/gunicorn/issues>`_
- Chat in `#gunicorn`_ on `Libera.chat`_
- See `CONTRIBUTING.md <CONTRIBUTING.md>`_ for contribution guidelines
Sponsors
--------
Gunicorn is maintained thanks to our sponsors. `Become a sponsor <https://github.com/sponsors/benoitc>`_.
.. Sponsor logos will appear here
License
-------
Gunicorn is released under the MIT License. See the LICENSE_ file for details.
.. _Unicorn: https://bogomips.org/unicorn/
.. _`#gunicorn`: https://web.libera.chat/?channels=#gunicorn
.. _`Libera.chat`: https://libera.chat/
.. _LICENSE: https://github.com/benoitc/gunicorn/blob/master/LICENSE
Languages
Python
99.9%