简体   繁体   English

nginx php-fpm配置达到子级限制

[英]nginx php-fpm configuration hitting children limit

I'm having this problem with nginx + php7.0-fpm. 我在nginx + php7.0-fpm中遇到了这个问题。

Testing is done on a pure php server with no other services installed. 测试是在没有安装其他服务的纯php服务器上完成的。

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. 我正在使用AWS t2.medium instance -2vCPU和4GB RAM。

My php7.0-fpm/www.conf set up looks like 我的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

I have a laravel application that I'm using to test which simply replies {"m":"OK"} to requests. 我有一个用于测试的laravel应用程序,该应用程序仅对请求回复{"m":"OK"}

I tested that using apache2-utils 我使用apache2-utils进行了测试

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

Response from ab test -> https://ghostbin.com/paste/528tw 来自ab测试的回复-> https://ghostbin.com/paste/528tw

And I watch the CPU usage using htop . 我使用htop观察CPU使用率。

The two CPU usages hit 100% quickly during ab test. ab测试期间,两个CPU的使用率迅速达到100%。 However, Memory usage is only 400MB . 但是,内存使用仅为400MB

Why is it using CPU too much? 为什么过多使用CPU? What do I do to make getting WARNING from php-fpm? 我该怎么做才能从php-fpm获得警告?

What am I doing wrong? 我究竟做错了什么? Please guide me through. 请引导我。

Thanks. 谢谢。

You may not only take in account the memory usage of PHP but also the concurrent CPU usage. 您不仅可以考虑PHP的内存使用情况,还可以考虑并发CPU的使用情况。

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. 如果子服务器过多,只会使情况变得越来越糟,并且PHP无法处理更多请求,它将完全阻塞所有内容。

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. 您的服务器仅有2个vCPU的内存太多,反之,它应该有更多的CPU以适应内存量。

This is more appropriate for 2 virtual cpu cores: 这对于2个虚拟CPU内核更合适:

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. 同样,当您使用Apache的Benchmark工具执行50个并发请求时,只有2个vCPU服务器非常慢是完全正常的。 Benchmarks should be ran from a different computer. 基准测试应从另一台计算机运行。

Keep in mind that the basic OS and your webserver (nginx) also needs some CPU usage. 请记住,基本操作系统和Web服务器(nginx)也需要一定的CPU使用率。

Your AWS server has about the same power as a RaspberryPi with a little more memory. 您的AWS服务器具有与RaspberryPi差不多的功能,但具有更多的内存。

Useful comment from Mjh : 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. 如果每秒达到100个请求,这还不错,如果达到某个程度,那将是一个很大的问题。 Dropping SSL in favor for requests per seconds might not be the best thing to do at this point. 此时,放弃SSL以支持每秒请求可能不是最好的选择。 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. 当然,我对您的网站及其用途没有任何了解,或者是否需要SSL,但是拥有SSL确实会影响您的Google排名。 It's always min-maxing, and in case of SSL, if I were you, I'd keep it. 总是最小到最大,如果使用SSL,如果我是你,我会保留它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM