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 脱敏项目合作,ner需求合作
  • ¥30 Matlab打开默认名称带有/的光谱数据
  • ¥50 easyExcel模板 动态单元格合并列
  • ¥15 res.rows如何取值使用
  • ¥15 在odoo17开发环境中,怎么实现库存管理系统,或独立模块设计与AGV小车对接?开发方面应如何设计和开发?请详细解释MES或WMS在与AGV小车对接时需完成的设计和开发
  • ¥15 CSP算法实现EEG特征提取,哪一步错了?
  • ¥15 游戏盾如何溯源服务器真实ip?需要30个字。后面的字是凑数的
  • ¥15 vue3前端取消收藏的不会引用collectId
  • ¥15 delphi7 HMAC_SHA256方式加密
  • ¥15 关于#qt#的问题:我想实现qcustomplot完成坐标轴