Score:0

Need help troubleshooting Apache2 MPM Worker on Ubuntu, system keeps crashing?

cn flag

I am on Ubuntu Server 22.04 using Apache2 2.4.56. I have PHP FPM 8.1 installed, and should be using MPM Worker enabled via module:

a2query -m
setenvif (enabled by maintainer script)
dir (enabled by maintainer script)
actions (enabled by unknown)
rewrite (enabled by unknown)
proxy_fcgi (enabled by site administrator)
autoindex (enabled by maintainer script)
authz_user (enabled by maintainer script)
slotmem_shm (enabled by unknown)
auth_basic (enabled by maintainer script)
authz_core (enabled by maintainer script)
authn_file (enabled by maintainer script)
proxy_balancer (enabled by unknown)
authz_groupfile (enabled by unknown)
access_compat (enabled by maintainer script)
proxy_html (enabled by unknown)
negotiation (enabled by maintainer script)
proxy_ajp (enabled by unknown)
cgi (enabled by unknown)
proxy_http (enabled by unknown)
authn_core (enabled by maintainer script)
xml2enc (enabled by unknown)
fcgid (enabled by maintainer script)
include (enabled by site administrator)
proxy_wstunnel (enabled by site administrator)
ssl (enabled by unknown)
env (enabled by maintainer script)
proxy (enabled by unknown)
http2 (enabled by site administrator)
filter (enabled by maintainer script)
reqtimeout (enabled by maintainer script)
proxy_connect (enabled by unknown)
socache_shmcb (enabled by unknown)
status (enabled by maintainer script)
mpm_worker (enabled by site administrator)
deflate (enabled by maintainer script)
authz_host (enabled by maintainer script)
headers (enabled by unknown)
mime (enabled by maintainer script)
alias (enabled by maintainer script)

Everything has been working fine, but I did some nextcloud app updates and I started getting this in the logs, then my system would become unreachable:

[Thu Mar 23 15:16:45.304069 2023] [core:notice] [pid 1188749:tid 139956863047552] AH00094: Command line: '/usr/sbin/apache2'
[Thu Mar 23 15:18:01.382967 2023] [mpm_worker:error] [pid 1188749:tid 139956863047552] AH00287: server is within MinSpareThreads of MaxRequestWorkers, consider raising the MaxRequestWorkers setting
[Thu Mar 23 15:18:22.408722 2023] [mpm_worker:error] [pid 1188749:tid 139956863047552] AH00286: server reached MaxRequestWorkers setting, consider raising the MaxRequestWorkers setting
[Thu Mar 23 15:20:32.327642 2023] [mpm_worker:notice] [pid 1188749:tid 139956863047552] AH00296: caught SIGWINCH, shutting down gracefully
[Thu Mar 23 15:20:35.688071 2023] [core:warn] [pid 1188749:tid 139956863047552] AH00045: child process 1188751 still did not exit, sending a SIGTERM

I manually modifed my /etc/apache2/apache2.conf to set ServerLimit and MaxRequestWorkers to 256 (which seems really high over the default of 16) but it isn't helping and it's still happening.

I'm kind of stuck diagnosing this? Is there a way to troubleshoot what is spawning so many workers? Or is there a way to prove that the setting isn't being loaded? (for example, I have removed it from an "ifmodule" block to make sure it isn't getting ignored). Any advice is helpful, most of my googling just says to "Increase MaxRequestWorkers and set ServerLimit to match" but that didn't help.

Score:1
ru flag

You don't specify all mpm parameters, but you must not set ServerLimit equals to MaxRequestWorkers in a threaded mpm like worker or event, because ServerLimit refers to child processes while MaxRequestWorkers refers to max Worker threads.

That is, if you have 5 servers and threads per child is 100 you can amount to a total of 500 request workers.

Consider this a sane default setup for average to high amount of traffic (depends on what the server does):

StartServers            1
ServerLimit             5
MinSpareThreads         100
MaxSpareThreads         300
ThreadsPerChild         100
ThreadLimit             100
MaxRequestWorkers       500
MaxConnectionsPerChild  100000000

PS: I would really start unloading unnecessary modules If I were you, the list you show sounds like an exaggerated list of default of modules you are not going to use. Also in 2.4 do not use 2.2 directives, mod_access_compat should not be used nowadays.

PS2: The errors you show are not apache crashing, more than gracefully shutting down IIRC.

surfrock66 avatar
cn flag
You're right, crash is the wrong term. I found a setting that worked as the answer; but that's a good note, this is an old install and I should audit stuff like that, I haven't in a long time.
Score:0
cn flag

I read more and saw that mpm_event might be better for my use case over mpm_worker. I had tried disabling nextcloud (which I thought was the issue) but it persisted, so I converted to mpm_event with the following settings based on the recommendation here https://stackoverflow.com/a/64937518/1739616 :

<IfModule mpm_event_module>
        StartServers            4
        MinSpareThreads         25
        MaxSpareThreads         75
        ThreadLimit             64
        ThreadsPerChild         25
        MaxRequestWorkers       800
        ServerLimit             32
        MaxConnectionsPerChild  10000
</IfModule>

This worked; the calculation was "ServerLimit x ThreadsPerChild = MaxRequestWorkers"

I sit in a Tesla and translated this thread with Ai:

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.