Search code examples
javaperformancesocketsniosocketchannel

What are the factors affecting the speed in sending large amount of data in SocketChannel?


Can someone tell me what are the specific factors affecting the speed in sending large amount of data in the SocketChannel? For example is the byte allocation affects the speed?


Solution

  • The main limiting factors, in order, are:

    1. Network bandwidth, by which I mean the bandwidth of the slowest part of the path between the peers.
    2. Size of the socket receive buffer at the receiver. If it is less than the bandwidth-delay product of the path, you won't be able to utilize the full available bandwidth.
    3. The speed at which you send. Contrary to a suggestion in the comments, you should send as much as possible at a time, and repeat as rapidly as you can, assuming blocking mode. In non-blocking mode it is considerably more complex, but if bandwidth utilization is your goal you're better off using blocking mode. You're probably also better off using java.net rather than NIO too.