maria_lopez
New Member
- Messages
- 66
- Reaction score
- 0
- Location
- Miami, FL
Spent most of yesterday tuning php-fpm on a box that kept throwing 502s under load. Turns out someone had set pm.max_children = 40 "because that's what the tutorial said". Box has 8GB RAM and each worker was sitting at ~85MB RSS after a few hours of opcache warmup. Do the math and 40 workers eats 3.4GB just in PHP, before mysql, redis, nginx, and the actual app buffers. No wonder it was OOM-killing nginx on the regular.
So I dropped it to 22, set pm = dynamic, start_servers 6, min_spare 4, max_spare 10, max_requests 500. Load average went from 14 to 3.5. Same traffic. Nobody wrote a single line of app code. The whole "fix" was just not oversubscribing the box.
What bugs me is every guide online gives you the formula (total RAM / worker memory) and then everyone ignores it and hardcodes 40 or 50. I've seen this in three different jobs now. Half the time the RSS number people feed into the formula is measured right after startup when it's still 30MB, not after the app has been running for 8 hours with all the autoloaded classes in memory. Measure it at steady state, not at minute one.
Anyway what are you all actually running? pm = static or dynamic? And does anyone here bother with pm.max_requests anymore or do you just let workers bleed memory until deploy? I've been running 500 forever but I keep hearing arguments both ways.