Apache Tuning query

Operating system: CentOS 7
OS version: CentOS Linux 7.9.2009

Hi All,

I have set up a new server and installed WebMin and VirtualMin on it and got a site up and running now.

Its a server just for one site, and pretty decent spec. Plenty of RAM etc (16GB).

I have read about tuning up apache for better performance and I was just wondering if anyone has any tips for starters.

When I go to Webmin->Servers->Apache->Global Configuration->Processes and Limits, everything is set to Default.

What are the best settings to alter in here for better performance (is this even the right place).

This is a big ecommerce site, and I perform some big operations in the back end that can result in a 503 service unavailable error until it finishes - I’d like to somehow improve this if possible.

Thanks in advance,
Craig

You could use php fpm and increase the workers and "kind of " do the same for apache2:

That alone can increase the speed.

But the 503 can be related to something else too, so the easiest thing would be to check the log files.

Thanks very much for the reply.

I am using php-fpm already :). Where do you configure the workers for this?

These are the sort of errors I was seeing in the log file:

[Mon Dec 21 14:11:01.388501 2020] [proxy_fcgi:error] [pid 22963] (70007)The timeout specified has expired: [client 108.162.229.199:55166] AH01075: Error dispatching request to :
[Mon Dec 21 14:15:01.780318 2020] [proxy_fcgi:error] [pid 24353] (70007)The timeout specified has expired: [client 141.101.69.122:37322] AH01075: Error dispatching request to :
[Mon Dec 21 14:19:01.567043 2020] [proxy_fcgi:error] [pid 24595] (70007)The timeout specified has expired: [client 141.101.98.121:31180] AH01075: Error dispatching request to :
[Mon Dec 21 14:23:02.027690 2020] [proxy_fcgi:error] [pid 25569] (70007)The timeout specified has expired: [client 141.101.69.122:15654] AH01075: Error dispatching request to :

Not sure though (the correct path), but I think its “/usr/bin/php/version/fpm/”.

For that error, you should take a look into “ProxyPassMatch” and “RequestReadTimeout”. I looked into that in the past and just did a quick check and most of the issues were related to those two.

Will have a look. I’ve also just checked the php-fpm log file and seen this:

[21-Dec-2020 15:36:50] WARNING: [pool 16081968184171] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 8 children, there are 0 idle, and 11 total children
[21-Dec-2020 15:36:51] WARNING: [pool 16081968184171] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 12 total children
[21-Dec-2020 15:36:52] WARNING: [pool 16081968184171] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 13 total children
[21-Dec-2020 15:36:53] WARNING: [pool 16081968184171] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 14 total children
[21-Dec-2020 15:36:54] WARNING: [pool 16081968184171] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 15 total children
[21-Dec-2020 15:36:55] WARNING: [pool 16081968184171] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 16 total children
[21-Dec-2020 15:36:56] WARNING: [pool 16081968184171] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 17 total children
[21-Dec-2020 15:36:57] WARNING: [pool 16081968184171] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 18 total children
[21-Dec-2020 15:36:58] WARNING: [pool 16081968184171] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 19 total children
[21-Dec-2020 15:36:59] WARNING: [pool 16081968184171] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 20 total children
[21-Dec-2020 15:37:00] WARNING: [pool 16081968184171] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 21 total children
[21-Dec-2020 15:37:01] WARNING: [pool 16081968184171] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 32 children, there are 0 idle, and 22 total children

Currently the settings I have are default and this:

pm = dynamic
pm.max_children = 9999
pm.start_servers = 1
pm.min_spare_servers = 1
pm.max_spare_servers = 5

I wouldn’t recommend to set it to such a high limit. That’s a bad idea for multiple reasons.

Try something like that (sys specs would help me to recommend something precise):

pm = dynamic
pm.max_children = 120
pm.start_servers = 40
pm.min_spare_servers = 20
pm.max_spare_servers = 40
pm.max_requests = 180

You can slow down the system or cause other issues if you set something wrong in regard of system load/balance/usage. So always check the load from cpu/ram/etc when adjusting configs.

1 Like

9999 is pathological. Don’t do that.

Obviously, it’s not being applied, though, since it’s maxing at 32, which is probably the default. Did you restart the php-fpm service after making your config change (php-fpm, unlike all other php execution modes, is not restarted by an Apache restart)? And are you sure you’re changing in the right place?

1 Like

And, it’s also possible something is just really inefficient. Maybe your database settings or queries need tuning. It’s usually the application that causes performance problems, not the web servers (and php-fpm is mostly just another web server).

I haven’t made any changes at all yet. I was just listing the settings that I can see when I go to

VirtualServer -> Services -> PHP-FPM Configuration -> Edit Configuration

If it isn’t using those, where should I be looking for the ones that are being used?

Assuming there are no horribly-designed databases or insanely complex scripts sucking up resources, I find I get the best bang for the buck by simply enabling gzip compression and browser caching in .htaccess. I’m pretty sure mod_gzip and mod_expires are enabled by default.

Richard

Huh, I guess maybe we’re defaulting to 9999 for some nutty reason, but that doesn’t explain why you’re topping out at 32. I’ve never needed to tune FPM, so I don’t know, I’ll have to do some experimenting…

1 Like

Thanks for this. Just not sure where to set it as it would appear that my current settings may be being ignored? Seeing as I have max children set to 9999, and its topping at 32 as Joe said…

The spec of the system is:

CPU: Intel Xeon Processor (Skylake, IBRS), 8 cores
RAM: 16GB DDR4
200GB SSD

I’m not sure exactly what these settings do. Its not the number of people who can visit the site at once is it?

No it isn’t.
Its about how much “processes” are started and what can handle how much and how in general.
You can adjust the settings I told you and restart php after that.

I think you should take a look at the load of your system when that happens and also check the database server. Because from my experience with e-commerce shops, they are not very efficient and like to use a lot of power for “nothing serious”.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.