alibaba / Sentinel

A powerful flow control component enabling reliability, resilience and monitoring for microservices. (面向云原生微服务的高可用流控防护组件)
https://sentinelguard.io/
Apache License 2.0
22.29k stars 7.99k forks source link

Redis-based token client implementation of cluster flow control #1188

Open bigstar119 opened 4 years ago

bigstar119 commented 4 years ago

TokenServer为什么不基于Redis时间窗口来实现呢?或者Redis本身就是一个TokenServer呀! 以“应用名_资源名_规则ID_参数值”作为redis的Key,时间窗口长度(durationInSec)为ttl,创建一条redis记录,创建记录通过 set key value ex ttl nx 指令,确保时间窗口内有且仅有一条有效记录。然后,通过incrBy key count指令进行分布式累积,当累积值超过阀值时,触发限流。 此外,还可以利用redis的分布式和抗压的特点,提长TokenServer的性能。 -- For English user why TokenServer is not based on Redis? or Redis itselt is a good TokenServer! create a redis key like "namespace_resource_flowId_param", ttl=durationInSec, use cmd "set key value ex ttl nx" to make sure in timeWindow only create on record. then use cmd "incrBy key count" for accumulation. if count > threshold then fired block Event.

sczyh30 commented 4 years ago

Considering performance and flexibility, Redis may not satisfy all scenarios for cluster flow control. However, it's encouraged to introduce a token client implementation based on Redis (lua script) so that users who leverage Redis as the token server could also use Sentinel (and benefit from advanced features and open-source ecosystem of Sentinel). Contributions are welcomed!

binecy commented 4 years ago

我们正在开发该功能,通过lua脚本定位滑动窗口和数据统计,后续可以提PR吗

sczyh30 commented 4 years ago

我们正在开发该功能,通过lua脚本定位滑动窗口和数据统计,后续可以提PR吗

@binecy Contributions are welcomed! This can be an individual token client module. You may refer to the SPI hierarchy of the token client.

binecy commented 4 years ago

ok