Backend API response is slow even though not using max limits

Anonymous
TRIAL

a year ago

Railway metrics says we have a max of 8 vCPUs. The max we're using is only 2.6 vCPUs. But we're still seeing degraded API performance

0 Replies

Anonymous
TRIAL

a year ago

3b58a837-a508-4969-a318-7c37050d177e


is your app a nodejs app?


Anonymous
TRIAL

a year ago

yes


then there's your answer, nodejs is single threaded so most of the time it can't reach max CPU utilization


you should take a look at replicas


Anonymous
TRIAL

a year ago

there is an endpoint that has a lot of external network calls. i tried disabling that and that seems to have fixed it for now.



Anonymous
TRIAL

a year ago

i am assuming the degradation was because there were several requests to that endpoint that were still pending so the newer ones were delayed to get response


Anonymous
TRIAL

a year ago

i tried using throng: https://www.npmjs.com/package/throng
with a concurrency worker count of 4, but didnt help


yeah, if you want to handle those requests you'll need to scale because nodejs won't magically work just by throwing more resources at it


my guess is that your worker count is too low and you're doing a lot of resource intensive tasks


if you need something more advanced, see https://github.com/taskforcesh/bullmq


then you can have multiple instances of your nodejs app processing a queue


Anonymous
TRIAL

a year ago

yeah we use bullmq for something else. we just had huge traffic last few hrs that was not anticipated


Anonymous
TRIAL

a year ago

will try out replicas. how does affect billing?


well get your current service usage times your amount of replicas


replicas is just another instance of your application running


Anonymous
TRIAL

a year ago

how would multiple throng workers vs. replicas differ?


Anonymous
TRIAL

a year ago

does all the replicas share the same 8 vCPUs or do they each get 8 vCPUs?


replicas is the way if you're planning on scaling more than 8vCPUs (or buy the pro plan for 32vCPUs)
throng will only take you to the max of one service resources (8vCPUS or 32vCPUs)



Anonymous
TRIAL

a year ago

got it. thanks! i suppose using more throng workers might help use the max of all resources currently available


yeah, for now it might fix but you might want to take a look at replicas soon or later


Anonymous
TRIAL

a year ago

gonna try that out first as the max being used is just 2.5 vCPUs without throng and around 5 vCPUs with 4 throng workers


Anonymous
TRIAL

a year ago

yup will do


yeah launch 7 throng workers and see how it goes


Anonymous
TRIAL

a year ago

got it. thank you so much for the support! 🙏


Backend API response is slow even though not using max limits - Railway Help Station