pasek's avatar
Level 1

Slow Response with Lumen (High TTFB)

Hello :)

I've been looking for days for a solution, but I'm getting nowhere. Maybe somebody can help me or give me tips where to find the error.

I have a lumen backend with which I get the data from the database and send it to my angular frontend. My problem is that the response time is already very large, although I sometimes only fetch a few data. Following example:

$query = \DB::table('ip_netztyp')
 ->orderBy('netztyp')
 ->get();

return $query;

This is my db query. It returns 16 values from the table like this:

{ "id": 10, "netztyp": "DMZ", "active": 1 }, { "id": 13, "netztyp": "LAN", "active": 1 }, ...

But the response times in Chrome Dev Tab are between 200ms - 300ms. My Postman test says, that 90 % of the time is "transfer start".. The DB request are about 0.0013 sec.

So I don't think the db is to slow but why is the lumen response so slow? I don't think that's normal.

When I runnig my setup in a docker container the TTFB is > 1,5 sec...

How can I troubleshoot the issue?

0 likes
10 replies
bugsysha's avatar

Solve other issues like large response payload, number of queries, number of hydrated models and TTFB will come down.

pasek's avatar
Level 1

My environment isn't big. So i create a new lumen project and opend the start page which shows simple "Lumen (7.2.0) (Laravel Components ^7.0)" In Chrome it says

"Waiting (TTFB)" 106 ms

"Content Download" 6 ms

An another machine with docker container with same new project:

"Waiting (TTFB)" 1670 ms

"Content Download" 9 ms

What goes wrong with that? Its a clean new project?

I can't believe this is normal. I've tested two different machines.

shez1983's avatar

is this local or production?

also try to add caching.. change your query/add indexes..

comparing docker with non docker environment wont help...

personally i dont think 200-300ms is that big of a deal thats like < 0.5 sec. you can easily add caching/opcache may help as well..

pasek's avatar
Level 1

is all development.

the test with docker and clean lumen project on the local machine resulted in a TTFB of 600ms-700ms..

now try to run with opcache from this article because the production is with docker.

https://laravel-news.com/php-opcache-docker

I'm using Docker Desktop for Windows.

bugsysha's avatar

I'm not sure about Docker for Windows, but Docker for Mac is very slow. And it depends on how those containers communicate.

pasek's avatar
Level 1

the first tests with Opcache activated look quite good. I will test it more closely at the weekend and get back to you. Thanks a lot for the tips so far.

bugsysha's avatar

OPcache is solving the issue, not the root cause of the problem.

shez1983's avatar

have u got indexes/foreign keys in your db? -

pasek's avatar
Level 1

yes, OPcache is resolving the issue and not the root cause.

I'm now facing the issue, that OPcache and IonCube not work good together...

With OPcache i have about 40ms. With OPcache + IonCube again at 800ms... I now know that this isn't a good combination. So how can i also fasten up a project without cache? It seems that my code and database isn't slow because with cache it is really fast.

Any other suggestions?

Please or to participate in this conversation.