Vishal Vyas
Vishal Vyas

Reputation: 2581

PHP Symfony Optimise Controller Execution Time Line

I am using Symfony version 3.1.9 for REST APIs that communicates with MySQL database.

Average time taken for most of the POST APIs (Controller functions) is ~3-4 second! Yes its ~3-4 seconds :(

For one of the API, here are the details from Symfony Profiler:

1st execution of API Performance metrics

13307 ms Total execution time
485 ms Symfony initialization
34.25 MB Peak memory usage

2nd subsequent execution of API Performance metrics

4862 ms Total execution time
266 ms Symfony initialization
34.00 MB Peak memory usage

Here is the screen shot of the 2nd execution time and it seems like controller is very busy in some heavy processing BUT all I am trying to do in controller function is to access information from MySQl database and I have confirmed that MySql queries via Doctrine are not taking more than 1ms.

What I have tried?

Please help. Let me know in comments if any other details are required.

Upvotes: 1

Views: 3288

Answers (1)

Alister Bulman
Alister Bulman

Reputation: 35169

You can use the stopwatch component to get a more accurate time of how long things are taking within a controller. Trying to accurately profile a Symfony app that is running in a 'dev' environment isn't worthwhile though - so much of the potential speed-ups that are used in production are removed, and development tools like the profiler take a great deal of time to produce - as well as building the entire container.

You can reduce the profiler threshold to 0 and see all the internal events that are being recorded, and then start using tools like Blackfire from there to optimise slow calls and database queries.

Also looking at the Doctrine tab in the profiler will show what, and how many queries are being made. This can also quickly show where issues may be arising - mostly from many more calls being made than you would initially think.

Upvotes: 1

Related Questions