a year ago
I'm trying to add workers to my Flask application. I was familiar with how to add them when Railway used Procfile, but I know that the Flask template now uses a railway.json file instead. Wondering if I can add an argument to railway.json that will allow for additional workers? Also wondering what the default number of workers is set to?
Here's my railway.json:
{
"$schema": "https://railway.app/railway.schema.json",
"build": {
"builder": "NIXPACKS"
},
"deploy": {
"restartPolicyType": "ON_FAILURE",
"restartPolicyMaxRetries": 10
}
}Thanks!
5 Replies
a year ago
Hello,
On Heroku you would run your whole stack in the same dyno since they charge per dyno, on Railway you would want to run your app, and workers in separate services.
We have a great guide that covers that here -
https://docs.railway.com/guides/django#set-up-database-migrations-celery-beat-and-celery
Status changed to Awaiting User Response Railway • about 1 year ago
a year ago
My deployment is setup with the main API as a service, and each background worker is in a separate service. I guess, the main Flask API (during peak demand times) is getting overwhelmed and slowing down. I've isolated this to likely not being a database/session management issue, and I'm wondering how to increase the number of synchronous operations my Flask service on Railway can do at a given time. Looking at the Metrics, and it's not coming anywhere close to the maximum, so wondering if there are further deployment optimizations I can make to speed things up.
Status changed to Awaiting Railway Response Railway • about 1 year ago
a year ago
Right now you are running Gunicorn with its default sync workers, I would recommend running gunicorn with an async worker such as uvicorn.
Status changed to Awaiting User Response Railway • about 1 year ago
a year ago
I'm not a DevOps engineer so apologies for the newbie question: would I need to create a Procfile to do that?
Status changed to Awaiting Railway Response Railway • about 1 year ago
Status changed to Awaiting User Response Railway • about 1 year ago
6 months ago
This thread has been marked as solved automatically due to a lack of recent activity. Please re-open this thread or create a new one if you require further assistance. Thank you!
Status changed to Solved Railway • 6 months ago