Skip to content

Commit ae776cf

Browse files
committed
Add ASGI performance documentation
1 parent 4bff2f3 commit ae776cf

File tree

1 file changed

+53
-1
lines changed

1 file changed

+53
-1
lines changed

docs/content/asgi.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,11 @@ gunicorn main:app --worker-class asgi --bind 0.0.0.0:8000
2424
The ASGI worker provides:
2525

2626
- **HTTP/1.1** with keepalive connections
27+
- **HTTP/2** with multiplexing and server push (requires SSL)
2728
- **WebSocket** support for real-time applications
2829
- **Lifespan protocol** for startup/shutdown hooks
29-
- **Optional uvloop** for improved performance
30+
- **Optional fast HTTP parser** via C extension for high throughput
31+
- **Optional uvloop** for improved event loop performance
3032
- **SSL/TLS** support
3133
- **uWSGI protocol** for nginx `uwsgi_pass` integration
3234

@@ -225,6 +227,56 @@ asgi_loop = "auto" # Use uvloop if available
225227
asgi_lifespan = "auto" # Auto-detect lifespan support
226228
```
227229

230+
## Performance
231+
232+
### Fast HTTP Parser
233+
234+
For maximum performance, install the optional `gunicorn_h1c` C extension:
235+
236+
```bash
237+
pip install gunicorn[fast]
238+
```
239+
240+
This provides a high-performance HTTP parser using picohttpparser with SIMD
241+
optimizations, offering significant speedups for HTTP parsing compared to the
242+
pure Python implementation.
243+
244+
The parser is automatically used when available (`--http-parser auto`), or you
245+
can explicitly require it:
246+
247+
```bash
248+
gunicorn myapp:app --worker-class asgi --http-parser fast
249+
```
250+
251+
| Parser | Description |
252+
|--------|-------------|
253+
| `auto` | Use fast parser if available, otherwise Python (default) |
254+
| `fast` | Require fast parser, fail if unavailable |
255+
| `python` | Force pure Python parser |
256+
257+
### Performance Tips
258+
259+
1. **Use uvloop** for improved event loop performance:
260+
```bash
261+
pip install uvloop
262+
gunicorn myapp:app --worker-class asgi --asgi-loop uvloop
263+
```
264+
265+
2. **Install the fast parser** for optimized HTTP parsing:
266+
```bash
267+
pip install gunicorn[fast]
268+
```
269+
270+
3. **Tune worker count** based on CPU cores:
271+
```bash
272+
gunicorn myapp:app --worker-class asgi --workers $(nproc)
273+
```
274+
275+
4. **Increase connections** for I/O-bound applications:
276+
```bash
277+
gunicorn myapp:app --worker-class asgi --worker-connections 2000
278+
```
279+
228280
## Comparison with Other ASGI Servers
229281

230282
| Feature | Gunicorn ASGI | Uvicorn | Hypercorn |

0 commit comments

Comments
 (0)