Score:2

Apache creates ~3x as many threads as MaxRequestWorkers

es flag

I'm hosting a non-profit community wiki for the upcoming video game Baldur's Gate 3. Since it looks like the game is likely to have millions of players, we started worrying about server capacity.

I'm on Apache 2.4.57 (latest stable), using the following mpm_event.conf right now, subject to further change:

ServerLimit             8
StartServers            2

ThreadLimit             32
ThreadsPerChild         32

MaxRequestWorkers       256

MinSpareThreads         32
MaxSpareThreads         128

MaxConnectionsPerChild  0

So, Apache should at any point have a maximum of 256 worker threads. Together with 8 main threads per MPM process and one root main process, that gives us a grant total of 265. (Maybe a couple more for other reasons, but the maximum should be in that ballpark anyway.)

Yet when I stimulate maximum load (ab -n 1500 -c 500 <url>) and see the status page served by mod_status indicate a full 256 workers, the command pgrep -wc apache returns a whopping 632.

I've also used the commands pgrep -wal apache | wc -l and ps -eL | grep -c apache with pretty much equivalent results, so I think my apache thread counting method should be accurate?

What could be the explanation of this?

The maximum number of threads on my system is limited by my "VPS" (not a real VPS, but rather a cheap container) to a total of 1100, so it's very important for me to know how many threads Apache will really be creating with a given configuration.

Could this have something to do with PHP FPM? My FPM's pool.d/www.conf currently contains the following (has not yet been tweaked to match the mpm_event settings):

pm = dynamic
pm.max_children = 5
pm.start_servers = 2
pm.min_spare_servers = 1
pm.max_spare_servers = 3

Even if each worker had an additional thread related to PHP, that would give us 512 threads, plus the few others mentioned earlier (MPM main threads + root process thread) for a total of 521, thus still leaving 112 threads unaccounted for.

The PHP version is 8.1.2-1ubuntu2.13.

jp flag
Check this bug https://bz.apache.org/bugzilla/show_bug.cgi?id=65626
TaylanKammer avatar
es flag
@AlexD Thanks but I don't think that's it, since I'm on the latest Apache version that supposedly fixed it. Threads are getting killed eventually for me as it seems, it's just that each worker seems to be made up of 2 threads plus there's some additional ones... Edited the question to note Apache and PHP versions.
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.