DB queries are slower after switch to V2
callmefredcom
PROOP

a year ago

I've switched my web app runtime to V2 as instructed
and I spent 2 hours migrating my DB (which was in another project) to put it in the same project as the web app and user reference variables.
But queries to the DB are now much slower than they used to be when the web app and the DB were in 2 different projects with a LEGACY runtime for the web app.
How can we fix this?
I didn't change anything to the app itself. So it's the switch to V2 and the migration which had a negative impact on performance.

Solved

86 Replies

callmefredcom
PROOP

a year ago

b082e796-c15c-43c8-b3d6-81fc47342308


dev
MODERATOR

a year ago

Are you connected to the database under the private network?


callmefredcom
PROOP

a year ago

yes I am


callmefredcom
PROOP

a year ago

of course


callmefredcom
PROOP

a year ago

that was the whole point


callmefredcom
PROOP

a year ago

bringing the DB inside the web app's project and connecting via the private network


callmefredcom
PROOP

a year ago

MYSQLDATABASE="${{MySQL.MYSQLDATABASE}}"
MYSQLHOST="${{MySQL.MYSQLHOST}}"
MYSQLPASSWORD="${{MySQL.MYSQLPASSWORD}}"
MYSQLPORT="${{MySQL.MYSQLPORT}}"


callmefredcom
PROOP

a year ago

and that's the Python code:

DATABASE_CONFIG = {
'user': 'root',
'password': os.environ.get('MYSQLPASSWORD'),
'host': os.environ.get('MYSQLHOST'),
'port': os.environ.get('MYSQLPORT'),
'database': os.environ.get('MYSQLDATABASE')
}

def getdb(): if hasattr(g, 'dbconn') and g.dbconn.isconnected():
return g.dbconn else: g.dbconn = mysql.connector.connect(**DATABASECONFIG) return g.dbconn


callmefredcom
PROOP

a year ago

it used to be almost instant even when I was connecting from one project to another (via the public access)


callmefredcom
PROOP

a year ago

so it's crazy that now that both the web app and the DB are in the same project, queries are slower


callmefredcom
PROOP

a year ago

the only difference I can see is that the legacy DB was mysql:8 and the new one is mysql:9


callmefredcom
PROOP

a year ago

(the legacy DB was started in Sept 2023, the new one today)


callmefredcom
PROOP

a year ago

it's definitely not a code issue since, again, it worked just fine in the previous configuration earlier today


callmefredcom
PROOP

a year ago

At the moment the app is using mysql-connector-python==8.0.33


dev
MODERATOR

a year ago

that is interesting, I don't really see why that would be the case


callmefredcom
PROOP

a year ago

Well, one way or another, it's the case 🙂


callmefredcom
PROOP

a year ago

any help would be appreciated


dev
MODERATOR

a year ago

yea I don't have the faintest idea why it could be slow for you, I've never seen anyone report a slow private network connection either
I did mention this post to the team though but they're currently out of office for the holidays


dwaynemac
PRO

a year ago

check if your app service and db service are on the same region. if they are on different regions that may be causing the lag.


dev
MODERATOR

a year ago

ooh good catch, thank you

yea I did some more digging and it a lot of people are reporting that their services have been moved to metal, metal doesn't support volumes yet so databases wouldn't be moved, causing the service and database to be in different regions which can cause delay even on private network


dev
MODERATOR

a year ago

Can you check the top of the build logs for your service, it'll mention the region here, let me know what it says


callmefredcom
PROOP

a year ago

web app: [Region: us-west1]


callmefredcom
PROOP

a year ago

database

1320525900101587000


dev
MODERATOR

a year ago

So it is the same region then, unless the UI is correct and the builder is reporting the region incorrectly 🤔


callmefredcom
PROOP

a year ago

So from what I can see in the UI for the web app I have


callmefredcom
PROOP

a year ago

1320526723573485600


callmefredcom
PROOP

a year ago

and for the DB the one above


dev
MODERATOR

a year ago

