Skip to content

Latest commit

 

History

History
27 lines (17 loc) · 1.07 KB

File metadata and controls

27 lines (17 loc) · 1.07 KB

此工程为ru-rocker/gokit-playground的精简版.

在原文Micro-services Using go-kit: Rate Limiting中提到了两种可引用的令牌桶算法.

一种是Juju, 另一种说是go-kit内置的中间件.

在示例31.gokit-lorem-ratelimit中我只使用了golang/x/time/rate库, 而在本例中替换为了Juju, 作用相同.

超过流速的请求需要通过同时手动发起n个请求以查看各响应来比较, 本示例的上限是每秒3个请求.

先启动 server 服务

$ go run cmd/main.go
Starting server at port 8080

常规请求如下

$ curl -XPOST localhost:8080/lorem/sentence/1/20
{"message":"Concurrunt nota re dicam fias sim aut pecco die appetitum ea mortalitatis hi."}

如下使用多开终端进行模拟则可以看到限流效果.