Laravel app - Slow Database Queries

dwhicker
FREE

3 months ago

Hi all
I am new and testing the free tier.
I wanted to test a very simple Laravel app with filament, nothing fancy.
Production queries are incredidlbe slow. Page loads are 1-2 seconds. Local development its fine.
I have used DBHOST etc to connect to the datbaes. I also tried DBURL using the internal url to the db. It make no real difference.
Both web server and db server are on the same region.
Any ideas?

0 Replies

dwhicker
FREE

3 months ago

I use database sessions and the first query to get the session is about 500ms


dwhicker
FREE

3 months ago

It’s 1ms on local dev


dwhicker
FREE

3 months ago

2d107d26-eef1-44e4-9d3b-ef006de2f025


smoothcubegit
HOBBY

3 months ago

Is this a connection thing? I think it might be your connection to the internet? I had the sme thing


dwhicker
FREE

3 months ago

Nope I have 1gb internet and no issues when deploying on Laravel forge with a cheap hetzner droplet


smoothcubegit
HOBBY

3 months ago

Might be the Database your using and the processing that it requires?


dwhicker
FREE

3 months ago

I just spun up a MySQL db on railway


dwhicker
FREE

3 months ago

400ms for a single from lookup. Vs 1ms on local


dwhicker
FREE

3 months ago

Not sure what else I can do setup wise on railway to aid


smoothcubegit
HOBBY

3 months ago

I got told that Postgres is the most lightweight on railway


smoothcubegit
HOBBY

3 months ago

Whats the reason why this delay matters?


dwhicker
FREE

3 months ago

Local vs production.

I don’t have my benchmark from forge/hetzner but even that was much faster compared to railway setup thus far

1368534020350279700
1368534020685693000


3 months ago

when you say production, does that mean your application running on Railway?


dwhicker
FREE

3 months ago

Yes sorry I mean the issue with speeds is solely when using railway


dwhicker
FREE

3 months ago

Local is very fast ( not expecting local speeds)

Laravel forge using the cheapest hetzner droplet is very fast.

Railways is very slow in comparison.

I don’t think I have configured anything incorrectly but I’m open to suggestions


dwhicker
FREE

3 months ago

But for the same query request on local it’s 1ms vs 300-400ms on railway. Seems quite a steep increase


dwhicker
FREE

3 months ago

Pictures above for comparison


3 months ago

are you opening a new database connection for every db call?


dwhicker
FREE

3 months ago

Nope. Well it’s just standard php Laravel app.


3 months ago

is both your application and database on metal?


dwhicker
FREE

3 months ago

Yes both on metal and both same region. Spun up yesterday. Used railpack as per one of your YouTube videos on setting up a Laravel app


dwhicker
FREE

3 months ago

It seems like the first query of each request is always the slowest by far


3 months ago

can you provide some full traces?


dwhicker
FREE

3 months ago

Not sure if this is what you are after but here goes. As you can see the first db call is by far the longest for what is a single record return. I turned off datbase sessions which was orignally top of the list, now that was removed this is the first in the list and now much higher.


dwhicker
FREE

3 months ago

1368676979426988300


3 months ago

yeah it looks like you are establishing a connection for every route, you would want to have a global connection pool


Laravel app - Slow Database Queries - Railway Help Station