I have a very weird problem. There is a test.php file on the server that has approximately 3k lines of code (100 kB). The code does nothing, it’s a definition of a rather big class with many parameters and functions but that class never gets instantiated or used in any way.
I am accessing test.php at the rate of 100 requests/second until it gets accessed 1000 times. After that I make sure the server is calm and run the test again. First few runs are usually fine. Then the following run has some timed out requests. The next run has much more timed out requests. And then if I do it again, almost all requests fail while top is showing a couple php5-fpm doing something that requires 100% of CPU. It usually takes minutes for the server to calm down and while in this state, any attempts to do HTTP requests result in 504 error.
Same tests with static files (e.g. test.html) or an empty test2.php which has php open-close tags only, produce no interesting results, everything runs smoothly.
The server is an Nginx AWS EC2 instance. I tried playing with configs with no luck so far. Below are some of the parameters that might be relevant.
root@ip-...:~# cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
cpu family : 6
model : 23
model name : Intel(R) Xeon(R) CPU E5430 @ 2.66GHz
stepping : 10
cpu MHz : 2659.994
cache size : 6144 KB
fdiv_bug : no
hlt_bug : no
f00f_bug : no
coma_bug : no
fpu : yes
fpu_exception : yes
cpuid level : 13
wp : yes
flags : fpu tsc msr pae cx8 cmov pat pse36 clflush dts mmx fxsr sse sse2 ss ht pbe nx lm constant_tsc up arch_perfmon pebs bts aperfmperf pni dtes64 monitor ds_cpl vmx est tm2 ssse3 cx16 xtpr pdcm dca sse4_1 lahf_lm dts tpr_shadow vnmi flexpriority
bogomips : 5319.98
clflush size : 64
cache_alignment : 64
address sizes : 38 bits physical, 48 bits virtual
power management:
root@ip-...:~# nproc
1
pm.max_requests = 500
pm.max_children = 5
pm = dynamic
nginx.conf
worker_processes 4;
events {
worker_connections 768;
}
http {
gzip on;
client_body_timeout 300;
client_header_timeout 300;
send_timeout 300;
sendfile on;
tcp_nopush on;
tcp_nodelay on;
keepalive_timeout 65;
types_hash_max_size 2048;
}
I tried decreasing this to 1 nginx worker + 1 php child as well as playing with a few other things but none of these things appear to be making any difference. From what I can tell memory never gets swapped. Any ideas on what else can be debugged or checked, would be highly appreciated!
Use
apc. This will cache the parsed PHP file as opcode and skip parsing it over and over again.