kitex
kitex copied to clipboard
Support customization of limiter implementation and fix the problem of mux server limiter.
Is your feature request related to a problem? Please describe.
Support customization of limiter implementation
Now the server limiter can only be created by Limits
options, which specify MaxConnections
and MaxQPS
.
https://github.com/cloudwego/kitex/blob/b889d3c7dff344dfd71868f19e090618e2a70eb4/pkg/limit/limit.go#L25
But customized limiter implementation is necessary for outside extention, such as the extention of polaris sdk, which has its own limiter implementation.
Fix the problem of mux server limiter
Now the qps limiter takes effect at OnRead callback. https://github.com/cloudwego/kitex/blob/b889d3c7dff344dfd71868f19e090618e2a70eb4/pkg/remote/bound/limiter_inbound.go#L52 But for mux server, it may cause problems, because requests are not recognized until they're decoded. So qps limiter for mux server should take effect at OnMessage callback.
Describe the solution you'd like
Support customization of limiter implementation
Add WithConcurrencyLimiter
and WithQPSLimiter
options to configure customized limiter.
Fix the problem of mux server limiter
For mux server, create another qps limiter which takes effect at OnMessage callback instead of OnRead.
Additional context
https://github.com/cloudwego/kitex/issues/421
限流的话,北极星是支持按照请求标签进行限流的,这里的话,如果只是按照 l.qpsLimit.Acquire() 的话,可能还不太够
@chuntaojun 感谢,已重新修改接口实现,在Limiter扩展中提供了Kitex请求参数。