Thursday, February 26, 2015

Simple experiment to illustrate bufferbloat using two Linux machines

 Tools required: iptraf, ethtool, nttcp

1. Connect two machines with a direct ethernet cable. Label one machine A and the other B.
2. Force the ethernet speed to 10Mbps. This only needs to be done on one machine, the other will comply. Run this command on machine A:
        sudo ethtool -s eth0 speed 10 duplex full
3. Start nttcp on machine B
        nttcp -i
4. Start a ping from machine A to machine B and leave it running as you follow the rest of the steps. Notice the RTT value.
5. Start the nttcp session from machine A
        nttcp -t -D -n2048000 <machine A ip address>
6. Notice the RTT value increase. This is because buffer is building up at the tx queue for the interface on machine A. This is not the NIC ring buffer, it's the tx queue inside the kernel.
7. On machine A, open IPTraf and monitor the TCP flow speed of the connection.
8. Eliminate the tx queue and watch the RTT go down. Change it back and watch the RTT increase again. The flow speed doesn't change. The change in delay is just bufferbloat.
        sudo ifconfig eth0 txqueuelen 0
        sudo ifconfig eth0 txqueuelen 1000

--> Default txqueuelen value is 1000. It makes sense to eliminate txqueue or make it smaller on a host and network where contention is not likely and link speed is stable. However for fluctuating capacity links (such as wireless) a reasonably sized buffer is important to absorb the changes and achieve high utilization.

Check the following pages for more info. The steps above are extracted from the second post.
https://gettys.wordpress.com/what-is-bufferbloat-anyway/
http://wiki.linuxwall.info/doku.php/en:ressources:dossiers:networking:traffic_control

Friday, December 20, 2013

Concurrently sharing a Linux terminal across different ssh sessions or terminal emulators

How can I share a terminal session in two different terminal emulator windows or ssh sessions?

Why?
I run pianobar on an old laptop to listen to music from Pandora. I usually start pianobar through ssh from another laptop to be able to control it from the other room. However when I am moving between rooms, I have to terminate pianobar across the ssh session and start it locally on the old laptop if I want to control it.

How?
I have been using the "screen" command for some time to maintain sessions across different ssh sessions. It turns out "screen" has a multi-user mode.

To share a terminal, you just follow these steps:
  1. Start "screen" through an ssh session or a local terminal emulator.
  2. Go to the another terminal session and start "screen -x". You will need to specify the tty to attach to if you have started more than one. 
  3. Voila ! These two sessions are identical. You can follow the progress of a command or control it simultaneously from both sessions.
Final note: This requires "screen" to be compiled with multi-user mode support which I have found to be the case for Mac OS X 10.9 and Debian 5. I assume it's enabled by default but just in case.

Back to listening to pianobar now :)

Thursday, December 12, 2013

Building 32-bit ports on 64-bit Mac OS X using Macports

I a big fan of C# and I also happen to be a Mac OS X user. I wanted to build some project that uses EmguCV on Monodevelop. EmguCV is the C# wrapper for the OpenCV library.

Mono is currently 32-bit only so I tried to build OpenCV in 32-bit as well. It turns out OpenCV needs to link to ffmpeg which was built as a 64-bit library by Macports. I got the following error during linking:

ld: warning: ignoring file /opt/local/lib/libavcodec.dylib, file was built for x86_64 which is not the architecture being linked (i386): /opt/local/lib/libavcodec.dylib
After some messing around and reading on Macports documentation, it turns out you can build universal packages (by default universal = i386 + x86_64 but you can change it in macports.conf) by adding one parameter to the port command:
sudo port install ffmpeg +universal
 This rebuilt ffmpeg to include both x86_64 and i386 and solved my problem.

Hope this helps someone else out there.