I found out that hobby deploys are exclusively metal now, which leads me to believe that the builder is incorrectly reporting the region
but then the difference in region would explain the delay, although the delay should still be somewhat minimal


callmefredcom
PROOP

a year ago

so the web app would be in US West California USA and the DB in US West Oregon USA?


dev
MODERATOR

a year ago

exactly


callmefredcom
PROOP

a year ago

and I can't switch back the web app to West Oregon USA?


callmefredcom
PROOP

a year ago

Or would switching to Pro give more control?


dev
MODERATOR

a year ago

Switching to pro would give you more control yes, under the pro plan you'll be able to switch the web app back to oregon


callmefredcom
PROOP

a year ago

it kind of defeats the purpose that 2 services under the same project are now in 2 different regions


callmefredcom
PROOP

a year ago

All of this after spending 2 hours migrating my DB to the same project as the web app to benefit from private networking


callmefredcom
PROOP

a year ago

and they're not in the same region…


dev
MODERATOR

a year ago

very true, I'm not sure why Railway didn't just wait until they had volume support under metal before forcing metal deploys 🤔


dev
MODERATOR

a year ago

don't worry though, volume support should be coming soon and then everything will be in the exact same region once again


callmefredcom
PROOP

a year ago

but now I'm stuck


callmefredcom
PROOP

a year ago

it's either upgrade to Pro or wait


Anonymous
PRO

a year ago

@Fragly am also facing the same challenges for me all my deployment were failing until I changed to v2 after that my app is very slow and getting 504 gateway time out any help


brody
EMPLOYEE

a year ago

in our testing the difference in regions add a +20 ms time to the database queries, that should not be perceived in the end user application unless you are making many databases queries per API route.

if that kind of additional time matters, it's unlikely to be fit for the hobby plan regardless of regions.

you may upgrade to pro or optimize your queries you make.


dwaynemac
PRO

a year ago

my tests show +1 SECOND or above delay


brody
EMPLOYEE

a year ago

For a single database query?


callmefredcom
PROOP

a year ago

Does the Pro plan improve connection speeds? (or query execution speed).


dwaynemac
PRO

a year ago

@brody no. For end user requests.


brody
EMPLOYEE

a year ago

dwaynemac, you would want some kind of tracing to find out where that extra time is coming from, because our platform alone is not adding that much additional time.


brody
EMPLOYEE

a year ago

no, the slow down you are experiencing is not a platform limitation


callmefredcom
PROOP

a year ago

How do you explain it occurred after the migration of the DB to the same project as the web app?
It was working perfectly fine before.
The only rational explanation seems to be the different regions.


brody
EMPLOYEE

a year ago

The zone itself is not causing the issues, instead it's exposing and exacerbating existing inefficiencies or issues in your code; meaning the zone difference is more like a trigger for revealing these issues in your application


callmefredcom
PROOP

a year ago

But why did it work fine before? That's the question.


brody
EMPLOYEE

a year ago

your app and database where in the same zone, and now the tiny bit of extra latency has exacerbated massive inefficiencies in your codebase


brody
EMPLOYEE

a year ago

there's nothing from the platform side of things we can do about this


callmefredcom
PROOP

a year ago

except having both the web app and db in the same region again.
How can I do this?


brody
EMPLOYEE

a year ago

they are still in the same region, just different zones


callmefredcom
PROOP

a year ago

well, in the same zone then, sorry for my semantic error


callmefredcom
PROOP

a year ago

how can I have them in the same zone?


callmefredcom
PROOP

a year ago

Can you set both in the same ZONE if you're on the Pro Plan?


brody
EMPLOYEE

a year ago

yes


callmefredcom
PROOP

a year ago

and pricing wise, it just means that I have to add $15 per month as a "basis" + usage (as for the Hobby plan, for which the basic excl. usage is $5). Correct?


brody
EMPLOYEE

a year ago

$20 plus whatever your resources cost


Anonymous
PRO

a year ago

@Brody My web app and database are in the same region as us west Oregon USA but am having operation time out after 30001 milliseconds with 0 byte received on railway app during database queries


