Is it possible to limit the server's global or channel bandwidth using Netty?
I can set explicit read or write rate limits via GlobalChannelTrafficShapingHandler, but I'm trying to limit the server's global bandwidth to roughly half the available bandwidth. So if the server can upload at 8MB/s, I want to limit the uploads to roughly 4MB/s. And I want the server to adjust as available bandwidth changes; so if the server's upload rate decreases to 5MB/s (perhaps due to network utilization by other apps), then I want to limit the rate to apprx 2.5MB/s.
I've been playing with overriding AbstractTrafficShapingHandler.submitWrite() and adding a delay based on the duration since the previous call, but the logic seems fragile and unreliable.
Any ideas on how to intelligently approach this problem?
Have you considered using GlobalTrafficShapingHandler
and periodically letting it go full throttle to figure out the server max bandwidth and then limiting it to half of that?
I would periodically do the following (on a schedule, maybe 1 second out of every minute)
setReadLimit
setWriteLimit
to the max you would ever allowGlobalTrafficShapingHandler
s TrafficCounter
(via public trafficCounter()
) to reset the count by calling resetCumulativeTime
TrafficCounter.configure(long)
GlobalTrafficShapingHandler
to use half of the bandwidth you just calculatedI think the above should give you what you want without being too fragile.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With