高速缓存前后压力测试
1.设置高速缓存前
[root@foundation1 ~]# ab -c10 -n5000 http://172.25.1.1/example.php %十个并发,每个5000个请求
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 172.25.1.1 (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: openresty/1.19.3.1
Server Hostname: 172.25.1.1
Server Port: 80
Document Path: /example.php
Document Length: 116 bytes
将测试页放置到openresty中nginx的默认发布目录下:
此时采用的是传统的缓存策略:
2.设置高速缓存
[root@server1 html]# pwd
/usr/local/openresty/nginx/html
[root@server1 html]# cd ..
[root@server1 nginx]# cd conf/
[root@server1 conf]# vim nginx.conf
upstream memcache {
server 127.0.0.1:11211;
keepalive 512;
}
location /memc {
internal;
memc_connect_timeout 100ms;
memc_send_timeout 100ms;
memc_read_timeout 100ms;
set $memc_key $query_string;
set $memc_exptime 300;
memc_pass memcache;
}
location ~ \.php$ {
set $key $uri$args;
srcache_fetch GET /memc $key; %现在memcache中找,如果有则直接返回,如果没有再通过fastcgi去后端找
srcache_store PUT /memc $key; %将在后端找到的值存储到memcache中,下次再请求的时候可以直接返回
root html;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
#fastcgi_param SCRIPT_FILENAME /scripts$fastcgi_script_name;
include fastcgi.conf;
}
[root@server1 conf]# /usr/local/openresty/nginx/sbin/nginx -t %检测是否有语法错误
nginx: the configuration file /usr/local/openresty/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty/nginx/conf/nginx.conf test is successful
[root@server1 conf]# /usr/local/openresty/nginx/sbin/nginx -s reload %重新加载
此时采用的是高速缓存策略:
3.再次进行压力测试
[root@foundation1 ~]# ab -c10 -n5000 http://172.25.1.1/example.php
This is ApacheBench, Version 2.3 <$Revision: 1843412 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking 172.25.1.1 (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: openresty/1.19.3.1
Server Hostname: 172.25.1.1
Server Port: 80
Document Path: /example.php
Document Length: 116 bytes
Concurrency Level: 10
Time taken for tests: 0.646 seconds
Complete requests: 5000
Failed requests: 0
Total transferred: 1529979 bytes
HTML transferred: 580000 bytes
Requests per second: 7739.47 [#/sec] (mean) %请求速度明显加快
Time per request: 1.292 [ms] (mean)
Time per request: 0.129 [ms] (mean, across all concurrent requests)
Transfer rate: 2312.74 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 0 0 0.1 0 2
Processing: 0 1 0.3 1 5
Waiting: 0 1 0.3 1 5
Total: 1 1 0.3 1 6
Percentage of the requests served within a certain time (ms)
50% 1
66% 1
75% 1
80% 1
90% 2
95% 2
98% 2
99% 2
100% 6 (longest request)