服务器dell 2950 8核,16g,网卡千兆,两台机器,一台做api网关+redis(日志级别error),一台php 关闭日志
openresty做api层(lua连接redis已使用连接池,keepalive 100),openresty+php调用api层接口,
php代码如下:
<?php
function microtime_float()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$ch = curl_init();
//设置选项,包括URL
curl_setopt($ch, CURLOPT_URL, "http://192.168.2.20/hb");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
//执行并获取HTML文档内容
$time_start = microtime_float();
$output = curl_exec($ch);
$time_end = microtime_float();
$time = $time_end - $time_start;
echo "耗时:{$time}";
//释放curl句柄
curl_close($ch);
//打印获得的数据
?>
ab -k -c 100 -n 99999 http://192.168.2.161/test2.php
压测结果:
Server Software: openresty/1.9.3.2
Server Hostname: 192.168.2.161
Server Port: 80
Document Path: /test2.php
Document Length: 1 bytes
Concurrency Level: 100
Time taken for tests: 20.540 seconds
Complete requests: 99999
Failed requests: 0
Keep-Alive requests: 0
Total transferred: 15399846 bytes
HTML transferred: 99999 bytes
Requests per second: 4868.62 [#/sec] (mean)
Time per request: 20.540 [ms] (mean)
Time per request: 0.205 [ms] (mean, across all concurrent requests)
Transfer rate: 732.19 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 1 25.9 0 1000
Processing: 2 20 3.1 20 38
Waiting: 2 20 3.1 20 38
Total: 3 21 25.9 20 1021
Percentage of the requests served within a certain time (ms)
50% 20
66% 21
75% 21
80% 21
90% 21
95% 21
98% 22
99% 22
100% 1021 (longest request)
压测一直保持在4800数值左右,加多台机器也是这个数值
服务器状态如下:
php机器
PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
22553 nobody 20 0 61716 6472 1072 S 32.5 0.0 0:20.41 nginx
10608 www 20 0 2280m 8728 3216 S 30.5 0.1 8:18.16 php-fpm
10604 www 20 0 2280m 8744 3236 S 30.2 0.1 8:14.75 php-fpm
10605 www 20 0 2280m 8768 3256 S 30.2 0.1 8:19.35 php-fpm
10606 www 20 0 2280m 8596 3092 S 30.2 0.1 8:12.25 php-fpm
10607 www 20 0 2280m 8728 3216 S 30.2 0.1 8:14.63 php-fpm
10609 www 20 0 2280m 9464 3932 S 30.2 0.1 8:19.13 php-fpm
22551 nobody 20 0 61656 6412 1072 R 26.6 0.0 0:26.76 nginx
22554 nobody 20 0 61508 6212 1076 S 22.9 0.0 0:25.03 nginx
api网关
1885 root 20 0 242m 117m 1200 R 36.9 0.7 13:52.29 redis-server
14795 nobody 20 0 582m 5488 2572 S 31.9 0.0 1:15.07 nginx
14792 nobody 20 0 582m 5736 2600 S 27.2 0.0 1:33.00 nginx
14794 nobody 20 0 582m 5528 2540 S 14.9 0.0 1:15.22 nginx
请问是什么原因导致呢,发生阻塞操作了吗,我需要如何优化才能把机器剩余性能用上!