Score:0

Apache with PHP FPM and requests spikes, how to set optimal configuration?

vu flag

I was lucky enough that my website went viral, and the server of course wasn't ready for it.

Unfortunately my setup is quite bad, a single server with Apache, PHP (Laravel), Mongodb and redis.

The backend (laravel) mostly serve a REST API. I currently have 1000+ concurrent users trying to use the website, and everything loads really slowly. MongoDB seems to be working fine, since I can access it through terminal and queries are resolved immediately. What worries me is the Apache/PHP FPM configuration.

My server: 8 core, 16GB RAM

I tried to play with PHP FPM configurations but didn't improve by much. For now I have it on static with 300 max_children.

On Apache I'm using MPM event with this config:

<IfModule mpm_event_module>
ServerLimit 40
    StartServers             2
    MinSpareThreads      50
    MaxSpareThreads      100
    ThreadLimit          64
    ThreadsPerChild      50
    MaxRequestWorkers     1000
    MaxConnectionsPerChild   0
</IfModule>

Using top I have this, which seems fine to me: enter image description here

Anyone can point me in the right direction?

np flag
Do you use OPcache for PHP? You can also consider migrating to nginx or OpenLiteSpeed. Opinion based, but still they usually scale much better for high load.
vu flag
I don't use OPCache, would it beneficial even if PHP just serves an API? I have mongo as DB and a redis caching layer. As for nginx and OPS, I was looking for a short term solution rather than migrate everything. But thanks for the suggestion
np flag
Laravel is pretty advanced framework and OPCache can really improve it's execution times. Your CPU usage are pretty close to 100% and most of it are used by apache processes, but still there are a lot of php-fpm workers there. It's pretty easy to install & configure it so I guess it's worth to try. I don't see any i/o wait so the bottleneck should be in the CPU processing.
vu flag
Will try it then! Just to test out, I tried to upgrade the server at 32 core and 192GB of ram, just to be sure. By changing a bit the configuration i reached 1500 concurrent users and then the website started to slow down, with just 30GB used out of 192GB, weird
np flag
To be honest, I don't have any experience with newer Apache MPM workers, like event one. So won't be guessing here. But with older versions & other works it was always slow for any significant load for me. I've always picked nginx if I'd expect any significant loads. After I've tried OLS, I usually try to stick with it. It has it's own issue, but performance wise it's really a great software. And I like it can parse apache style .htaccess rewrite rules (only for mod_rewrite unfortunately, but it's usually enough).
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.