Showing posts with label ethernet. Show all posts
Showing posts with label ethernet. Show all posts

Saturday, June 11, 2011

Reduce transmit queue length

As enough pieces have fallen into place to make actual predictions, (and the quarry’s spoor noticed), I decided to perform more deliberate experiments to see if I could capture more henchmen of the mastermind. I did.
I’ll start to provide puzzle pieces I’ve discovered here regularly, so you can help with the conviction of the criminal and repair of the damage they have caused. Today’s simple experiments only involve your router’s switch. We’ll do some experiments on the wireless side of the router next.
Conclusion: something stinks in operating system’s network stacks. Linux is often worst, with two different but related problems, followed by Mac OSX; Microsoft Windows manages to obfuscate much of it’s problems, but also demonstrably suffers. After mitigation, Linux may be able to perform much better than either.

Experiment Setup

If your home router has a gigabit switch (a few do, these days), you’ll want to find a 100 meg switch to perform this experiment with. You may be able to achieve the same effect using “ethtool” and setting your ethernet link speed to 100Mbps. I presume your machines all have gigabit network interfaces; most have for a while.
Hook up your laptop directly to the switch’s ethernet port. Hook a second machine up to a second port to act as your server. In case one or the other of your computers is wimpy, let’s use nttcp for our testing. The point here is to transfer data over the link as fast as you can.
Install “nttcp“. Run “nttcp -i” on the machine you designate as your server.

Experiment 1a:

Run “nttcp -t -D -n2048000 server & ping-n server” on your laptop.
What do you observe after, say, 20 seconds? Is this what you would expect, given that a packet of 1500 bytes takes only .13 milliseconds to pass through a 100Mbps switch?

Experiment 1b:

