快速解决ThinkPHP5.1出现MISS缓存未命中问题
本篇文章给大家带来了关于ThinkPHP5.1的相关知识,其中主要介绍了CDN是什么?为什么使用它?怎么解决ThinkPHP5.1 MISS缓存未命中问题?感兴趣的朋友下面一起来看一下吧,希望对大家有帮助。
ThinkPHP5.1使用CDN加速-MISS缓存未命中解决
在单独给首页配置CDN加速后,出现了X-Cache: MISS TCP_MISS dirn:-2:-2,MISS也就是缓存没有被命中。这个问题不是配置错了,而框架问题。
什么要使用CDN?
“cdn简介 CDN的全称是Content Delivery Network,即内容分发网络。
为什么使用CDN?
CDN就近节点访问,提高了网站加载速度,降低延时;能起到分流作用,减轻服务器负载,
使用动静分离提高网站访问速度。
配置实现
这个呢,我是部署在了生产环境,实际测试大并发高流量处理,当然了,也有很多的不足。
环境
服务器:腾讯云
系统:CentOS7
框架:ThinkPHP5.1
使用阿里云OSS+CDN并配置缓存
当然还要有经过备案的域名。
关于怎么使用阿里云OSS对象存储系统,Laravel6.x上传视频到阿里云Oss对象存储 这篇文章记录过。
bucket创建完成后,可以在列表中看到 '阿里云 CDN 加速',点击这个进行相关的CDN操作,配置完后需要在域名中进行解析。
问题
在单独给首页配置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的优势就不言而喻了。
本文网址:https://www.zztuku.com/index.php/detail-13783.html
站长图库 - 快速解决ThinkPHP5.1出现MISS缓存未命中问题
申明:本文转载于《ziruchu》,如有侵犯,请 联系我们 删除。
您还没有登录,请 登录 后发表评论!
提示:请勿发布广告垃圾评论,否则封号处理!!