开发者

Rate limiting a connection group in multithreaded environment

开发者 https://www.devze.com 2023-02-09 02:10 出处:网络
I am wondering w开发者_如何学编程hich 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 sing

I am wondering w开发者_如何学编程hich 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号