How can a debug slow mysql query times?
passatgt
PROOP

a month ago

Hi! I'm migrating a freescout instance from a simple hostinger.com shared hosting over to Railway. I'm using this template: https://railway.com/deploy/cgZiHc

I've setup everything but i find it quite slow. For example running this simple query: SELECT * FROM mailboxes - i get this on hostinger:

Showing rows 0 - 2 (3 total, Query took 0.0002 seconds.)

And this on railway:

Showing rows 0 - 2 (3 total, Query took 0.0054 seconds.)

Exactly the same database and it's 27x slower. This is not normal right? Obviously this query is still fast, but while using the app itself, loading times are 1+ sec / page, while on hostinger it works under 300ms. How can i debug this? Thanks

$20 Bounty

7 Replies

Status changed to Open Railway about 1 month ago


domehane
FREE

a month ago

.


domehane

.

domehane
FREE

a month ago

Hello passatgt,

i think the latency gap is normal , on hostinger your app and db run on the same machine so network cost is zero, on railway they're separate services so every query has a network round trip

two things to check, first hat is your db_host set to? if it's a public hostname you're routing every query over the public internet. switch it to the private .railway.internal hostname from your mysql service settings

and second are both your app and mysql service in the same region? if not, railway docs say you get 50-150ms added per query by design

so can you share what your db_host is and which region each service is deployed to?


optimalresource
PRO

a month ago

I think the issue may be in how the MySQL database is being accessed on railway. If you are accessing it using the internal link, it should be much faster, but through DATABASE_PUBLIC_URL, it will bring about more cost and less speed. So try connecting using the internal url and ssh directly into the instance using railway command line. Also put the services in the same project to consume the DB internally.


domehane

Hello **passatgt,** i think the latency gap is normal , on hostinger your app and db run on the same machine so network cost is zero, on railway they're separate services so every query has a network round trip two things to check, first hat is your db\_host set to? if it's a public hostname you're routing every query over the public internet. switch it to the private .railway.internal hostname from your mysql service settings and second are both your app and mysql service in the same region? if not, railway docs say you get 50-150ms added per query by design so can you share what your db\_host is and which region each service is deployed to?

(The application already uses private networking. You can check this through its preconfigured variables when deploying the template.)


0x5b62656e5d

(The application already uses private networking. You can check this through its preconfigured variables when deploying the template.)

domehane
FREE

a month ago

ok then i think it's the region mismatch, @passatgt are both your app and mysql service deployed in the same region? you can check this in each service's settings tab


By default, services will be deployed in the user's preferred region (under account settings), but doesn't hurt to check.


0x5b62656e5d

By default, services will be deployed in the user's preferred region (under account settings), but doesn't hurt to check.

passatgt
PROOP

a month ago

Yes, using private networking, same region, so thats not the issue.


Welcome!

Sign in to your Railway account to join the conversation.

Loading...