Network optimalizations

This pull request contains:
* The commits from #2016 and #2017
* Fixes and memory improvements for those
* A change from per-connection to per-message send buffers

This should improve network latency and memory usage.