Granian¶
High-performance Rust-based server supporting both ASGI and WSGI.
Use when: Maximum performance, modern deployments Don’t use when: Need mature ecosystem (use Gunicorn or ASGI Mode)
Installation¶
pip install django-prodserver[granian]
Backends¶
ASGI Mode¶
For async Django with WebSocket support:
PRODUCTION_PROCESSES = {
"web": {
"BACKEND": "django_prodserver.backends.servers.granian.GranianASGIServer",
"ARGS": {
"address": "0.0.0.0",
"port": "8000",
"workers": "4",
}
}
}
WSGI Mode¶
For traditional Django:
PRODUCTION_PROCESSES = {
"web": {
"BACKEND": "django_prodserver.backends.servers.granian.GranianWSGIServer",
"ARGS": {
"address": "0.0.0.0",
"port": "8000",
"workers": "4",
}
}
}
Common ARGS¶
Argument |
Default |
Description |
|---|---|---|
|
|
Address to bind |
|
|
Port to bind |
|
|
Worker processes |
|
|
Threads per worker (WSGI) |
|
|
Blocking threads (ASGI) |
|
|
Connection backlog |
|
|
HTTP version ( |
|
|
Log level |
|
|
Enable access logging |
|
|
SSL certificate path |
|
|
SSL key path |
Examples¶
High-Performance ASGI¶
"ARGS": {
"address": "0.0.0.0",
"port": "8000",
"workers": "4",
"blocking-threads": "2",
"log-access": "False",
}
WSGI with Thread Pool¶
"ARGS": {
"address": "0.0.0.0",
"port": "8000",
"workers": "2",
"threads": "4",
}
HTTP/2¶
"ARGS": {
"http": "2",
"workers": "4",
}
ASGI vs WSGI¶
Feature |
ASGI |
WSGI |
|---|---|---|
Async views |
Yes |
No |
WebSockets |
Yes |
No |
Thread model |
Async + blocking |
Thread pool |
Troubleshooting¶
Installation fails: Granian requires Rust on some platforms. Try pip install --upgrade granian
ASGI app not found: Ensure asgi.py exists