dqvs45976 2019-03-15 14:05
浏览 101
已采纳

如何在Go中实现简单的流量整形

I am trying as an exercise to implement simple traffic shaper in go.

The API is: push(int): puts an int in the shaper out(): outputs 1 or more int(s) from the shaper.

push is called by the clients and the rate can't be controlled. out is called roughly every 1ms and can output 1 or more ints and is trying to maintain a constant out put rate of r ints per 1s but can output more if the intrnal buffer of the shaper is in danger of getting filled up. However the output should be as uniform as possible. For example: Out: 1 1 2 2 2 1 is better than Out: 1 1 5 1 1

since the second example is bursty (there's an output of 5 ints).

I have an idea of how to do this using leaky bucket algorithm.

My question: How to implement in Go that output is called semi-regularly roughly at 1ms ticks?

  • 写回答

1条回答 默认 最新

  • dsc56927 2019-03-15 19:27
    关注

    How to implement in Go that output is called semi-regularly roughly at 1ms ticks?

    Use the standard time.Ticker, configured to flush output every 1 millisecond.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 yolov8边框坐标
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么
  • ¥15 banner广告展示设置多少时间不怎么会消耗用户价值
  • ¥16 mybatis的代理对象无法通过@Autowired装填
  • ¥15 可见光定位matlab仿真
  • ¥15 arduino 四自由度机械臂