Laravel app - Slow Database Queries
dwhicker
FREEOP

a year 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 DB_HOST etc to connect to the datbaes. I also tried DB_URL 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

a year ago

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


dwhicker
FREEOP

a year ago

It’s 1ms on local dev


dwhicker
FREEOP

a year ago

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


smoothcubegit
HOBBY

a year ago

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


dwhicker
FREEOP

a year ago

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


smoothcubegit
HOBBY

a year ago

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


dwhicker
FREEOP

a year ago

I just spun up a MySQL db on railway


dwhicker
FREEOP

a year ago

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


dwhicker
FREEOP

a year ago

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


smoothcubegit
HOBBY

a year ago

I got told that Postgres is the most lightweight on railway


smoothcubegit
HOBBY

a year ago

Whats the reason why this delay matters?


dwhicker
FREEOP

a year 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

1368534020350279741

1368534020685692978


a year ago

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


dwhicker
FREEOP

a year ago

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


dwhicker
FREEOP

a year 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

a year ago

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


dwhicker
FREEOP

a year ago

Pictures above for comparison


a year ago

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


dwhicker
FREEOP

a year ago

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


a year ago

is both your application and database on metal?


dwhicker
FREEOP

a year 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

a year ago

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


a year ago

can you provide some full traces?


dwhicker
FREEOP

a year 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

a year ago

1368676979426988235


a year ago

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


Welcome!

Sign in to your Railway account to join the conversation.

Loading...