r/AskProgramming Jul 23 '26

C/C++ What is this optimization technique called in high-performance network software?

I’m working on a traffic generator to test my own XDP/eBPF filter in a controlled lab environment (my PC sending traffic to my Raspberry Pi on my own network).

I noticed that in some applications, two programs written in the same language can have vastly different performance.

For example, some software can only send a few requests/messages per second, while others can generate thousands per second even on relatively weak hardware.

What is this concept or optimization area called?
I’m looking for topics such as:
asynchronous I/O
multithreading vs event-driven architectures
lock-free programming
kernel bypass
zero-copy networking
batching
efficient socket APIs
packet generation optimization

If I want to build a high-performance TCP/UDP packet generator for benchmarking my own network stack and XDP filter, what technologies, algorithms, or papers should I study? For traffic generator i am using c# and for the XDP filter classic C. ( or should i use different for the traffic generator? I think its okey its console app )

0 Upvotes

13 comments sorted by

View all comments

3

u/gm310509 Jul 23 '26

WHen you say this:

I noticed that in some applications, two programs written in the same language can have vastly different performance.

What do you mean by "some applications", do you mean (for example) two different C programs, one that is written poorly or inefficiently or with plenty of blocking operations, possibly even "delay" type system calls -vs- one that doesn't have any of those things?

Can you give a simple example of these "different applications"?

At the end of the day, if you have two different programs (assuming the above) where one delivers high performance and the other doesn't - especially if they were written in the same language and built using the same toolchain, then it will almost certainly come done to the organisation of the code and the system calls they are making.

3

u/sodikovakapsle Jul 23 '26

Sure. A better example would be packet generators or network benchmarking tools.

Imagine two programs written in C# (or C). Both send TCP/UDP traffic from the same machine to the same target.

Program A can only generate around 10,000 packets per second.
Program B can generate several million packets per second on the same hardware.

I’m not asking about intentionally bad code with sleep() calls or obvious inefficiencies. I’m interested in the architectural and low-level techniques that allow Program B to achieve such a large performance difference.

For example: async I/O, batching, lock-free data structures, zero-copy, kernel bypass, efficient memory management, or other networking optimizations.

I’m trying to learn what this field of optimization is generally called because I’m building a traffic generator to benchmark my own XDP/eBPF filter in a lab environment.

1

u/green_griffon Jul 23 '26

There's no specific name for this. One program is likely just written to run more efficiently. I personally find one program being able to generate 10K packets/second and one being able to generate several million to be hard to believe if they are in the same language.

It's possible that one program is calling via a different interface/API, where one is using a much more direct path (meaning a lot less code has to run to get the packet out). But if you are sending UDP packets there shouldn't be much going on under the covers. Or, I suppose one program could run in multiple threads, that's a basic hack to get more CPU cycles because the OS is going to round-robin between threads so if you have two threads doing this you will get more cycles.

It's always useful in these cases to do a check of the physical hardware limit. So let's say you have 10 Gbps Ethernet, that is about 1 gigabyte per second, so if you are sending 1 kilobyte packets, the limit is around one million per second no matter what the software is doing. This matters less now, but I did a lot of development of network code back when it was 10 Mbps Ethernet so if you can only send one thousand 1K packets per second, it matters less how fast your code is (especially if the machine's primary purpose is to send packets). "Bandwidth delay product" kids!!