本文主要介绍了CDN是什么,以及为什么使用它,还有怎么解决ThinkPHP5.1 MISS缓存未命中问题,下面一起来看一下,希望能给大家带来帮助。
聊聊ThinkPHP5.1中出现的MISS缓存未命中问题
问题
在单独给首页配置CDN加速后,出现了X-Cache: MISS TCP_MISS dirn:-2:-2,MISS也就是缓存没有被命中。这个问题不是配置错了,而框架问题。
解决方法
第一步:public/index.php读取/设置缓存限制器:
<?php
namespace think;
// 设置缓存限制
session_cache_limiter('public');
require __DIR__ . '/../thinkphp/base.php';
Container::get('app')->run()->send();
第二步:开启请求缓存:
// 文件位置: config/app.php
'request_cache' => true,
ab压测:
如下压测是经过了CDN+OSS之后的结果,可以看到qps可以达到573:
$ ab -c100 -n1000 你的页面URL
This is ApacheBench, Version 2.3 <$Revision: 1430300 $>
Copyright 1996 Adam Twiss, Zeus Technology Ltd, http://www.zeustech.net/
Licensed to The Apache Software Foundation, http://www.apache.org/
Benchmarking miaosha.nikexu.com (be patient)
Completed 100 requests
Completed 200 requests
Completed 300 requests
Completed 400 requests
Completed 500 requests
Completed 600 requests
Completed 700 requests
Completed 800 requests
Completed 900 requests
Completed 1000 requests
Finished 1000 requests
Server Software: Tengine
Server Hostname: miaosha.nikexu.com
Server Port: 80
Document Path: /
Document Length: 774 bytes
Concurrency Level: 100
Time taken for tests: 1.745 seconds
Complete requests: 1000
Failed requests: 0
Write errors: 0
Total transferred: 1403829 bytes
HTML transferred: 774000 bytes
Requests per second: 573.16 [#/sec] (mean)
Time per request: 174.472 [ms] (mean)
Time per request: 1.745 [ms] (mean, across all concurrent requests)
Transfer rate: 785.76 [Kbytes/sec] received
Connection Times (ms)
min mean[+/-sd] median max
Connect: 15 17 1.5 16 25
Processing: 18 91 113.4 71 1195
Waiting: 18 90 113.4 71 1195
Total: 36 107 113.4 87 1212
Percentage of the requests served within a certain time (ms)
50% 87
66% 99
75% 103
80% 105
90% 120
95% 195
98% 437
99% 834
100% 1212 (longest request)
在来看看500个并发的压测:
ab -c500 -n10000 你的页面URL
Requests per second: 965.61 [#/sec] (mean)
Time per request: 517.806 [ms] (mean)
Time per request: 1.036 [ms] (mean, across all concurrent requests)
Percentage of the requests served within a certain time (ms)
50% 257
66% 319
75% 541
80% 1043
90% 1102
95% 1281
98% 1560
99% 1821
100% 3771 (longest request)
通过这个两个手段,已经可以看到还并发量提供,500的并发量,80%的用户可以在1s左右打开。在没有使用CDN+OSS前,我压测的结果是 150的并发,CPU就冲到了90%。使用OSS+CDN的优势就不言而喻了。
关于ThinkPHP5.1中出现的MISS缓存未命中问题的解析就到这里,翼速应用平台内有更多相关资讯,欢迎查阅!
我来说两句