I'm serving Wordpress pages via nginx/PHP5-FPM using APC caching (through the W3 Total Cache plugin). Nginx communicates with PHP-FPM via TCP sockets on port 9000. I've adjusted the number of max connections via sysctl to be 1024. I've set both max_execution_time (in php.ini) and request_terminate_timeout (in FPM conf file) to 30 seconds.
Every now and then (say every 8-10 hours, and not linearly) the number of open TCP connections on port 9000 grows to near 1000 (in CLOSE_WAIT status mostly, some FIN_WAIT, FIN_WAIT_2), surpassing 1000 sometimes, and my web server starts returning 504 errors. Once I kill all TCP connections on that port and restart FPM, it starts working fine again.
I enabled the slow log to see what's going on, and if I'm reading it right, it's hanging on apc_store() calls.
Is this an APC misconfiguration or do I need to tweak with FPM settings? And is there a way to force those TCP connections to terminate even if the script doesn't send the final termination signal?
Example trace from FPM slow log:
[22-Jan-2015 09:42:49] [pool www] pid 20327
script_filename = /var/www/index.php
[0x00007fdc527ec908] apc_store() /var/www/wp-content/plugins/w3-total-cache/lib/W3/Cache/Apc.php:55
[0x00007fdc527ec768] set() /var/www/wp-content/plugins/w3-total-cache/lib/W3/ObjectCache.php:254
[0x00007fdc527ec5e0] set() /var/www/wp-content/plugins/w3-total-cache/lib/W3/ObjectCache.php:300
[0x00007fdc527ec488] add() /var/www/wp-content/plugins/w3-total-cache/lib/W3/ObjectCacheBridge.php:73
[0x00007fdc527ec330] add() /var/www/wp-content/object-cache.php:94
[0x00007fdc527ec200] wp_cache_add() /var/www/wp-includes/option.php:176
[0x00007fdc527ec078] wp_load_alloptions() /var/www/wp-includes/functions.php:1272
[0x00007fdc527ebf40] is_blog_installed() /var/www/wp-includes/load.php:474
[0x00007fdc527ebdb0] wp_not_installed() /var/www/wp-settings.php:109
[0x00007fdc527ebc88] +++ dump failed