4 months ago
hey there! ive a railway project with a simple setup - a postgres database and a service that is an api and utilizes the database. the database is present in sgp region, and the api has two replicas - one in us-east and one in sgp. i was doing benchmarking for the api and noticed that the database queries were taking quite a lot of time. i ran explain analyze on the queries, which were heavily utilized by the api. the total execution time returned by explain analyze is sub 1 ms, but during benchmarking, the db queries (those queries were similar to the ones on which ive run explain analyze) were taking 150-180 ms for execution. ive done the benchmarking from india, so the replica in sgp region must be the one which should have processed my request.
the connection between the database and api is through an internal network, what could be the reason behind the huge network latency?
0 Replies
4 months ago
Hello,
I can confirm that your requests were hitting the deployment in Asia, and that you are correctly using the private network. There are no issues on the Railway setup side of things.
But those times you gave (150-180) almost perfectly match the average to p99 private DNS lookup times in our Asia region, but DNS lookup times shouldn't come into play with database queries unless you are opening a new connection to the database for every query, and that is what I think is happening here. Could you please check if you are using a pooled database connection?
Best,
Brody