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 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler