I would like to be able to limit bandwidth of tcp connection in my code. This question has some clues, but not exactly what I want. I have tried to hack src code of go standard lib (net/tcp package), using similar approach, but failed. My main idea is to somehow write data from syscall to internal buffer slowly, thus making OS to drop tcp packets.
1条回答 默认 最新
- douwang9650 2018-01-27 13:18关注
As said in the comment, the easiest way is to do it at the OS level with wondershaper tool. If you look at 'wondershaper' script, it uses '/sbin/tc' command from the 'iproute2' package. I understand that it is not exactly what you would like to do, but you can go at a lower level by executing 'tc' commands in your source code with os.exec(). Implementing your own "traffic control" algorithm is maybe too much work and not necessary for your goal.
解决 无用评论 打赏 举报