title: Throttle server bandwidth by percentage using Netty
body: <p>Is it possible to limit the server's global or channel bandwidth using Netty?</p>
  
  <p>I can set explicit read or write rate limits via <a href="https://netty.io/4.1/api/io/netty/handler/traffic/GlobalChannelTrafficShapingHandler.html" rel="noreferrer">GlobalChannelTrafficShapingHandler</a>, 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.</p>
  
  <p>I've been playing with overriding <a href="https://netty.io/4.1/api/io/netty/handler/traffic/AbstractTrafficShapingHandler.html#submitWrite(io.netty.channel.ChannelHandlerContext,%20java.lang.Object,%20long,%20io.netty.channel.ChannelPromise)" rel="noreferrer">AbstractTrafficShapingHandler.submitWrite()</a> and adding a delay based on the duration since the previous call, but the logic seems fragile and unreliable.</p>
  
  <p>Any ideas on how to intelligently approach this problem?</p>