Reputation: 2581
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?
In case of all the GET request where applicable, I am using Cache-Control headers as below:
Cache-Control: must-revalidate=true
Cache-Control: max-age=180
This is not helping much as the Ubuntu server machine (using Apache) restarts itself because of load and execution time and In case of POST APIs I am still helpless.
I have also tried enabling OPcache on Apache server but not sure that is helping as I am very naive in optimising application server and server configuration.
Please help. Let me know in comments if any other details are required.
Upvotes: 1
Views: 3288
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