在多线程环境中限制连接组的速率
当我想在多线程环境中限制套接字组的传输速率时,我想知道哪种速率限制算法最有效。目前我正在使用单线程设计,它依赖于 选择器类。在这个系统中限制传输速率非常简单,但我正在考虑使用工作线程来处理每个 IO 操作。当然,如果可能的话,我希望避免同步开销。
I am wondering which is the most efficient rate limiting algorithm when I want to limit the transfer rate of a socket group in a multithreaded environment. Currently I am using a single threaded design which relies on the Selector class. It is pretty simple to limit the transfer rate in this system, but I am considering using worker threads to handle every IO operations. Of course I would like to avoid synchronization overhead if it is possible.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
每次对 Socket/SocketChannel 读/写的调用都涉及许多同步。您可以限制写入数据的速率,但尝试限制读取数据的速率不太可能产生太大效果,它只会确定发生多少缓冲,而不是发送数据的速率。
值得注意的是,同步成本高达 2 微秒。一旦限制发送的数据,您将延迟更大的数字,例如 100 us 到 100,000 us。
我建议你实现一些简单且有效的东西,然后再考虑优化它。
Every call to a Socket/SocketChannel read/write involve a number of synchronizations. You can limit the rate at which you write data, but attempting to limit the rate you read data is unlikely to have much effect, it will just determine how much buffering occurs rather than the rate data is sent.
Its worth noting that synchronization cost up to 2 micro-seconds. As soon as to limit the data sent you will delaying by a much larger figure say 100 us to 100,000 us.
I suggest you implement something which is simple and works and worry about optimising it later.