Django project Memory usage | Tips

printnifesimiHOBBY

10 months 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?

0 Replies

printnifesimiHOBBY

10 months ago

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


coderjoshdkTRIAL

10 months 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


printnifesimiHOBBY

10 months ago

I am using gunicorn for WSGI and uvicorn for ASGI


10 months ago

please explain how you are using both in your deployment?


printnifesimiHOBBY

10 months ago

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


printnifesimiHOBBY

10 months ago

I am doing more research right now


10 months ago

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


printnifesimiHOBBY

10 months ago

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


10 months ago

okay gunicorn with a uvicorn event worker


coderjoshdkTRIAL

10 months 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”


printnifesimiHOBBY

10 months ago

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


printnifesimiHOBBY

10 months ago

hmmmm


10 months ago

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


printnifesimiHOBBY

10 months ago

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