How to speed up API response?
jcode
PROOP

10 months ago

My NodeJS API responds pretty slow to requests to the public network IP Railway provides.
Anyway to speed this up?

27 Replies

jcode
PROOP

10 months ago

5a8681b5-f0ee-46a2-bed3-62fba619de18


medim
MODERATOR

10 months ago

Did you deploy this API in a region near your end user/you?


medim
MODERATOR

10 months ago

How are you measuring the latency of the requests?


jcode
PROOP

10 months ago

Yeah Amsterdam and i'm in Belgium


jcode
PROOP

10 months ago

Via the Network tab in DevTools, it's around 40ms to 69ms. Some are 100ms


jcode
PROOP

10 months ago

I got very good ping and internet at my house, so that shouldn't be a big factor.


medim
MODERATOR

10 months ago

Are you using the metal edge network? You can check that in your service -> public networking


jcode
PROOP

10 months ago

Yeah

1366872241878335500


medim
MODERATOR

10 months ago

Can you try disabling it and seeing if the latency lowers or is more consistent?


jcode
PROOP

10 months ago

As in downgrading the network?


jcode
PROOP

10 months ago

(clicking that refresh icon?)


jcode
PROOP

10 months ago

If it's not better, can I still go back to Metal edge network?


medim
MODERATOR

10 months ago

yes


medim
MODERATOR

10 months ago

and yes


jcode
PROOP

10 months ago

It's the same


jcode
PROOP

10 months ago

Maybe i'm used to quicker cuz of local environment and now everything else feels slow


jcode
PROOP

10 months ago

But there probably isn't much I can do right other than improve my NodeJS code for better performance?


mikexie360
PRO

10 months ago

details on what the API is doing?

if the API has to handle a lot of work, then here are some solutions that I can think of.

  • Do API calls asynchronously.

  • Do API calls in big batches all at once

  • Do API calls in parallel instead of concurrent.


jcode
PROOP

10 months ago

So basically improve my code


jcode
PROOP

10 months ago

I already do most of those things


mikexie360
PRO

10 months ago

ok, so the only thing now is to probably try other regions, or other cloud providers


mikexie360
PRO

10 months ago

You could probably to also look into finding out if you could test the latency remotely on a different computer in a different geographical location compared to yours.

So use a service on a different cloud provider, call that api on railway, and log the latency to see if it is a regional thing.


adam
MODERATOR

10 months ago

this is likely the case. api calls to a local server will have 0ms rtt, plus the actual processing that the api is doing


adam
MODERATOR

10 months ago

more details on what processing is actually being done by your api would be helpful for suggesting optimizations


adam
MODERATOR

10 months ago

40ms is not bad


jcode
PROOP

10 months ago

Oh okay 🙂


jcode
PROOP

10 months ago

Thanks guys


Loading...