Mohamad-Jaafar NEHME
Mohamad-Jaafar NEHME

Reputation: 1215

Detecting maximum throughput of my network using C++

My application aims to detect the network throughput. Despite the C++ code, I am seeking for a reliable theory of throttling my network which returns exact value of maximum accepted baudrate. Indeed, I could write the code later.

After checking several ideas from internet I didn't find which suits my case.

I tried to send data as much as possible using TCP/IP and then check the baudrate on each sending of 10MB. Please find here the pseudo code for my algorithm:

while (send(...)){
    if (tempSendBytes > 10Mb)
        if (baudrate > predefinedThreshold)
            usleep(calculateNeededTime());
    tempSendBytes += sentBytes;
    }

But, when the predefinedThreshold is acheived, buffers full up and my program get stuck without returning any error. As a matter of fact, checking the baudrate on each sent message will decrease my bandwidth to its minimum. So, I preferred to check each 10MB.

PS: There are no other technical problems in my code neither a memory leak. In addition, my program runs normally (sending and receiving data 100%) if I decrease predefinedThreshold.

My question: Is there a way to detect the maximum bandwidth (on both loopback and real network) without buffers overflow neither getting stucked?

Upvotes: 1

Views: 3606

Answers (1)

mshish
mshish

Reputation: 346

Yes, you can detect maximum throughput on both loopback and real interface. The real interface may require a TCP server running remotely with sufficient bandwidth to provide an accurate estimate of max throughput.

If you are strictly looking for theoretical, you may be able to run the test on the real interface the same way you run it on localhost with the server bound to the real interface's IP and the client running on the same computer. I'm not sure though what your OS's networking stack will do to this traffic but it should treat it like it was coming off box.

A lot of factors contribute to max theoretical throughput for TCP. TCP MTU, OS send buffer, OS receive buffer, etc. Wikipedia has a good high level overview, but it sounds like you may have already read it. http://en.wikipedia.org/wiki/Measuring_network_throughput You might also find this TCP tuning overview helpful, http://en.wikipedia.org/wiki/TCP_tuning

IPerf is commonly used to accurately measure bandwidth and the techniques it uses are rather comprehensive. It is written in C++ and its code base may be a good starting point for you. https://github.com/esnet/iperf

I know none of this provides an exact discussion of the theory, but hopefully helps clarify some things.

Upvotes: 2

Related Questions