Forwarder is a production-ready, fast MITM proxy with PAC support. It's suitable for debugging, intercepting and manipulating HTTP traffic. It's used as a core component of Sauce Labs Sauce Connect Proxy.
The io.Copy implementation is synchronous. It reads and writes in a for loop on a single thread. When read and write costs are high (i.e. using net.Conn) it cal halve the performance.
We could easily optimize that by prefetching data while writing.
Now
R R R
W W W
Desired
RRR
WWW
Implementation idea:
Reader uses two buffers 128K each
If buffer capacity goes below 32kiB the buffers are switched
Reader sends buffer subslices to writer over a channel, channel capacity is 1
Writer writes what it gets over the channel as in io.Copy
Note use subslice with capacity [start:len:cap] syntax.
The io.Copy implementation is synchronous. It reads and writes in a for loop on a single thread. When read and write costs are high (i.e. using net.Conn) it cal halve the performance.
We could easily optimize that by prefetching data while writing.
Now
Desired
Implementation idea:
Note use subslice with capacity
[start:len:cap]
syntax.