Tuesday, April 14, 2015

Command-line network speed testing

Is your web app slow? Is network bandwidth the problem? To diagnose the problem, begin by measuring the network bandwidth. Many users run the popular, web-based speedtest.net to capture speed performance data. This is a good solution if the X Window System is installed on the webserver. However, I have a Linux VPS server without an X graphical environment. Command line is the only viable way to perform a speed test on that server.

Power Linux users may want to use the iperf program to measure network bandwidth. To use iperf effectively, you need some basic knowledge of TCP/IP. In addition, you need to setup iperf to run on 2 machines: the 'client' and the 'server'. Yet, if you like the simplicity of using speedtest.net, you will be happy to know the following command-line tool to access speedtest.net servers.

speedtest-cli is a command-line Python program for testing Internet bandwidth using speedtest.net.

To download, and configure speedtest-cli, run the following commands:

$ wget -O speedtest-cli https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest_cli.py
$ chmod +x speedtest-cli

To capture the upload and download speeds of a local machine, you can simply run speedtest-cli without any parameter. The program automatically selects the 'best' speedtest.net server to test bidirectional transmission from the local machine.

$ ./speedtest-cli
Retrieving speedtest.net configuration...
Retrieving speedtest.net server list...
Testing from Telus Communications (108.180.199.xxx)...
Selecting best server based on latency...
Hosted by TELUS (Vancouver, BC) [3.73 km]: 34.739 ms
Testing download speed........................................
Download: 3.04 Mbit/s
Testing upload speed..................................................
Upload: 0.74 Mbit/s

In the above example, the program selected a test server located only 3 kilometers away from the local machine. That is not where most of my web visitors are from, namely the east coast of United States. The speed tests are more useful to me if the test server is located say in New York city.

You can designate a specific speedtest.net server in your speed testing. First, list the supported test servers.

$ ./speedtest-cli --list
...
982) Interserver, inc (Secaucus, NJ, United States) [3895.32 km]
2947) Atlantic Metro (New York City, NY, United States) [3903.25 km]
663) Optimum Online (New York City, NY, United States) [3903.25 km]
...

Then, select one from the list to specify as the test server, say 2947 (Atlantic Metro in New York City). To track network speed performance more consistently over time, you can designate the same test server in your subsequent tests.

$ ./speedtest-cli --server 2947
Retrieving speedtest.net configuration... Retrieving speedtest.net server list...
Testing from Telus Communications (108.180.199.xxx)...
Hosted by Atlantic Metro (New York City, NY) [3903.25 km]: 2629.346 ms
Testing download speed........................................
Download: 2.79 Mbit/s
Testing upload speed..................................................
Upload: 0.84 Mbit/s

For more information about speedtest-cli parameters, execute the command below.

$ ./speedtest.cli -h

No comments:

Post a Comment