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.

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

报告相同问题?

悬赏问题

  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入
  • ¥40 使用MATLAB解答线性代数问题
  • ¥15 COCOS的问题COCOS的问题
  • ¥15 FPGA-SRIO初始化失败
  • ¥15 MapReduce实现倒排索引失败