Django project Memory usage | Tips
printnifesimi
HOBBYOP

2 years ago

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?

14 Replies

printnifesimi
HOBBYOP

2 years ago

c3b65042-0b65-41cd-846d-d4bd9bf07397


coderjoshdk
TRIAL

2 years ago

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


printnifesimi
HOBBYOP

2 years ago

I am using gunicorn for WSGI and uvicorn for ASGI


2 years ago

please explain how you are using both in your deployment?


printnifesimi
HOBBYOP

2 years ago

My understanding was that one handles WSGI and the other handles ASGI


printnifesimi
HOBBYOP

2 years ago

I am doing more research right now


2 years ago

right but that doesn't explain what you are doing specifically


printnifesimi
HOBBYOP

2 years ago

this is what my start command looks like:
gunicorn someapp.asgi:application -w 1 -k uvicorn.workers.UvicornWorker


2 years ago

okay gunicorn with a uvicorn event worker


coderjoshdk
TRIAL

2 years ago

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”


printnifesimi
HOBBYOP

2 years ago

is it fine to do this, can one handle both asgi and wsgi


printnifesimi
HOBBYOP

2 years ago

hmmmm


2 years ago

do you need to handle both? what's your usecase?


printnifesimi
HOBBYOP

2 years ago

Currently I am handling regular requests synchronous
and i added uvicorn into the project when i implemented a messaging system with websockets/consumers


Loading...