PHP+MySQL页面访问速度分析(ab命令),本地访问0.7ms/request(硬件条件充足)

PHP+MySQL页面访问速度分析(ab命令),本地访问0.7ms/request(硬件条件充足)

test.php内容:

<?php
//数据库连接 php /newdata/web/web/test/test/testmysql.php
$mysqli = new mysqli('localhost', 'root', '', 'test0220',3306);
$mysqli->set_charset("utf8");
//获取用户列表,匹配用户信息
$sql = "select * from user limit 1";
$result = $mysqli->query($sql);
$list_user = $result->fetch_array(MYSQLI_ASSOC);
var_dump($list_user);
?>

测试用例1:1个并发量发送100个请求,testmysql.php页面为一个字符a,本地访问,服务器cpu,内存等硬件资源充足。在(注意如果只发送1个请求,测试结果为每个请求1.2ms)

[root@iZ25ja2kaemZ ~]# ab -c 1 -n 100  http://testlocals.bestbeijing.top/test/testmysql.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking testlocals.bestbeijing.top (be patient).....done
Server Software:        Apache/2.2.15
Server Hostname:        testlocals.bestbeijing.top
Server Port:            80

Document Path:          /test/testmysql.php
Document Length:        101 bytes

Concurrency Level:      1
Time taken for tests:   0.074 seconds
Complete requests:      100
Failed requests:        0
Write errors:           0
Total transferred:      29500 bytes
HTML transferred:       10100 bytes
Requests per second:    1355.22 [#/sec] (mean)
Time per request:       0.738 [ms] (mean)
Time per request:       0.738 [ms] (mean, across all concurrent requests)
Transfer rate:          390.42 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0    0   0.0      0       0
Processing:     1    1   0.1      1       1
Waiting:        0    1   0.1      1       1
Total:          1    1   0.1      1       1

Percentage of the requests served within a certain time (ms)
  50%      1
  66%      1
  75%      1
  80%      1
  90%      1
  95%      1
  98%      1
  99%      1
 100%      1 (longest request)

测试用例2:5000个并发量发送5000个请求,,平均每个请求耗时1.2ms。本地访问,可见耗时比1个并发量增长为大概2倍,说明服务器cpu,内存资源或web服务器apache配置等达到了瓶颈,需要优化web服务器配置,因为本地测试,一定不是带宽的问题,且配置了hosts,本地带宽很大。

[root@iZ25ja2kaemZ ~]# ab -c 5000 -n 5000  http://testlocals.bestbeijing.top/test/testmysql.php
This is ApacheBench, Version 2.3 <$Revision: 655654 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/

Benchmarking testlocals.bestbeijing.top (be patient)
Completed 500 requests
Completed 1000 requests
Completed 1500 requests
Completed 2000 requests
Completed 2500 requests
Completed 3000 requests
Completed 3500 requests
Completed 4000 requests
Completed 4500 requests
Completed 5000 requests
Finished 5000 requests

Server Software:        Apache/2.2.15
Server Hostname:        testlocals.bestbeijing.top
Server Port:            80

Document Path:          /test/testmysql.php
Document Length:        101 bytes

Concurrency Level:      5000
Time taken for tests:   6.017 seconds
Complete requests:      5000
Failed requests:        0
Write errors:           0
Total transferred:      1482965 bytes
HTML transferred:       507727 bytes
Requests per second:    830.99 [#/sec] (mean)
Time per request:       6016.955 [ms] (mean)
Time per request:       1.203 [ms] (mean, across all concurrent requests)
Transfer rate:          240.69 [Kbytes/sec] received

Connection Times (ms)
              min  mean[+/-sd] median   max
Connect:        0  899 1259.3     78    3093
Processing:     1  883 1280.2    147    5289
Waiting:        0  865 1280.8    134    5256
Total:        149 1782 2200.0    216    5911

Percentage of the requests served within a certain time (ms)
  50%    216
  66%   1756
  75%   4504
  80%   4789
  90%   5363
  95%   5538
  98%   5774
  99%   5779
 100%   5911 (longest request)

(0)

相关推荐