-1

Background: Coding multiplayer for a simulator (Windows, .net), using peer-to-peer UDP transmission. This Q is not about advantages of UDP vs. TCP nor about packet headers. A related discussion to this Q is here.

Consider: I send a UDP packet with payload size X, where X can be anything between 1 and 500 bytes.

Q: Will there/can there, at any point during the transmission, temporarily be added slack bytes to the packet, ie. bytes in addition to needed headers/payload? For example, could it be that any participant in the transmission (Windows OS - NAT - internet - NAT - Windows OS) added bytes to fulfill a certain block size, so that these added bytes become a part of the transmission (even though cut off later on), and actually are transmitted, thus consuming processor (switch, server CPU) cycles?

(Reason for asking is how much effort to spend on composing/decomposing the packet, of course :-). Squeeze it to the last bit (small, more local CPU cycles) vs. allow the packet to be partially self-describing (bigger, less local CPU). Note that packet size is always less than the (nearest to me, that i know of) MTU, the normally-closer-to 1500 bytes)

Thx!

Community
  • 1
  • 1
Stormwind
  • 814
  • 5
  • 9

1 Answers1

1

The short answer is: Yes.

Take Ethernet as an example. For collision detection purposes, the minimum payload size of an Ethernet frame is 42 bytes. If payload (which includes application data, UDP and IP header, in this case) is less than that, a padding will be added to the Ethernet frame.

Also, as far as I know, the network card will to this job, not it's driver or the OS.

If you want to decide whether it is better to send small packets or wait and send bigger ones, take a look at Nagle's algorithm.

Here ou can see the Ethernet padding in practice: What are the 0 bytes at the end of an Ethernet frame in Wireshark?

Community
  • 1
  • 1
Jefferson
  • 529
  • 4
  • 9
  • Based on the answer above, would it be fair to assume that, for the part of the transmission where the packet is *"outside"* the two peers' computers, it does not matter if the payload is 1 or 42 bytes or anything in between, when focusing on transmission speed? This is roughly, as i realize there are numerous other things affecting, like trigger times and local housekeeping cycles. Nevertheless this is relevant, as one could for example "localize" benchmarking for the <42byte packet management and "exclude internet" as a constant . – Stormwind Mar 05 '16 at 01:17
  • Yes, for so small packets it doesn't matter, the packet will be at least 72 bytes long in the network, with or without enough data. To decide better, please also have these 2 points in mind: 1 - Processing time is much smaller than "networking time", so try to send as few packets as possible to for better performance. 2 - All those overheads inflate your data, so sending a lot of small packets actually means sending a huge lot of bytes when compared to sending a few bigger packets. Please don't forget to vote in the answer if I cleared your doubts. – Jefferson Mar 05 '16 at 12:14