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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