First off, in the spirit of gratitude for Railway, I wanna say thanks because this company just saved my ass for my undergrad thesis.
So here's my problem:
I basically deployed a 225mb machine learning model as a RESTful API service (FastAPI).
I've been on the Developer Plan for more than a month now. So the 512mb cap is off, but I just wanna know if this memory usage is normal for an app like this. Even when it's idle, it's consuming 1.8GB RAM constantly.
This usage has bumped me up to $4.51 in just 9 days of December and is estimated to be $18.03 by the end of the month. I don't know if either Railway is scamming me at this point just because the 512mb cap on memory is off or if I'm just unnecessarily using too much memory in my app.
My temporary solution
I did find a way to lower it down just now which is basically just loading the model within a function instead of globally within main.py. (you can see the drop in the graph at the end there).
The result is a somewhat slower request (because the model has to load again for every request), but lower usage when the API is not being used.
I monitored this on Task Manager so it does save around 200mb. What doesn't make sense to me how it uses more memory on Railway when deployed compared to when it's running on my computer. It has lower usage on my computer. Also, the model is only 220mb, why does it have to use 1.8GB memory constantly, even when idle.
Another thing, after every request, the idle memory usage sort of increases. Is this normal for FastAPI apps? I didn't know RAM usage grows over time. Does this mean I have to restart the app every now and then so it goes back to the lower initial memory usage again?