如何在go中实现简单的流量整形
How to implement simple traffic shaping in go
我正在尝试在 go 中实现简单的流量整形器。
API是:
push(int):将一个 int 放入整形器中
out(): 从整形器输出 1 个或多个 int(s)。
推送是客户端调用的,速率无法控制。
out 大约每 1 毫秒调用一次,可以输出 1 个或多个整数,并试图保持每 1 秒 r 个整数的恒定输出速率,但如果整形器的内部缓冲区有填满的危险,则可以输出更多。但是,输出应尽可能统一。例如:
输出:1 1 2 2 2 1 优于
输出:1 1 5 1 1
因为第二个例子是突发的(有 5 个整数的输出)。
我知道如何使用漏桶算法来做到这一点。
我的问题:
如何在 Go 中实现大约在 1ms ticks 时半定期调用输出?
How to implement in Go that output is called semi-regularly roughly at 1ms ticks?
使用标准time.Ticker, configured to flush output every 1 millisecond。
我正在尝试在 go 中实现简单的流量整形器。
API是: push(int):将一个 int 放入整形器中 out(): 从整形器输出 1 个或多个 int(s)。
推送是客户端调用的,速率无法控制。 out 大约每 1 毫秒调用一次,可以输出 1 个或多个整数,并试图保持每 1 秒 r 个整数的恒定输出速率,但如果整形器的内部缓冲区有填满的危险,则可以输出更多。但是,输出应尽可能统一。例如: 输出:1 1 2 2 2 1 优于 输出:1 1 5 1 1
因为第二个例子是突发的(有 5 个整数的输出)。
我知道如何使用漏桶算法来做到这一点。
我的问题: 如何在 Go 中实现大约在 1ms ticks 时半定期调用输出?
How to implement in Go that output is called semi-regularly roughly at 1ms ticks?
使用标准time.Ticker, configured to flush output every 1 millisecond。