cloudwego / volo

Rust RPC framework with high-performance and strong-extensibility for building micro-services.
https://crates.io/crates/volo
Apache License 2.0
2.2k stars 180 forks source link

Implement a limiter Layer for volo / 为 Volo 实现一个过载保护 Layer #9

Open PureWhiteWu opened 2 years ago

PureWhiteWu commented 2 years ago

Feature Request

Crates

This should be placed under https://github.com/volo-rs.

这应该放在 volo-rs 组织下,作为 volo 的生态。

Motivation

Limiters are very useful when under high qps, which can prevent the server from being overload.

We can support it for volo.

过载保护对于在大流量下保护 server 非常有用,这可以防止 server 被打挂然后雪崩。

Proposal

We propose to support a QPS limiter and a concurrent limiter for volo.

实现一个 QPS limiter 和一个 concurrent limiter,尽可能让 gRPC 和 Thrift 都能用。

changrui0608 commented 2 years ago

If nobody is working on it yet, I may have a try. Although I may have little free time so this may takes a long time. It's OK to assign to other people if I'm not responding.

如果还没人认领,我就先占个坑吧,但不保证投入时间,若之后没响应,也可转让其他人接手。

我这里曾在其他语言框架下,对过载保护有些许经验,包括一些更复杂的机制(e.g. 自监控过载程度、请求优先级机制),想正好先通过相对没那么复杂的 qps 或 concurrent 来尝试上手语言、框架,再之后若时间允许,也会在 volo 下尝试一下上述高级算法的可能性。

PureWhiteWu commented 2 years ago

@raaay0608 十分欢迎!作为认领者,你觉得 crate 名叫什么比较好(我建议以volo-开头)?我帮你在 volo-rs 组织下建立一个 repo~

changrui0608 commented 2 years ago

@raaay0608 十分欢迎!作为认领者,你觉得 crate 名叫什么比较好(我建议以volo-开头)?我帮你在 volo-rs 组织下建立一个 repo~

我觉得不着急建仓,我先在我名下自建repo开发,时机成熟时转移,届时可以按照那时的规划定来修改。(另一方面也防止万一我鸽了,留一个空仓太难看了哈哈哈)

我这边暂时的想法是,根据看你们的代码库规划,若希望所有过载保护类的内容都在一个仓内或者一个group内,据我了解过载保护对应英文是 overload control,因而可以叫 volo-overload-control。若各自为仓,可以类似于 volo-concurrency-limiter 或者 volo-flow-control-limiter 等等,可以参考这个想法来做后续规划。

PureWhiteWu commented 2 years ago

@raaay0608 ok,没问题,我觉得具体是拆分多个仓库还是在一个仓库内,取决于是否有一些公用的组件,以及你作为实现者的个人选择。 期待你的贡献~

changrui0608 commented 2 years ago

@PureWhiteWu 这里初步实现了一版:https://github.com/raaay0608/volo-limit/pull/1/ 还希望帮助确认:

  1. 是否还有 code review 需要、代码库规范要求等等,任何问题,可以直接提在上边的链接中
  2. 若代码层面 ok 之后,是否我直接 transfer ownership 到 https://github.com/volo-rs 下即可
PureWhiteWu commented 2 years ago

@raaay0608 太赞了,非常感谢你的贡献,我今天会尽快 review 一下~

PureWhiteWu commented 2 years ago

很抱歉今天事情比较多,没有 review 完,明天我会继续 review~

changrui0608 commented 1 year ago

Hi,抱歉直到最近才有时间和状态填这个坑 concurrency limiter的部分已经重新整理,see:https://github.com/changrui0608/volo-concurrency-limiter/pull/1 若这个没有太大问题,rate limiter 也会重新整理尽快提供 @PureWhiteWu