当前位置:网站首页>Sentinel热门词汇限流如何实现
Sentinel热门词汇限流如何实现
2022-07-29 15:46:00 【亿速云】
Sentinel热门词汇限流如何实现
本文小编为大家详细介绍“Sentinel热门词汇限流如何实现”,内容详细,步骤清晰,细节处理妥当,希望这篇“Sentinel热门词汇限流如何实现”文章能帮助大家解决疑惑,下面跟着小编的思路慢慢深入,一起来学习新知识吧。
热点参数限流
何为热点?热点即经常访问的数据。很多时候我们希望统计某个热点数据中访问频次最高的 Top K 数据,并对其访问进行限制。比如:
商品 ID 为参数,统计一段时间内最常购买的商品 ID 并进行限制
用户 ID 为参数,针对一段时间内频繁访问的用户 ID 进行限制
热点参数限流会统计传入参数中的热点参数,并根据配置的限流阈值与模式,对包含热点参数的资源调用进行限流。热点参数限流可以看做是一种特殊的流量控制,仅对包含热点参数的资源调用生效。
基本使用
1、引入maven依赖
<dependency> <groupId>com.alibaba.csp</groupId> <artifactId>sentinel-parameter-flow-control</artifactId> <version>x.y.z</version></dependency>
2、手动编写代码添加限流规则
@RequestMapping("/getUserOrder")public String getUserOrder(Long userId) { Entry entry = null; try { entry = SphU.entry(getUserOrder, EntryType.IN, 1, userId); return "根据userId获取用户订单信息成功"; } catch (Exception e) { return "您操作的比较频繁,请稍后重试!"; } finally { if (entry != null) { entry.exit(); } }}// 定义热点限流的规则,对第一个参数设置 qps 限流模式,阈值为1ParamFlowRule rule = new ParamFlowRule(getUserOrder) .setParamIdx(0) .setGrade(RuleConstant.FLOW_GRADE_QPS) .setCount(1);ParamFlowRuleManager.loadRules(Collections.singletonList(rule));
或者使用控制台形式添加热词限流规则
正常编写Java接口
@RequestMapping("/getUserOrder")@SentinelResource(value = "getUserOrder")public String getUserOrder(Long userId) { return "根据userId获取用户订单信息成功";}
索引名:参数下表从 0 开始
单机阈值:单机部署时在统计时间内可以访问多少次
统计窗口时长:统计热词的时间
可以给指定的参数额外设定阈值:例如:VIP用户拥有特定的标识,判断为VIP用户时,可以请求接口的次数增加。
读到这里,这篇“Sentinel热门词汇限流如何实现”文章已经介绍完毕,想要掌握这篇文章的知识点还需要大家自己动手实践使用过才能领会,如果想了解更多相关内容的文章,欢迎关注亿速云行业资讯频道。
边栏推荐
- CAN报文:数据帧详解
- 一文读懂Elephant Swap,为何为ePLATO带来如此高的溢价?
- 718. The longest repeat subarray
- 化妆品行业分销渠道管理系统加强企业渠道管控能力,赋能化妆品渠道数字化升级
- 数字赋能机械制造业,供应链协同管理系统解决方案助力企业供应链再升级
- Linux environment redis complete configuration and startup command
- [Server Storage Data Recovery] A data recovery case of a RAID 5 crash caused by the failure of a certain model of Huawei OceanStor storage RAID 5 hard disk and the failure to synchronize data with the
- win10 校验sha256
- 【小程序项目开发--京东商城】uni-app之自定义搜索组件(上)-- 组件UI
- 大规模线上应用TiDB会遇到的坑,本文都帮你排除好了
猜你喜欢
【小程序项目开发-- 京东商城】uni-app之商品列表页面 (上)
File management: logical structure
This article penetrates the architecture design and cluster construction of the distributed storage system Ceph (hands-on)
Easy Genes: Human tRNA loci exhibit DNA hypermethylation associated with aging | Research Article
This article penetrates the architecture design and cluster construction of the distributed storage system Ceph (hands-on)
Altair SimSolid complex assembly meshless rapid structure simulation online seminars
边缘计算如何与小程序结合?智能家居如何借势发展?
图文结合纯c手写内存池
【PCL学习笔记】点云处理常用的库和API(PCL库+Eigen)
稳步向前不忘初心,沃尔沃的安全感来自公众的认可
随机推荐
浏览器线程
Impala时间函数总结
环球晶圆成功以43.5亿欧元获得Siltronic控股权
【PCL学习笔记】点云处理常用的库和API(PCL库+Eigen)
ByteArrayOutputStream 类源码分析
Win11 最新补丁更新破坏了任务栏中的“开始”菜单
数商云SCM供应链系统方案服务亮点:生产管理更智能、产业供应链协同管理更便捷
The future trend of the conversation
打卡广汽本田喜悦安全驾驶中心,体验最刁钻的场地训练
如果不知道这4种缓存模式,敢说懂缓存吗?
双非渣渣的上岸之路!备战 60 天,三战滴滴侥幸收获 Offer
参与一个rk3399的一起学习班级
See you in shenzhen!Cloud native to accelerate the application building special: see cloud native FinOps, SRE, high-performance computing scenario best practices
Alibaba 开源内网高并发编程手册
File management: logical structure
Turbine聚合监控
MySql数据库命令大全:数据库操作命令,表操作命令,修改表结构命令,数据操作命令,数据查询操作命令
联想集团宣布在科创板上市!杨元庆:进一步释放联想的价值!
教程篇(7.0) 07. 诊断和故障排除 * FortiClient EMS * Fortinet 网络安全专家 NSE 5
Recommended Remote Desktop Tools