深圳網(wǎng)站營(yíng)銷(xiāo)推廣公司電話網(wǎng)絡(luò)推廣怎么找客戶資源
參數(shù)設(shè)置
- 熔斷時(shí)長(zhǎng) 、最小請(qǐng)求數(shù)、最大RT ms、比例閾值、異常數(shù)
熔斷策略
- 慢調(diào)??例
- 當(dāng)單位統(tǒng)計(jì)時(shí)?內(nèi)請(qǐng)求數(shù)??于設(shè)置的最?請(qǐng)求數(shù)?,并且慢調(diào)?的?例?于閾值,則接下來(lái)的熔斷時(shí)?內(nèi)請(qǐng)求會(huì)?動(dòng)被熔斷
- 異常?例
- 當(dāng)單位統(tǒng)計(jì)時(shí)?內(nèi)請(qǐng)求數(shù)??于設(shè)置的最?請(qǐng)求數(shù)?,并且異常的?例?于閾值,則接下來(lái)的熔斷時(shí)?內(nèi)請(qǐng)求會(huì)?動(dòng)被熔斷
- 異常數(shù)
- 當(dāng)單位統(tǒng)計(jì)時(shí)?內(nèi)的異常數(shù)?超過(guò)閾值之后會(huì)?動(dòng)進(jìn)?熔斷
- 熔斷規(guī)則
- 熔斷條件
- 接口異常率超過(guò)10%,或者慢調(diào)用(響應(yīng)時(shí)間>3s)的比例大于20%,觸發(fā)60s熔斷
- 熔斷操作
- 直接返回默認(rèn)實(shí)現(xiàn)
- 熔斷條件
ZooKeeper 作為配置中心
Sentinel 是阿里巴巴開(kāi)源的一套服務(wù)容錯(cuò)框架,用于服務(wù)的流量控制、熔斷和系統(tǒng)負(fù)載保護(hù)。Sentinel 可以通過(guò)多種方式動(dòng)態(tài)配置規(guī)則,其中包括使用 ZooKeeper 作為配置中心來(lái)集中管理和推送規(guī)則。以下是 Sentinel 如何使用 ZooKeeper 的基本步驟和配置:
- 搭建 ZooKeeper 環(huán)境:
- 啟動(dòng) ZooKeeper 服務(wù),可以使用 ZooKeeper 的常用命令來(lái)管理服務(wù),例如啟動(dòng) (sh bin/zkServer.sh start)、查看狀態(tài) (sh bin/zkServer.sh status)、停止 (sh bin/zkServer.sh stop) 和重啟 (sh bin/zkServer.sh restart) 服務(wù)。
- 引入 ZooKeeper 依賴(lài):
- 在 Sentinel Dashboard 工程中引入 ZooKeeper 相關(guān)的依賴(lài),例如使用 Apache Curator 客戶端:
<dependency> <groupId>org.apache.curator</groupId> <artifactId>curator-recipes</artifactId> <version>${curator.version}</version> </dependency>
注意去掉 test 標(biāo)簽,以便在非測(cè)試環(huán)境中使用。
- 同步規(guī)則到 ZooKeeper:
- 在 Sentinel Dashboard 中,通過(guò) ZooKeeper 同步流控規(guī)則和降級(jí)規(guī)則。需要指定 ZooKeeper 路徑(zkpath)來(lái)存儲(chǔ)規(guī)則信息,例如:
// 流控規(guī)則 final String flowPath = "/sentinel_rule_config/" + appName + "/flow"; // 降級(jí)規(guī)則 final String degradePath = "/sentinel_rule_config/" + appName + "/degrade";
其中 appName 是應(yīng)用的名稱(chēng)。
- 修改 Controller:
- 修改 Sentinel Dashboard 中的 Controller,以便在規(guī)則變更時(shí)通過(guò) ZooKeeper 發(fā)送通知。這涉及到修改流控規(guī)則(FlowController)和降級(jí)規(guī)則(DegradeController)的 Controller。
- 客戶端配置:
- 在客戶端項(xiàng)目中引入 Sentinel ZooKeeper 數(shù)據(jù)源依賴(lài):
<dependency> <groupId>com.alibaba.csp</groupId> <artifactId>sentinel-datasource-zookeeper</artifactId> <version>${sentinel.version}</version> </dependency>
- 創(chuàng)建 ZookeeperDataSource 實(shí)例并注冊(cè)到對(duì)應(yīng)的 RuleManager:
ReadableDataSource<String, List<FlowRule>> flowRuleDataSource = new ZookeeperDataSource<>(remoteAddress, path, source -> JSON.parseObject(source, new TypeReference<List<FlowRule>>() {})); FlowRuleManager.register2Property(flowRuleDataSource.getProperty());
其中 remoteAddress 是 ZooKeeper 服務(wù)地址,path 是數(shù)據(jù)路徑。
通過(guò)以上步驟,Sentinel 可以利用 ZooKeeper 來(lái)集中管理和推送規(guī)則,實(shí)現(xiàn)規(guī)則的持久化和實(shí)時(shí)更新。這樣,即使服務(wù)重啟,配置的規(guī)則也不會(huì)丟失,并且可以快速響應(yīng)規(guī)則的變化。