Django project Memory usage | Tips
Hello reader, I’m Still trying to get a hang of railway.
Deployed a Django project that uses gunicorn and uvicorn with one worker.
It connects to one Postgres DB and reddis for web socket / Django channels stuff.
I don’t currently have any celery implementation for background activities but plan to do so in the future.
My ram usage is currently at about 256MB stable usage. This backend is only interacted with, through a mobile frontend (app). Currently in the testing phase and don’t have a lot of users making requests often. Upon restarting the deployment, the memory usage drops to 104MB
Is this regular for a Django project? Are there anything’s I should be monitoring or checking? Any tips on memory usage?
12 Replies
Project ID:
c3b65042-0b65-41cd-846d-d4bd9bf07397
You are using gunicorn and uvicorn? That doesn't seem right.
But yea, I find that with gunicorn, it is ~100MB of memory per worker. The number can fluctuate. But it does settle to about that. I have a project with 5 workers and about 510MB. So it does seem like double the amount of memory is being used vs needed. (it sounds like a not large django project). And so the first thing I suspect is the use of gunivorn + uvicorn
I am using gunicorn for WSGI and uvicorn for ASGI
please explain how you are using both in your deployment?
My understanding was that one handles WSGI and the other handles ASGI
I am doing more research right now
right but that doesn't explain what you are doing specifically
this is what my start command looks like:
gunicorn someapp.asgi:application -w 1 -k uvicorn.workers.UvicornWorker
okay gunicorn with a uvicorn event worker
You don’t need that much. Just gunicorn is fine. It would explain why you are experiencing double memory. But like, it’s not “wrong” to use both. Just no real gain. So I guess “wrong”
is it fine to do this, can one handle both asgi and wsgi
hmmmm
do you need to handle both? what's your usecase?
Currently I am handling regular requests synchronous
and i added uvicorn into the project when i implemented a messaging system with websockets/consumers