php5-fpm vs Laravel high resource consumption, or something else?
I have an issue and I will describe it in details.
I have 10 servers. One of them is a database server with PostgreSQL. 8 of them have Nginx web service and they act as Backend servers. The last server is a load balancing server with Nginx. I am not sure if this is the right way to calculate the computing power of the system but in total those 10 servers have 15 CPUs and 60GB RAM.
So, all input requests are handled by the load balancer and forwarded to the back-end servers. The backend servers work with PHP Framework Laravel 4 which communicates with the database server.
It can't be as simple as that. And here is the issue. I wanted to see how the server performs if I send X requests/second. I started with 50 requests per second. The result is that I have average response time of about 800 ms which is ok, and also 0% error rate. All of this is ok. Then I started a new test with 100 requests per second, the results was slightly different, 2 seconds average response time and 0% error rate. I hit the bottom when I tried to send 200 requests per second. The result was 100% error rate...which means that all packages sent back from the server are with Http Code different from 200. During the test I tried to access the server from my web browser and I got "502 Bad Gateway" (Nginx).
I tried to find out what the reason might be. The load balancing server does not use even 5% of its capabilities. The database server works fine. So, the issue is somewhere in between...the back-end servers. So, I executed two requests:
- to an URL located on the server which corresponds to pure PHP:
<?php echo ''Hello World!';
- and the second one to an URL which corresponds to a resource served by Laravel.
The result was that I can execute as many requests to the pure PHP as I wish. I tried with 1000 requests per second (average response time 25 ms and 0% error rate) and even with 10 000 requests per second and it works fine (average response time 35 ms and 0.8% error rate). But when I tried to send requests to Laravel...it just crashes.
So, my question is simple. Do you think that the issue is only with Laravel or there is a connection with any misconfiguration with php5-fpm or Nginx? Is it possible to optimize somehow Laravel and php5-fpm?