Ashley
Ashley

Reputation: 659

TCP packet sizing at application level for max throughput

At application level, say using java, how much do I have to worry about the actual TCP packet size? So, for example, I am trying to write an application that should send data over TCP socket's outputstream, do I have to always keep into account the size of the data written to the stream? Since java sockets are streaming sockets, I havent actually considered the size of data units, but the TSO (TCP Segmentation offload) is "turned on" for the OS/NIC, then I can write a 64KB data slice or MSS to the outputstream and thus try to save the precious CPU time of slicing the data to less than 1500 bytes (< MTU). How effective could my programming be, in terms of being able to take care of this dynamically? I know we can get NetworkInterface.getMTU() to determine OS/NIC MTU size, but not sure how it can help that. So, I can say that overall, I am a bit confused on how to maximize my throughput of byte writing to the outputstream.

Upvotes: 2

Views: 2499

Answers (2)

user207421
user207421

Reputation: 310860

TCP buffers, paces, decides segment sizes etc behind the scenes for you. There is nothing you can do to help except write as much as possible as fast as possible, and use a large socket send buffer at the sender and a large socket receive buffer at the receiver.

Upvotes: 0

Peter Lawrey
Peter Lawrey

Reputation: 533472

how much do I have to worry about the actual TCP packet size?

Almost never. You can setNoTcpDelay(true); but this rarely makes a difference.

So, for example, I am trying to write an application that should send data over TCP socket's outputstream, do I have to always keep into account the size of the data written to the stream?

I doubt it. If you have a 1 Gb connection or slower, you will have trouble writing a program so inefficient it can't use this bandwidth.

Since java sockets are streaming sockets, I havent actually considered the size of data units, but the TSO (TCP Segmentation offload) is "turned on" for the OS/NIC, then I can write a 64KB data slice or MSS to the outputstream and thus try to save the precious CPU time of slicing the data to less than 1500 bytes (< MTU).

I don't see how give most decent network adapter support TCP offloading.

How effective could my programming be, in terms of being able to take care of this dynamically?

Java doesn't support it in any case.

I know we can get NetworkInterface.getMTU() to determine OS/NIC MTU size, but not sure how it can help that.

Me neither.

So, I can say that overall, I am a bit confused on how to maximize my throughput of byte writing to the outputstream.

The most significant change you can make in Java is to use NIO. I suggest blocking NIO as this is the simplest change from NIO. If you use direct ByteBuffers this can save redundant memory copies from Java to native memory.

Do you know you have a problem using the maximum bandwidth of your network? If you haven't measured this is the cause of your problem, it's just a guess.

Upvotes: 2

Related Questions