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?
Asked
Active
Viewed 43 times
0
-
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 Answers
0
The main limiting factors, in order, are:
- Network bandwidth, by which I mean the bandwidth of the slowest part of the path between the peers.
- 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.
- 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
-
I'll agree their is no merit to the small packet sizes if you don't wish to show progress. – parabolah Jun 11 '16 at 05:21
-
@WinterRoberts So why did your comment state, or at least imply, the opposite? – user207421 Jun 11 '16 at 05:22
-
I made a random assumption that the progress would need to be tracked. – parabolah Jun 11 '16 at 05:24
-
I am using NIO and my goal is just to send the file as fast as I can so should I still send data as much as possible at a time? – Sumakumlawgaw Jun 11 '16 at 06:23