Score:0

How to determine the best setting for php-fpm pm.max_requests?

pg flag

I'm not much of a system / network administrator. I'm searching for a way to properly determine the settings of my php-fpm.

So far I found this article explaining the details to calculate these settings based on the server specs (https://chrismoore.ca/2018/10/finding-the-correct-pm-max-children-settings-for-php-fpm/): pm.max_children pm.start_servers pm.min_spare_servers pm.max_spare_servers

But there's a setting here pm.max_requests, so I'm wondering what value I should put here? How do I determine what value I should put there? Should I leave it at default 0?

Orphans avatar
cn flag
What are you trying to achieve here? To me, it just looks like you want to populate settings just because you want to do it - not because you actually have found a need to. 99.9999% of cases - you can just let it be the default value.
aceraven777 avatar
pg flag
@Orphans , I think you misunderstood my motive here, you're assuming. I just want to know what are the optimal settings to put. In my question details I mention that I'm not much of a system administrator. I don't any experience doing this things, that's why I'm asking it here. Also in my question I put there "Should I leave it at default 0?".
Marcel avatar
gb flag
Hi @aceraven777, I'd suggest you to look for my answers [regarding](https://serverfault.com/questions/787919/optimal-value-for-nginx-worker-connections/788703#788703) [capacity](https://serverfault.com/questions/503657/apache-requests-stuck-in-reading-state/505420#505420) in other serverfault messages.
diya avatar
la flag
Performance tuning and tuning in general is as much an art as a science. You need data (obtained by careful monitoring), actual load (by either synthetic running load generators & stress tests and/or on your production environment) to identify bottle necks , before selecting and adjusting certain specific potentially beneficial settings and then measure the effect of those changes. Generally most settings don't have fixed formula, no `sigma(#cores) / gamma(#RAM memory) ^ psi(#concurrent users) * rho(moon phase)`, that result in an *"optimal"* value. Much depends on your own use-cases.
diya avatar
la flag
https://www.php.net/manual/en/install.fpm.configuration.php explains what the setting does : *"`pm.max_requests int` The number of requests each child process should execute before respawning. This can be useful to work around memory leaks ... Default value: `0`."* - based on that info: As a sysadmin I would adjust the default when monitoring shows that over time each php_fpm process starts consuming more and more memory (indicating a memory leak somewhere) and otherwise there is no immediate need to adjust the default value.
aceraven777 avatar
pg flag
Thanks @diya , the info you gave me is quite helpful. I'll take note of this. Based on my tests seems that I don't have to put a default value to `pm.max_requests`. But just to be safe I may have to put a high value here (like 5000) to clear some memory leaks.
Score:1
us flag

The only possible answer here is that there is no exact answer to give.

It really depends. Performance settings are solely dependent on each use-case, specs, project structure, etc.


You should only set a value here if you have a reason to.

If you don't care how many requests each process can get before restarting, you should just leave it at the default setting.

The same can be said for most settings in all sorts of applications, not just PHP-FPM.


From the docs:

pm.max_requests

The number of requests each child process should execute before respawning. 
This can be useful to work around memory leaks in 3rd party libraries. 
For endless request processing specify '0'. Equivalent to PHP_FCGI_MAX_REQUESTS. Default value: 0.

So, ask yourself: Are you having an issue with memory leaks, hung connections, etc? If so, maybe this functionality would be useful to you. If not, maybe just leave it alone.

I'll summarize with an analogy: Just because you have a workshop full of tools, it does not mean you need every tool for every job. This setting only needs to be configured if there is a problem to solve.

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.