How can I benchmark TCP and UDP using C? How can I benchmark TCP and UDP using C? unix unix

How can I benchmark TCP and UDP using C?


Question 1: You probably can find existing test cases with some use of Google. But if there are special situations you need to deal with, then it probably makes sense to write your own so that you take that into account.

Question 2: Maybe there is an official definition of "latency" in terms of network operations, but I think what is really important is the round trip cost. So I would not divide by 2. The total round trip cost is what the user (client) experiences. That will be the latency they see.

Question 3: I think your plan of using differing packet sizes is good for measuring the throughput. There is another SO question related to this. I posted an answer to that question and provided some numbers from my own testing of UDP versus TCP. Those might be of interest as a "sanity" checkpoint.

Ah - I forgot one thing I was going to mention. If you write a really simple test case with UDP, it might be somewhat unrealistic. If you use UDP directly, you will need to add your own error handling, packet verification, etc. That will add cost. Ultimately, we find that UDP is faster in most situations for us because we have tailored it to our own use. But it certainly requires a LOT more code to get everything working correctly.


There already exists a program called ttcp which test TCP and UDP performance:

DESCRIPTION

Ttcp times the transmission and reception of data between two systems using the UDP or TCP protocols.

It does not calculate latency, but you can take a look at the source code of that program to examine how it does other calculations. And you can also use that as either client or server in case you do not want to write both yourself.

Update: Other similar TCP test programs

as well as related programs


You may want to look at tools that already exist for this type of thing. Maybe D-ITG or iperf combined with tcpdump or wireshark? Unless the intent is to learn more about socket programming itself.