当前位置:网站首页>限流与下载接口请求数控制
限流与下载接口请求数控制
2022-06-11 00:11:00 【程序员青菜】
收银台系统相对于互联网应用流量要平稳很多,高峰流量也就平时的三倍,完全是可控的,我们这里用限流主要是控制后台同时下载XLS表格的请求数,因为后台系统要提供大量的导出XLS表格功能,收银员与管理人员需要用我们导出的数据去做各种分析(应该是我们的报表功能还不够完善造成的)。
下面整理一下Guaua提供的限流工具以及我们自己的做法。
一、使用LoadCaching实现接口限流
思路:创建LoadCaching对象,设置有效期为1秒,缓存Key为时间戳(当前秒数),值是计数器(调用次数累加),如果查询命中计数器自增,当计数器值大于限定值时不处理,如果没有命令中,创建一个新的时间戳缓存并初始化值为0,达到限流的目的。

二、使用RateLimter限流
RateLimter限制对资源的访问速率,有两种获取令牌的接口,一种是非阻塞式,拿不到令牌直接返回false,另一种是阻塞式,拿不到令牌等待令牌。
RateLimiter rateLimiter = RateLimiter.create(10)
每秒创建令牌的数量
三、下载接口请求数量限流
思路:创建一个拦截器,使用redis存储当前下载的请求(生成一个唯一串),判断当前redis该key的size大小,如果超过限定值,就直接返回需要等待的消息,当下载完成后,将该请求唯一串从redis中删除。

边栏推荐
- Animation
- ViewPager和底部无线循环的小圆点
- [ROS tutorial] - 02 ROS installation
- 【VBA脚本】提取word文档中所有批注的信息和待解决状态
- What is MYCAT? Get to know you quickly
- ion_ mmap
- 记录oracle的几个参数 db_files,Cursor_sharing ,open_cursor
- table_exists_action=append和table_exists_action=truncate
- ADB loop output memory information to folder
- WSL 自动更新 ip hosts 文件
猜你喜欢

Viewpager and dot of bottom wireless loop
WSL 自动更新 ip hosts 文件

文件“Setup”不存在,怎么办?

Teach you the front and back separation architecture (V) system authentication implementation

适配器模式
【ROS入门教程】---- 02 ROS安装

为什么使用 Golang 进行 Web 开发

What is the difference between hubs, switches and routers?

System interpretation: Authority Design Guide

The best creative drum tool: groove agent 5
随机推荐
Why web development with golang
DeepStream系列之鱼眼相机测试
SQL审核 | “云上”用户可以一键使用 SQLE 审核服务啦
pytorch分类问题总结
Wechat applet to realize OCR scanning recognition
为什么使用 Golang 进行 Web 开发
SqlServer中的锁
Promise
Team management | how to improve the thinking skills of technical leaders?
Load balancing strategy graphic explanation
day01
五大类型负载均衡的原理场景详解
ADB loop output memory information to folder
时间相关-格式、运算、比较、转换
【ROS入门教程】---- 03 ROS工作空间与功能包
【原】expdp参数CONTENT
Alicloud configures SLB (load balancing) instances
The driver has not received any packets from the server
Solid basic knowledge + correct method is the key to quickly read the source code
OTA升级