1

I have an application that consumes a lot of network traffic. I used psutil to measure network activity in kbits with the following code:

old_value = psutil.net_io_counters(nowrap=True).bytes_sent + psutil.net_io_counters(nowrap=True).bytes_recv
sleep(1)

while True:
    new_value = psutil.net_io_counters(nowrap=True).bytes_sent + psutil.net_io_counters(nowrap=True).bytes_recv
    net_usage = (new_value - old_value)/1024.0 * 8
    old_value = new_value

    print(net_usage)
    sleep(1)

Before that, I limited the network to 10Mbps using the following command:

ethtool -s eth0 speed 10 duplex full autoneg off

I expected to see a list of numbers close to 10000kbit, instead, the numbers were clearly limited by a number close to ~6380:

Network usage, after limiting to 10Mbit

Is there an explanation for this? I.e. why the limit was not 10000, even though the numbers were clearly limited by the ethtool? Is my measuring code or expectations somehow flawed?

EDIT: My application uses the network mainly for uploading the data. Is it possible that the limit of 10Mbit is split between upload and download directions by ethtool and upload is assigned only 6.4 Mbit?

Larrax
  • 87
  • 1
  • 8
  • What is your network bandwidth? Are you sure the local NIC is the limiting factor? – MisterMiyagi Jul 13 '20 at 12:46
  • It was a communication on a local 1Gbps network. Without the ethtool command, the usage was clearly higher. The ~6k limit was present only after the ethtool command was applied. – Larrax Jul 13 '20 at 12:57

2 Answers2

0

You should put "time.sleep(1)" between old value and new value.

Giampaolo Rodolà
  • 12,488
  • 6
  • 68
  • 60
  • That would be wrong. If you think about how the loop works, the difference is always computed between values 1 second apart. – Larrax Jul 14 '20 at 10:26
0

This was probably a network issue, which I solved by setting the "autoneg" to "on". Therefore, the correct command was:

ethtool -s eth0 speed 10 duplex full autoneg on

With this, I see list of values close to 10000.

Anyway, any explanation for this behavior would still be appreciated.

Larrax
  • 87
  • 1
  • 8