Laravel app - Slow Database Queries
dwhicker
FREEOP

10 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?

26 Replies

dwhicker
FREEOP

10 months ago

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


dwhicker
FREEOP

10 months ago

It’s 1ms on local dev


dwhicker
FREEOP

10 months ago

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


smoothcubegit
HOBBY

10 months ago

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


dwhicker
FREEOP

10 months ago

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


smoothcubegit
HOBBY

10 months ago

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


dwhicker
FREEOP

10 months ago

I just spun up a MySQL db on railway


dwhicker
FREEOP

10 months ago

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


dwhicker
FREEOP

10 months ago

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


smoothcubegit
HOBBY

10 months ago

I got told that Postgres is the most lightweight on railway


smoothcubegit
HOBBY

10 months ago

Whats the reason why this delay matters?


dwhicker
FREEOP

10 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


10 months ago

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


dwhicker
FREEOP

10 months ago

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


dwhicker
FREEOP

10 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
FREEOP

10 months ago

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


dwhicker
FREEOP

10 months ago

Pictures above for comparison


10 months ago

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


dwhicker
FREEOP

10 months ago

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


10 months ago

is both your application and database on metal?


dwhicker
FREEOP

10 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
FREEOP

10 months ago

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


10 months ago

can you provide some full traces?


dwhicker
FREEOP

10 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
FREEOP

10 months ago

1368676979426988300


10 months ago

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


Loading...