今日已更新 344 条资讯 | 累计 37249 条内容
关于我们

Understanding PHP-FPM's process manager (by actually watching it)

kevariable 2026年08月20日 17:05 8 次阅读 来源:Dev.to

I thought I understood pm = dynamic until I sat down and watched it work in real time. It turns out the whole process manager is one tiny loop, and once you see the loop, every number in fpm-status suddenly makes sense. This is what I learned, with real outputs from a real server. The config pm = dynamic pm.max_children = 300 ; hard ceiling on total workers pm.start_servers = 5 ; workers created at boot pm.min_spare_servers = 5 ; never fewer than 5 idle pm.max_spare_servers = 50 ; never more than 50 idle pm.max_requests = 1000 ; recycle each worker after 1000 requests The whole algorithm is one loop FPM's master process runs one check, roughly every second: How many workers are idle? Fewer than min_spare_servers ? Fork one. More than max_spare_servers ? Kill one. Otherwise, do nothing. That is it. Everything below falls out of this one rule. The mystery of the 6th worker I booted FPM with start_servers = 5 and immediately saw 6 workers. Where did the extra one come from? t=0 boot 5 workers, all idle check: 5 idle. fine. t=1 a request comes in 1 busy + 4 idle = 5 total check: 4 idle < 5 min -> FORK ONE t=2 1 busy + 5 idle = 6 total check: fine. t=3 request done 0 busy + 6 idle = 6 total check: 6 > 50 max? no -> do nothing And there it stays: 6. The part everyone misses is t=3. FPM never shrinks back to start_servers . The kill rule only fires above max_spare_servers . Between the two bounds, the pool simply stays wherever demand pushed it. It ratchets up easily and trims lazily. start_servers only matters for the first second of the pool's life. Watching it happen Two seconds after a restart: start since : 2 idle processes : 4 active processes : 1 total processes : 5 The 1 active worker is my own curl. The status request is itself served by a worker, so checking the counter increments the counter. And 4 idle is already below min_spare_servers = 5 , which means the fork is about to happen. Thirty seconds later: start since : 34 accepted conn : 99 idle processes : 5 ac

本文内容来源于互联网,版权归原作者所有
查看原文