---02---
---03---
10K以上的。
nginx是5万。
---09---
---11---
测试,将首页的广告缓存进去。
lua脚本
ngx.header.content_type="application/json;charset=utf8"
local cjson = require("cjson")
local mysql = require("resty.mysql")
local uri_args = ngx.req.get_uri_args()
local id = uri_args["id"]
local db = mysql:new()
db:set_timeout(1000)
local props = {
host = "192.168.211.132",
port = 3306,
database = "changgou_content",
user = "root",
password = "123456"
}
local res = db:connect(props)
local select_sql = "select url,pic from tb_content where status ='1' and category_id="..id.." order by sort_order"
res = db:query(select_sql)
db:close()
local redis = require("resty.redis")
local red = redis:new()
red:set_timeout(2000)
local ip ="192.168.211.132"
local port = 6379
red:connect(ip,port)
red:set("content_"..id,cjson.encode(res))
red:close()
ngx.say("{flag:true}")
修改nginx:
重新加载文件
---12---
添加缓存到广告中。
路径:
文件:
ngx.header.content_type="application/json;charset=utf8"
local uri_args = ngx.req.get_uri_args();
local id = uri_args["id"];
--获取本地缓存
local cache_ngx = ngx.shared.dis_cache;
--根据ID 获取本地缓存数据
local contentCache = cache_ngx:get('content_cache_'..id);
if contentCache == "" or contentCache == nil then
local redis = require("resty.redis");
local red = redis:new()
red:set_timeout(2000)
red:connect("192.168.244.140", 6379)
local rescontent=red:get("content_"..id);
if ngx.null == rescontent then
local cjson = require("cjson");
local mysql = require("resty.mysql");
local db = mysql:new();
db:set_timeout(2000)
local props = {
host = "192.168.244.140",
port = 3306,
database = "changgou_content",
user = "root",
password = "123456"
}
local res = db:connect(props);
local select_sql = "select url,pic from tb_content where status ='1' and category_id="..id.." order by sort_order";
res = db:query(select_sql);
local responsejson = cjson.encode(res);
red:set("content_"..id,responsejson);
ngx.say(responsejson);
db:close()
else
cache_ngx:set('content_cache_'..id, rescontent, 2*60);
ngx.say(rescontent)
end
red:close()
else
ngx.say(contentCache)
end
这个就是加载ngnix的缓存模块是需要定义的。
接下来我们定义nginx的缓存模块。
---13---
并发问题:
限流就是一个ip一秒钟允许请求有限的次数的。
---14---
漏桶和令牌桶:https://blog.csdn.net/m0_37477061/article/details/95313062?utm_source=blogxgwz4
漏桶实现:https://baijiahao.baidu.com/s?id=1666902623332115966&wfr=spider&for=pc
令牌桶实现:https://www.jianshu.com/p/f76730be59e0
限流是解决雪崩的一种有效的手段之一。
如何配置呢?
第一步:
第二步:
---
jMeter如何使用的呢?
第一步整一个单元测试:
第二步,线程15个:
第三步:
第四步:
执行
---
---15---
控制请求的并发量。
我们配置下。就是请求nginx的地址然后跳转到访问我的本地:
测试:都是并发数
---16---
canal:
数据库变了但是缓存还是有原来的数据的
还可以写es 或者其他的数据库
---17---
canal的原理。
---18---
---19---
---
---20---
微服务的搭建
注意这个
安装下。
---21---
---22---