Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Why TCP echo benchmark so much faster than UDP echo benchmark? #36

Open
nicodemuz-zz opened this issue Nov 11, 2020 · 6 comments

Comments

@nicodemuz-zz
Copy link

From your examples in the Readme, the TCP benchmar pushes on the order 40 times more messages per second than UDP.
Even SSL is on the order 10x faster than UDP.

When I compiled and ran it myself I got over 100 times more messages with TCP than what I got with UDP.

Why TCP and SSL echo benchmarks so much faster than UDP echo benchmark?

@ne0phyte70
Copy link

Yes. I have also found this to be very surprising. Can the developer please comment? TIA

@chronoxor
Copy link
Owner

chronoxor commented Jan 8, 2021

In TCP a stream buffer is used to put all outgoing messages together and send them in a batch with full IP packet. Batch mode is more effective.

In UDP a small datagram is send each time in a new IP packet which is not full.

It's just a kind of scenario. In other scenarios UDP could be more effective (e.g. broadcasting).

@ne0phyte70
Copy link

ne0phyte70 commented Jan 8, 2021 via email

@chronoxor
Copy link
Owner

Yes, but in those time for us TCP/SSL sessions were more important, so I add analogical UDP benchmark just for brief comparison.
I'll think it over, maybe in near future we'll create benchmarking tests special for UDP.

@ne0phyte70
Copy link

ne0phyte70 commented Jan 9, 2021 via email

@nicodemuz-zz
Copy link
Author

nicodemuz-zz commented Jan 18, 2021

With UDP packets fairly large, and with the benefit of a smaller header, the free´d capacity for more "packets" in batch mode doesn't explain a factor 100 in performance difference unless we go really close to 0 in packet size (payload size), or unless it is CPU limited and not throughput limited.

For 1 Gbps throughput limit, which should not be limit with test in same PC, a UDP packet totalling ~120 bytes including IP and UDP header should result in 1 million packets per second as each is ~1000 bits in size. But I am not getting close to those figures with UDP.

So is it a CPU constraint from CPU overhead at each packet transmission? I never did check the CPU usage...

By the way:
Appropriate send and receive buffer sizes on TCP could even things out, and disabling Nagle algorithm would also adress the stream vs datagram issues making UDP and TCP implementation more comparable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants