<?php
function make_seed() {
list($usec,$sec)=explode(' ',microtime());
return(float) $sec+((float)$usec*100000);
}
$i=0;
$k=0;
while($i < 1000){
$i++;
mt_srand(make_seed());
if($i%2 == 0)
$k += mt_rand();
else
$k -= mt_rand();
}
echo $k;
phpinfo();
?>
测试方法:
-
在同网段找一台服务器
-
使用webbench来测试
-
./webbench -c 500 -t 30 http:
-
-
cat nginx-access.log | grep -v 200 | grep WebBench | wc -l
-
检查返回内容的稳定性
在同网段找一台服务器
使用webbench来测试
./webbench -c 500 -t 30
cat nginx-access.log | grep -v 200 | grep WebBench | wc -l
检查返回内容的稳定性
测试结果(每种测试3次,每次都重启nginx和php-fpm):
Tcp socket的情况
-
异常返回:4
-
Speed=14502 pages/min, 11660916 bytes/sec.
-
Requests: 7251 susceed, 0 failed.
-
异常返回:0
-
Speed=14480 pages/min, 11644002 bytes/sec.
-
Requests: 7240 susceed, 0 failed.
-
异常返回:1 (http 499 客户端断开连接)
-
Speed=14542 pages/min, 11693312 bytes/sec.
-
Requests: 7271 susceed, 0 failed.
异常返回:4
Speed=14502 pages/min, 11660916 bytes/sec.
Requests: 7251 susceed, 0 failed.
异常返回:0
Speed=14480 pages/min, 11644002 bytes/sec.
Requests: 7240 susceed, 0 failed.
异常返回:1 (http 499 客户端断开连接)
Speed=14542 pages/min, 11693312 bytes/sec.
Requests: 7271 susceed, 0 failed.
Unix socket的情况(放在/dev/shm中)
-
异常返回:388
-
Speed=15194 pages/min, 11600151 bytes/sec.
-
Requests: 7596 susceed, 1 failed.
-
异常返回:271
-
Speed=15020 pages/min, 11644336 bytes/sec.
-
Requests: 7510 susceed, 0 failed.
-
异常返回:831
-
Speed=16110 pages/min, 11625129 bytes/sec.
-
Requests: 8054 susceed, 1 failed.
异常返回:388
Speed=15194 pages/min, 11600151 bytes/sec.
Requests: 7596 susceed, 1 failed.
异常返回:271
Speed=15020 pages/min, 11644336 bytes/sec.
Requests: 7510 susceed, 0 failed.
异常返回:831
Speed=16110 pages/min, 11625129 bytes/sec.
Requests: 8054 susceed, 1 failed.
Unix socket的情况(放在/tmp中)
-
异常返回:230
-
Speed=14972 pages/min, 11632380 bytes/sec.
-
Requests: 7459 susceed, 27 failed.
-
异常返回:647
-
Speed=15804 pages/min, 11687138 bytes/sec.
-
Requests: 7898 susceed, 4 failed.
-
异常返回:698
-
Speed=15944 pages/min, 11685551 bytes/sec.
-
Requests: 7972 susceed, 0 failed.
异常返回:230
Speed=14972 pages/min, 11632380 bytes/sec.
Requests: 7459 susceed, 27 failed.
异常返回:647
Speed=15804 pages/min, 11687138 bytes/sec.
Requests: 7898 susceed, 4 failed.
异常返回:698
Speed=15944 pages/min, 11685551 bytes/sec.
Requests: 7972 susceed, 0 failed.
针对上面的测试结果,简单总结一下,未必客观,仅供参考:
-
UnixSocket性能比TcpSocket最多高不超过10%
-
UnixSocket的异常率比TcpSocket至少高226倍
-
UnixSocket返回异常时,Http Code 502,php-fpm返回11: Resource temporarily unavailable,google后尝试修改backlog,但结果无明显变化
-
-
结论:在查明UnixSocket异常原因之前,建议依然使用TcpSocket(即默认的127.0.0.1:9000方式)
UnixSocket性能比TcpSocket最多高不超过10%
UnixSocket的异常率比TcpSocket至少高226倍
UnixSocket返回异常时,Http Code 502,php-fpm返回11: Resource temporarily unavailable,google后尝试修改backlog,但结果无明显变化
结论:在查明UnixSocket异常原因之前,建议依然使用TcpSocket(即默认的127.0.0.1:9000方式)
附:
看到了这篇文章:
-
echo 'net.core.somaxconn = 2048' >> /etc/sysctl.conf
-
sysctl -p