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

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.

  • 写回答

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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法