Improve sleeping algorithm for rate limiting output streams

This pull request contains minor cleanup, and also a more accurate approach to sleeping when we determine that we need to throttle down the rate at which we are writing bytes. This is based on the way Kafka does it via their Throttler utility class. Previously we were always sleeping a static 5ms when throttling down.