0

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?

  • Unless you have a 100Gbps network link then bandwidth _will_ be the limiting factor unless you use ridiculously small packet sizes that lead to large overhead waste. – Jim Garrison Jun 11 '16 at 04:58
  • @WinterRoberts That won't make the slightest improvement: on the contrary; not that I would describe 256kb as a 'small packet'. TCP will segmentize that, and IP will packetize it, into much smaller pieces anyway. – user207421 Jun 11 '16 at 05:18
  • This 256kb is in order to track the progress of downloads from a file-server. – parabolah Jun 11 '16 at 05:20
  • @WinterRoberts It will leave the NIC in frames of 1500 bytes at most. – user207421 Jun 11 '16 at 05:21
  • If you're sending a file via NIO [transferFrom](https://docs.oracle.com/javase/8/docs/api/java/nio/channels/FileChannel.html#transferTo-long-long-java.nio.channels.WritableByteChannel-)/To might be useful. – the8472 Jun 16 '16 at 00:29

1 Answers1

0

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.
user207421
  • 305,947
  • 44
  • 307
  • 483