php-fpm: What is the bottleneck for accepting connections faster?

A.B. Carroll asked:

On a php5-fpm status page, what is the bottleneck that is preventing my server from accept()‘ing new sockets fast enough?

pool:                 www
process manager:      static
start time:           20/Jan/2015:16:37:18 +0000
start since:          176705
accepted conn:        903749
listen queue:         0
max listen queue:     129
listen queue len:     128
idle processes:       59
active processes:     69
total processes:      128
max active processes: 128
max children reached: 0

As you can see, I’ve reached my listen queue, and this happens quite frequently. I understand the basic logic behind the listen queue, and it is laid out in some detail here: php-fpm status page: what are the "queue" items in this report?

I realize that I should increase the queue length, and I will make it so. However, my question is why is my listen queue filling up, and what is the bottleneck to prevent it from filling up in the first place? I assume if there is a large listen backlog, then there has to be something that isn’t “keeping up”? Is this a CPU bottleneck / load issue that it cannot accept() fast enough?

My answer:

You don’t appear to have enough PHP worker processes for the traffic you’re receiving.

The obvious solutions are:

  1. Allow for more total processes. But you need to have the CPU and RAM to handle this, and you didn’t say anything about what resources you have available or how much was consumed.
  2. Make your application run faster. Better programming, appropriate use of page caching and opcode caching, etc.

View the full question and any other answers on Server Fault.

Creative Commons License
This work is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License.