dongtuji0992
2017-01-10 15:01
浏览 111
已采纳

nginx php-fpm配置命中儿童限制

I'm having this problem with nginx + php7.0-fpm.

Testing is done on a pure php server with no other services installed.

I'm getting the following warning.

WARNING: [pool www] seems busy (you may need to increase pm.start_servers, or pm.min/max_spare_servers), spawning 16 children, there are 0 idle, and 35 total children

And it slows the server down greatly.

I'm using AWS t2.medium instance - 2vCPU and 4GB RAM.

My php7.0-fpm/www.conf set up looks like

pm = dynamic
pm.max_children = 50
pm.start_servers = 20
pm.min_spare_servers = 10
pm.max_spare_servers = 20
pm.max_requests = 500

I have a laravel application that I'm using to test which simply replies {"m":"OK"} to requests.

I tested that using apache2-utils

ab -n 1000 -c 50 https://mytestserver.com/

Response from ab test -> https://ghostbin.com/paste/528tw

And I watch the CPU usage using htop.

The two CPU usages hit 100% quickly during ab test. However, Memory usage is only 400MB.

Why is it using CPU too much? What do I do to make getting WARNING from php-fpm?

What am I doing wrong? Please guide me through.

Thanks.

图片转代码服务由CSDN问答提供 功能建议

我在使用nginx + php7.0-fpm时出现此问题。

测试是在没有安装其他服务的纯PHP服务器上完成的。

我收到以下警告。

 警告:[pool www]似乎很忙(你可能需要增加pm.start_servers,或pm.min / max_spare_servers),产生16个孩子,有0个空闲,35个孩子
 <  / code>  
 
 

它大大减慢了服务器速度。

我正在使用 AWS t2.medium实例 - 2vCPU和4GB RAM。

我的 php7.0-fpm / www.conf 设置看起来像

  pm = dynamic 
pm.max_children = 50 
pm.start_servers = 20 
pm.min_spare_servers = 10 
pm.max_spare_servers = 20 
pm.max_requests = 500 
   
 
 

我有一个laravel应用程序,我正在测试它只是回复 {“m”:“OK”} 到请求。

我测试了 apache2-utils

  ab -n 1000 -c 50 https://mytestserver.com/
   \  n 
 

来自 ab 测试的响应 - &gt; https://ghostbin.com/paste/528tw

我使用 htop 观察CPU使用情况。

ab 测试期间,两个CPU使用率快速达到100%。 但是,内存使用仅为 400MB

为什么它使用CPU太多了? 如何从php-fpm获取警告?

我做错了什么? 请指导我。

谢谢。

  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douwei7501 2017-01-10 15:27
    已采纳

    You may not only take in account the memory usage of PHP but also the concurrent CPU usage.

    If you have too many child servers, it will only make things worse and slower and PHP can't handle any more of the requests, it can totally block everything.

    Your server has a little too much memory for only 2 vCPUs, or the other way, it should have more CPU to fit to the amount of memory.

    This is more appropriate for 2 virtual cpu cores:

    pm = dynamic
    pm.max_children = 4
    pm.start_servers = 2
    pm.min_spare_servers = 1
    pm.max_spare_servers = 2
    pm.max_requests = 500
    

    Also when you do 50 concurrent requests with Apache's Benchmark tool, it is totally normal for only 2 vCPU server to be very slow. Benchmarks should be ran from a different computer.

    Keep in mind that the basic OS and your webserver (nginx) also needs some CPU usage.

    Your AWS server has about the same power as a RaspberryPi with a little more memory.

    Useful comment from Mjh:

    100 requests a second isn't bad, if you get to a point where you have that much - that's a great problem to have. Dropping SSL in favor for requests per seconds might not be the best thing to do at this point. Of course, I don't know anything about your site and what you use it for, or whether SSL is needed or not, but having SSL does have an impact on your google ranking. It's always min-maxing, and in case of SSL, if I were you, I'd keep it.

    已采纳该答案
    打赏 评论

相关推荐 更多相似问题