brody
EMPLOYEE

a year ago

That would be an issue with your application that we are not able to provide support for


Anonymous
PRO

a year ago

@Brody if I upgrade to a pro plan with the database and web app in the same region will it enhance my queries.. for the records I have checked my application completely.. and the issue is not from my end.


Anonymous
PRO

a year ago

Up until yesterday everything was working perfectly well until I changed my runtime to v2 after my deployment we constantly failing


callmefredcom
PROOP

a year ago

There's definitely a recurring correlation between the fact we had to switch to V2 and performance issues.
It must be at least acknowledged by Railway, as a minimum.


Anonymous
PRO

a year ago

I think railway must be proactive to say the least and provide a definite solution because am getting frustrated here.


brody
EMPLOYEE

a year ago

yes we are aware but due to the fact that this is not caused by any platform issues there's nothing we can do about this, sorry


callmefredcom
PROOP

a year ago

Ok, let's recap:
The issue has been experienced by many users due to a (forced) change in their runtime configuration, enacted by Railway (probably for some good reasons).
Everything was running smoothly for those users (incl. myself) before this forced switch.
Railway considers they have no responsibility in the degradation of the service which was triggered by this configuration change, which has just revealed the poor coding skills of those users.

Not very rational IMO.


callmefredcom
PROOP

a year ago

And I would add: the only "solution" seems to be to pay $15 more per month to at least make sure the web app and the DB are in the same zone.
Well, well, well…


callmefredcom
PROOP

a year ago

I mean, I love Railway, don't get me wrong.
But this doesn't sound quite right.


brody
EMPLOYEE

a year ago

we have only seen a handful of reports about slow downs, most of them solved by using the private network, given that 100% of hobby users are now on metal, so I would say it has not been experienced by many users


callmefredcom
PROOP

a year ago

there's always a difference between those who complain and those who don't because they can't articulate their complaints.
But for those who did, there's a causal relationship, it's undeniable.


callmefredcom
PROOP

a year ago

anyways, spending time writing those lines is better invested upgrading to Pro I presume.


callmefredcom
PROOP

a year ago

@Brody I'm pretty happy that I spent time optimizing my main queries.

Thanks for pushing me in the right direction.

My performance is now MUCH BETTER than it used to be before my switch to V2.
I have implemented connection pooling for mysql and joins on my complex queries.
Top result.

Still considering upgrading to Pro to have both services in the same zone.


brody
EMPLOYEE

a year ago

I could not be more happy to hear that, I'm really sorry if I came off as pushy, but this is truly some awesome news


callmefredcom
PROOP

a year ago

If anyone is developing Flask web apps and needs some assistance on the optimization front, I'm happy to share my takeaways. Cheers


brody
EMPLOYEE

a year ago

gave you some credits for your time!


brody
EMPLOYEE

a year ago

when metal supports volume you can move the db to the same zone to get that -10 ms back for the query time


callmefredcom
PROOP

a year ago

Thank you so much!


callmefredcom
PROOP

a year ago

I guess this will be announced in the weekly newsletter when available.


brody
EMPLOYEE

a year ago

yep 100%


richmeij
PRO

a year ago

For all the good reasons Railway is pushing this move, I am disappointed on how this was (or rather wasnt) communicated. Either some migration docs or common performance tips would be really helpful. Now it kinda came out of nowhere and the gist of the official replies is: its not us its you, and youre on your own.


richmeij
PRO

a year ago

As far as I can see, we are using the internal URLs to connect from the API to the PostgresDB, we have all indexes in place, but even a simple Select on a primary key or index takes about 800ms-900ms where it used to be much much faster before switching to the metal region. This 800ms-900ms is the time from the API to the DB, so it should be all internal. On a local machine this stuff is instant, so it really cant be that our code is that horrible.


brody
EMPLOYEE

a year ago

as fred as shown above he was able to significantly speed up his db queries by writing more efficient queries.

but 800-900ms makes me think you are still using the public network one way or another.


brody
EMPLOYEE

a year ago

!s


Loading...