Issue the command “ifconfig eth0“; look at the txqueuelen value. On my laptop, it is set by Linux to 1000.
Is the latency constant, or variable, as you manipulate the txqueuelen parameter?
Set the txqueuelen parameter to half of its initial size (e.g. “ifconfig eth0 txqueuelen 500“. What happens to the observed latency?
What do you observe? How does it differ from Experiment 1a?
Try playing with different values of txqueuelen while continuing to observe the ping latency. On most current hardware, you can set the txqueuelen to zero; on some older hardware, you may have problems if you do so.

Experiment 1c:

Install the command “ethtool” if you don’t have it installed.
Set the txqueuelen to the minimum operating value (0 on my laptop) for this experiment.
Execute the command “ethtool -g” and note the current hardware settings for your ethernet interface. Note that not all device drivers support this interface. On my laptop, the ring size is 256 by default.
Run “nttcp -t -D -n2048000 server & ping -n server” on your laptop. What do you observe? Why?
Try playing with different values for the ring parameters (e.g. “ethtool -G eth0 tx 64” , and observe the ping latency. Your hardware will probably have some limit minimum ring size that you cannot go below. On my laptop, this is 64 entries.
Is the latency constant, or variable? Why?

Experiment 1d:

Note that you can perform similar experiments on Mac OSX and Windows, both of which behave much better than Linux “out of the box” (though Linux is better than OSX once the transmit queue is truncated). Note that the details of the hardware matter here: you should use the same hardware, or hardware using the same ethernet chip if possible.
For extra credit, explain why Windows default behavior is so much better than either Linux or OSX on 100Mbps Ethernet. (Hint: try setting the transmit speed on the Windows machine to 10Mbps; and search Windows technical notes about multimedia playing). Do you now believe Microsoft’s explanations? Or is there a different explanation given these experiments that makes more sense?

http://www.bufferbloat.net/projects/bloat/wiki/Linux_Tips

Friday, September 10, 2010

Ethernet Frame Calculations

Ethernet Frame Calculations

This page contains some example calculations for the operation of an Ethernet LAN.
Example 1: Calculate the maximum frame rate of a node on an Ethernet LAN.

The minimum frame payload is 46 Bytes (dictated by the slot time of the Ethernet LAN architecture). The maximum frame rate is achieved by a single transmitting node which does not therefore suffer any collisions. This implies a frame consisting of 72 Bytes (see table above) with a 9.6 µs inter-frame gap (corresponding to 12 Bytes at 10 Mbps). The total utilised period (measured in bits) corresponds to 84 Bytes.

Frame Part Minimum Size Frame
Inter Frame Gap (9.6µs) 12 Bytes
MAC Preamble (+ SFD) 8 Bytes
MAC Destination Address 6 Bytes
MAC Source Address 6 Bytes
MAC Type (or Length) 2 Bytes
Payload (Network PDU) 46 Bytes
Check Sequence (CRC) 4 Bytes
Total Frame Physical Size 84 Bytes


Calculation of number of bit periods occupied by smallest size of Ethernet frame

The maximum number of frames per second is:

Ethernet Data Rate (bits per second) / Total Frame Physical Size (bits)

= 10 000 0000 / (84 x 8 )

= 14 880 frames per second.

In practice, this exceeds the forwarding capacity of many routers and bridges (typically 1000's of frames per second). This is however not usually a concern, since most Ethernet networks carry packets with a range of lengths and usually transmit a significant proportion of maximum sized frames (the maximum rate of transmission of maximum sized frames is only 812 frames per second). If the forwarding capacity is momentarilly exceeded due to a large number of small frames, the bridge/router will simply discard the excess frames which it can not process (this is allowed, since Ethernet provides only a best effort link layer service).
Example 2: Calculate the maximum throughput of the link layer service provided by Ethernet

The maximum frame payload is 1500 Bytes, this will offer the highest throughput, when the frames are transmitted by only one node on the network (i.e. there are no collisions) To calculate the throughput provided by the link layer, one must first calculate the maximum frame rate for this size of frame. Frame Part Maximum Size Frame
Inter Frame Gap (9.6µs) 12 Bytes
MAC Preamble (+ SFD) 8 Bytes
MAC Destination Address 6 Bytes
MAC Source Address 6 Bytes
MAC Type (or Length) 2 Bytes
Payload (Network PDU) 1500 Bytes
Check Sequence (CRC) 4 Bytes
Total Frame Physical Size 1538 Bytes


Calculation of number of bit periods occupied by largest size of Ethernet frame

The largest frame consists of 1526 Bytes (see table above) with a 9.6 µs inter-frame gap (corresponding to 12 Bytes at 10 Mbps). The total utilised period (measured in bits) therefore corresponds to1538 Bytes.

The maximum frame rate is:

Ethernet Data Rate (bits per second) / Total Frame Physical Size (bits)

= 812.74 frames per second

The link layer throughput (i.e. number of payload bits transferred per second) is:

Frame Rate x Size of Frame Payload (bits)

= 812.74 x (1500 x 8)

= 9 752 880 bps.

This represents a throughput efficiency of 97.5 %.
Example 3: One node transmits 100 Byte frames at 10 frames per second, another transmits 1000 Byte frames at 2 frames per second, calculate the utilisation of the Ethernet LAN.

The utilisation is the percentage of time the physical link is transmitting data. This calculation will assume that the transmissions do not collide. (Thisd may need to be reviewed if the utilisation is greater than about 10%).

The maximum frame payload is 1500 Bytes, this will offer the highest throughput. To calculate the throughput provided by the link layer, one must first calculate the maximum frame rate for this size of frame. Frame Part Frame 1 Frame 2
Inter Frame Gap (9.6µs) 12 Bytes 12 Bytes
MAC Preamble (+ SFD) 8 Bytes 8 Bytes
MAC Destination Address 6 Bytes 6 Bytes
MAC Source Address 6 Bytes 6 Bytes
MAC Type (or Length) 2 Bytes 2 Bytes
Payload (Network PDU) 100 Bytes 1000 Bytes
Check Sequence (CRC) 4 Bytes 4 Bytes
Total Frame Physical Size 138 Bytes 1038 Bytes


Calculation of number of bit periods occupied by largest size of Ethernet frame

The two frames occupy respectively a period corresponding to 138 Bytes and 1038 Bytes (including the 9.6 µs inter-frame gap). The total number of bits which are utilised in 1 second are therefore be:

(Frame Size 1 x Frame Rate 1) + (Frame Size 2 x Frame Rate 2)

= (138 x 8 x 10) + (1038 x 8 x 2)

= 27648 bits

This represents a utilisation of :

(27648 / 10 000 0000) x 100

= 0.28 %

(N.B. 0.28 % << 10%, therefore it was permissable to neglect the effect of collisions.)

Courtesy : http://www.erg.abdn.ac.uk/users/gorry/course/lan-pages/enet-calc.html