R
Railway5mo ago
Nife

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?
No description
12 Replies
Percy
Percy5mo ago
Project ID: c3b65042-0b65-41cd-846d-d4bd9bf07397
Joshie
Joshie5mo 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
Nife
NifeOP5mo ago
I am using gunicorn for WSGI and uvicorn for ASGI
Brody
Brody5mo ago
please explain how you are using both in your deployment?
Nife
NifeOP5mo ago
My understanding was that one handles WSGI and the other handles ASGI I am doing more research right now
Brody
Brody5mo ago
right but that doesn't explain what you are doing specifically
Nife
NifeOP5mo ago
this is what my start command looks like: gunicorn someapp.asgi:application -w 1 -k uvicorn.workers.UvicornWorker
Brody
Brody5mo ago
okay gunicorn with a uvicorn event worker
Joshie
Joshie5mo 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”
Nife
NifeOP5mo ago
is it fine to do this, can one handle both asgi and wsgi hmmmm
Brody
Brody5mo ago
do you need to handle both? what's your usecase?
Nife
NifeOP5mo ago
Currently I am handling regular requests synchronous and i added uvicorn into the project when i implemented a messaging system with websockets/consumers
Want results from more Discord servers?
Add your server