Answer the question
In order to leave comments, you need to log in
How to increase the number of requests per second Laravel (PHP)?
Good afternoon!
There is a Laravel application that implements all endpoints, a PostgresSQL database and a server with 32 cores, 32 GB of RAM. Indexing is configured in the database, fpm is configured, but the throughput of one request with interaction with the database is 32 requests per second, while indicators such as CPU & RAM are loaded by 10-15%
How to increase the number of requests per second, processing all requests evenly distributed among the cores?
Answer the question
In order to leave comments, you need to log in
1) disable debugging in production, it slows down a lot, checked
2) enable OpCacher, opcode caching increases performance
3) do profiling, identify code bottlenecks. As a rule, these are requests ... There is a lot of information on the Internet about optimization and profiling of requests. Most people in frameworks use ORMs. It must be remembered that the ORM usually makes NOT optimal queries.
4) It may be worth some data to be cached or calculated at the start of the framework.
5) if the problem is in calculations, then move part of the code into a separate microservice and write it in something faster, for example golang. This is taken out to a separate url (router) and resolved by nginx location. This is already extreme...
6) There may be problems in the architecture of the application itself, it may be worth putting something into separate parts (workers) and pulling up AJAX or WebSocket after the page has loaded: upon request, we launch a subtask that, when ready, will notify the page and it will already pull out the remaining data.
just as a doctor cannot make a correct diagnosis without examining the patient, so here, without turning the knobs, without studying the code and architecture, it is impossible to advise anything correctly
What about disk queues? To the network? In general, you need to find long queries: https://pgcookbook.ru/article/slow_queries_search.html and analyze their execution plan using something like https://explain.tensor.ru/
Check how long it takes to generate one response
If there are problems, add intermediate measurements and define heavy calculations to optimize
the overall picture, as well as adding measurements to the timeline, you can use the same Debugbar or clockwork,
you can also see the time of requests to the database there
If that's all ok
Check fpm pool options
pm.max_children
pm.start_servers
pm.min_spare_servers
pm.max_spare_servers
It speeds up OPcache very well, I recommend enabling and configuring it. According to the database, you need to look at queries, it may be worth optimizing them, using raw queries without using Eloquent. Cache configuration, routes (php artisan optimize)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question