天天看點

暢購商城---canal和nginx緩存---04

暢購商城---canal和nginx緩存---04

---02---

暢購商城---canal和nginx緩存---04
暢購商城---canal和nginx緩存---04

---03---

10K以上的。

nginx是5萬。

---09---

暢購商城---canal和nginx緩存---04

---11---

測試,将首頁的廣告緩存進去。

暢購商城---canal和nginx緩存---04

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:

暢購商城---canal和nginx緩存---04

重新加載檔案

暢購商城---canal和nginx緩存---04
暢購商城---canal和nginx緩存---04

---12---

添加緩存到廣告中。

路徑:

暢購商城---canal和nginx緩存---04

檔案:

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
           
暢購商城---canal和nginx緩存---04

這個就是加載ngnix的緩存子產品是需要定義的。

接下來我們定義nginx的緩存子產品。

暢購商城---canal和nginx緩存---04
暢購商城---canal和nginx緩存---04

---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

限流是解決雪崩的一種有效的手段之一。

如何配置呢?

第一步:

暢購商城---canal和nginx緩存---04

第二步:

暢購商城---canal和nginx緩存---04

---

jMeter如何使用的呢?

第一步整一個單元測試:

暢購商城---canal和nginx緩存---04

第二步,線程15個:

暢購商城---canal和nginx緩存---04

第三步:

暢購商城---canal和nginx緩存---04
暢購商城---canal和nginx緩存---04

第四步:

暢購商城---canal和nginx緩存---04

執行

暢購商城---canal和nginx緩存---04

---

暢購商城---canal和nginx緩存---04
暢購商城---canal和nginx緩存---04

---15---

控制請求的并發量。

暢購商城---canal和nginx緩存---04

我們配置下。就是請求nginx的位址然後跳轉到通路我的本地:

暢購商城---canal和nginx緩存---04
暢購商城---canal和nginx緩存---04

測試:都是并發數

---16---

canal:

資料庫變了但是緩存還是有原來的資料的

暢購商城---canal和nginx緩存---04

還可以寫es 或者其他的資料庫

---17---

canal的原理。

---18---

暢購商城---canal和nginx緩存---04

---19---

暢購商城---canal和nginx緩存---04
暢購商城---canal和nginx緩存---04
暢購商城---canal和nginx緩存---04

---

暢購商城---canal和nginx緩存---04

---20---

微服務的搭建

暢購商城---canal和nginx緩存---04

注意這個

暢購商城---canal和nginx緩存---04

安裝下。

---21---

暢購商城---canal和nginx緩存---04

---22---

繼續閱讀