运行程序,我们看到第一批请求意料之中的大约每 200ms 处理一次。 |
$ go run rate-limiting.go request 1 2012-10-19 00:38:18.687438 +0000 UTC request 2 2012-10-19 00:38:18.887471 +0000 UTC request 3 2012-10-19 00:38:19.087238 +0000 UTC request 4 2012-10-19 00:38:19.287338 +0000 UTC request 5 2012-10-19 00:38:19.487331 +0000 UTC |
第二批请求,由于爆发(burstable)速率控制,我们直接连续处理了 3 个请求, 然后以大约每 200ms 一次的速度,处理了剩余的 2 个请求。 |
request 1 2012-10-19 00:38:20.487578 +0000 UTC request 2 2012-10-19 00:38:20.487645 +0000 UTC request 3 2012-10-19 00:38:20.487676 +0000 UTC request 4 2012-10-19 00:38:20.687483 +0000 UTC request 5 2012-10-19 00:38:20.887542 +0000 UTC |
下一个例子: 原子计数器