lamp架构(6)-构建nginx高速缓存

高速缓存前后压力测试

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)
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值