Dubbo-go provides users with built-in flow-limiting rejection logic, and supports users to define the required flow-limiting mechanism and rejection logic according to their own business scenarios.
Under normal circumstances, no flow limit is set. When the user configures the flow limit logic and parameters on the server side, it will
go-server/conf/dubbogo.yaml: Configure current limiting parameters
dubbo:
protocols:
triple:
name: tri
port: 20000
provider:
services:
GreeterProvider:
interface: "" # read from pb
tps.limiter: "method-service"
tps.limit.strategy: "slidingWindow"
tps.limit.rejected.handler: "default"
tps.limit.interval: 1000
tps.limit.rate: 3
Parameter Description:
According to the above configuration, the server only allows the current interface to be called three times within one second.
Set the client’s request logic to request five times per second, and calculate the success rate.
go-client/cmd/client.go
func main() {
config. SetConsumerService(grpcGreeterImpl)
if err := config.Load(); err != nil {
panic(err)
}
logger.Info("start to test dubbo")
req := &api.HelloRequest{
Name: "Laurence",
}
for {
goodCount := 0
badCount := 0
for {
time.Sleep(time.Millisecond*200)
reply, _ := grpcGreeterImpl.SayHello(context.Background(), req)
if reply.Name == "" {
badCount++
} else {
goodCount++
}
if badCount + goodCount == 5{
break
}
}
logger.Infof("Success rate = %v\n", float64(goodCount)/float64(goodCount + badCount))
}
}
It can be seen in the log that the request success rate is 0.6, and only three requests are allowed to be executed per second.
INFO cmd/client.go:62 Success rate = 0.6
INFO cmd/client.go:62 Success rate = 0.6
INFO cmd/client.go:62 Success rate = 0.6
You can see the rejection information in the server log:
ERROR tps/filter.go:84 The invocation was rejected due to over the limiter limitation...