https://github.com/limscoder/grpc-athrottle
Adaptive throttling for golang gRPC clients
https://github.com/limscoder/grpc-athrottle
Last synced: about 1 year ago
JSON representation
Adaptive throttling for golang gRPC clients
- Host: GitHub
- URL: https://github.com/limscoder/grpc-athrottle
- Owner: limscoder
- License: apache-2.0
- Created: 2018-10-07T16:30:10.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2018-10-15T16:43:50.000Z (over 7 years ago)
- Last Synced: 2025-01-12T11:49:14.759Z (about 1 year ago)
- Language: Go
- Homepage:
- Size: 11.7 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# grpc-athrottle
Adaptive throttling for golang gRPC clients
gRPC interceptor that throttles outgoing connections based on trailing accept rate as described in [Google SRE Book](https://landing.google.com/sre/book/chapters/handling-overload.html).
## usage
```go
import (
throttle "github.com/limscoder/grpc-athrottle"
"google.golang.org/grpc"
)
func connect() {
opts := throttle.ThrottleOptions{
// sliding window for the past n minutes, used to calculate throttle ratio
WindowDuration: 3 * time.Minute,
// number of requests that must be present within WindowDuration before throttling
MinRequestCount: 25,
// ratio of requests/successes that must be met before throttling begins
// refered to as "K" in the Google SRE book
MaxRatio: 2.,
// callback function for counter events,
// useful for logging throttle events and/or metrics
Callback: func(CounterEvent) {},
}
conn, err := grpc.Dial(address, grpc.WithInsecure(), grpc.WithUnaryInterceptor(
throttle.NewClientUnaryInterceptor(&opts)))
}
```
example usage with event logger: https://github.com/limscoder/kubetastic/blob/master/cmd/randoui/main.go