Network performance

Recently I had some network issues at work with lower than normal speeds, narrowed it down to the D-Link switch. I rebooted it and things seemed to be back to normal. Then at home I was hitting some similar performance issues both wired and wireless.

First thing was to verify that the wall port was giving me the correct speeds, then through the switch. Bingo, speeds were dropping. Ensured I was using Cat6 cables, found one cable that just didn’t want to connect, threw it out. Then I used the IT Crowd mantra and tried turning it off and on again. Speeds were back to normal.

Rebooted the downstairs switch as well, used iperf to measure the wired performance, 935 Mbits/sec.

$ iperf -p 2222 -c
Client connecting to, TCP port 2222
TCP window size: 85.0 KByte (default)
[  3] local port 35464 connected with port 2222
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  1.09 GBytes   935 Mbits/sec
$ iperf -p 2222 -c
Client connecting to, TCP port 2222
TCP window size: 85.0 KByte (default)
[  3] local port 35470 connected with port 2222
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec  1.09 GBytes   935 Mbits/sec

So wired performance fixed. Next up was the wireless. I was getting 8.3MBps/66.4 Mbps, second run 7.0MBps/56Mbps. Reading the dd-wrt docs it reads:

You must use HT40 channel width & WPA2 AES when encrypting your wireless connection, otherwise the router will fallback to 802.11a/g speeds since WPA2 AES is a mandatory requirement of 802.11n specification as WPA2 AES is the only approved encryption method in the 802.11n standard.

Security was already WPA2 AES, but the Channel Width was set to the dd-wrt default of Full (20MHz). I changed it to Wide HT40 (40 MHz). Rebooted the router, and gave the tests another go.

First I used dd and nc then iperf. The dd reported 13.7MBps/109.6Mbps.

$ dd if=/dev/zero bs=1024K count=512 | nc -v 2222
Ncat: Version 7.12 ( )
Ncat: Connected to
512+0 records in
512+0 records out
536870912 bytes (537 MB, 512 MiB) copied, 39.1152 s, 13.7 MB/s
Ncat: 536870912 bytes sent, 0 bytes received in 39.32 seconds.

iperf results in similar results if only slightly slower.

$ iperf -p 2222 -c
Client connecting to, TCP port 2222
TCP window size: 85.0 KByte (default)
[  3] local port 52358 connected with port 2222
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   110 MBytes  92.2 Mbits/sec
$ iperf -p 2222 -c
Client connecting to, TCP port 2222
TCP window size: 85.0 KByte (default)
[  3] local port 52360 connected with port 2222
[ ID] Interval       Transfer     Bandwidth
[  3]  0.0-10.0 sec   102 MBytes  85.0 Mbits/sec

Two runs resulted in 92.2Mbps and 85.0Mbps. The three runs average out to 95.6Mbps wireless.

While not bad wireless performance, I was hoping to get closer to the 300Mbps product rating.

Network Hardware:


  • Lenovo T460S
  • homebuilt server, MSI 785GTM-E45 motherboard with gigabit port

More Go links

Cobra is both a library for creating powerful modern CLI applications as well as a program to generate applications and command files.

Viper is a complete configuration solution for go applications including 12 factor apps. It is designed to work within an application, and can handle all types of configuration needs and formats.

pflag is a drop-in replacement for Go’s flag package, implementing POSIX/GNU-style –flags.

7 common mistakes in Go and when to avoid them

Go! Speed Racer Go!

I finally reached a point where I could start running the go version of sm-photo-tool. I finished the option validation for the list command. While I was testing it I noticed how much faster the Go version felt. Here are the python vs Go versions of the commands.

The python version took 80 milliseconds to run the validation of parameters and print out the error message. This is expected, you have to start the python VM (and if not precompiled, the code would need to be compiled). In this test, the code was precompiled.

$ time sm-photo-tool list invalid blah
ERROR: valid options are ['album', 'galleries']

real	0m0.080s
user	0m0.059s
sys	0m0.021s

Ok so how fast is the Go version? My guess was half the time, 40ms. I was way off. Try 6ms. SIX! That’s amazing to do the exact same amount of work.

$ time ./sm-photo-tool list invalid blah
ERROR: valid options are [album galleries]

real	0m0.006s
user	0m0.001s
sys	0m0.005s

Control your caps

On all of my computers I use gnome-tweak-tool to remap CAPSLOCK to CTRL. But there are times when I’m working in a virtual machine that doesn’t have that setup so I need to go back to old school methods.

If you’re on a box just run this from any terminal:

setxkbmap -option ctrl:nocaps

That avoids trying to kill a program with C which usually doesn’t work🙂

Go resources

Mostly a note to myself, but others might find them useful.

Use of Go articles

Here are some articles of companies using Go

Go After 2 years in production
Building Web Apps with Go
Companies using Go
Go at Heroku
Handling five billion sessions a day – in real time
Open Sourcing Our Go Libraries
The March towards Go
How we went from 30 Servers to 2: Go
OpenShift 3 and Go: Teaching Old Dogs New Tricks

Node.js to Go

I found quite a few articles where folks were using Node.js and moved to Go.

A closer look at Go and Node.JS
Making the Switch
from Node.js to Golang

Farewell Node.js
From Node.js to Go, Why One Startup Made The Switch
Node.js vs Golang: Battle of the Next-Gen Languags

Go web frameworks

Since web apps are the thing these days, it’s a good idea to look at web frameworks for Go.

Gorilla web toolkit
Beego Quickstart
Go kit – distributed programming toolkit
Revel web framework
IRIS Web Framework
A Survey of 5 Go Web Frameworks
Making a RESTful JSON API in Go
Key/value logs in Go
How We Moved Our API From Ruby to Go and Saved Our Sanity

If you have a framework, article, or comparison you’d like to share, leave me a comment.

Private Golang, reporting for duty

Many modern programming languages have a mechanism for controlling the visibility of members and methods. Most of the languages use keywords like private and public.

Java and C++ use public, private, and protected. Ruby also uses keywords: private, and protected.

Python on the other hand uses convention to control visibility, prefixing your methods with _ or __. Even then it’s more of a suggestion in Python as you can call it anyway. There is nothing to prevent it from actually being called from other code. It’s an understanding among Python developers that if there is an underscore you shouldn’t call it.

Go also has no keyword to control visibility. What no keyword? There has to be something? Maybe it uses _ like python? Nope that won’t do anything. Then what would Go use to control visibility? Go uses a very simple syntax, capitalization.

CAPITALIZATION? What? Yes, that’s correct. A simple capital letter makes the member or method public. Lowercase member, methods are private.

// GetName is a public method of User struct
func (u *User) GetName() string {

// nickName is a private method of User struct
func (u *User) nickName() {
  // do something

The same logic applies to members. Given the following example struct, Foo is public and bar is private:

type Example struct {
  Foo string
  bar string

So if you want to make your Go methods or members private, just start them with a lowercase letter. Want others to use it, capitalize it.

Constructors? Not in Go

If you’ve used any object-oriented language in the past decade, C++, Java, Python, Ruby, C#, you are used to defining a class and each having its own constructor. Here’s a sample in Java and Python, respectively.

public class User {
    private String username;

    public User(String name) {
        username = name
    // ...
class User(object):
    def __init__(self, name):
        self.username = name

Previously, I wrote about Go having no class. Go uses structs. I covered how to write a struct and add methods to it. But now how do you create one? Let’s continue with the user example from above. In Go, we’d create a user struct:

type User struct {
    username string

Ok that was easy. But what about the constructor? Go doesn’t use constructors as you are accustomed. Go will basically initialize everything to their ZERO value, i.e. ints are 0, strings are empty. structs will have their members set to their respective zero values. Let’s look at the User example above.

u := User{}

This creates the User u instance with the username set to the zero value for strings, “”.

Sometimes the zero value isn’t enough. Sometimes you want to pass in values you know you need for that particular instance. That’s pretty simple too, again let’s look at the User struct:

u : User{"joeuser"}

This will set the username to joeuser. What if the struct had more attributes? You can either specify all the values in order or by name and value. Let’s add the age attribute to the User struct.

type User struct {
    username string
    age int

Initialize both by passing all the values:

u := User{"joeuser", 30}

Alternatively, we can initialize the username and leave the age to be it’s default zero value.

u := User{username: "joeuser"}

But what about something more complex than a two field User object? Since Go doesn’t have constructors, you have to create what I like call a “pseudo constructor”, basically a method that returns the initialized struct.

func NewUser(name string, age int) *User {
    // do whatever work you need to do
    // calculate fields, set defaults, etc.
    if age < 18 {
        fmt.Println("user is a minor")
    return &User{name, age}

The name can be anything, I like to use NewStructName as a convention to make it easier to see what they are for.

While Go doesn’t have constructors, there are still three ways you can “construct” objects:

  • using the zero values
  • using the {} to pass in the values to the struct
  • creating a construction function to build the struct

Now “Go” and construct some objects.

Golang: search an array

Go is a pretty awesome language, typed, C-like, fast. I’m porting one of my python applications to Go. Searching an array isn’t as simple as it is in python though.

In Python you can use in or not in:

if self.args[1] not in self.valid_options:
    print("ERROR: valid options are %s" % self.valid_options)

Go doesn’t have membership operators, so you have to search the string for what you want. Then you get the index and see if it actually exists:

i := sort.SearchStrings(lc.valid_options, args[1])
if i >= len(lc.valid_options) ||
  i < len(lc.valid_options) && lc.valid_options[i] != args[1] {

  fmt.Printf("ERROR: valid options are %v\n", lc.valid_options)

Pretty Print directory of .json files

I had a bunch of compressed json files that I needed to pretty print to make them more readable. This little snippet will create a new pretty printed json file prefixed with pp:

ls *.json | xargs -I {} sh -c "cat {} | python -mjson.tool > pp{}"

Instead of having to look at files that look like this:

{ "attributes": [ { "name": "type", "value": "PKT" }, { "name": "arch", "value": "x86_64,x86" }, { "name": "name", "value": "Awesome OS" } ], "dependentProductIds": [], "href": "/products/00", "id": "00", "multiplier": 1, "name": "Awesome OS", "productContent": [ { "content": { "arches": null, "contentUrl": "/content/6/$releasever/$basearch/debug", "gpgUrl": "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-awesome-os", "id": "FFFF", "label": "awesome-os-debug-rpms", "metadataExpire": 86400, "modifiedProductIds": [ "0A" ], "name": "Awesome OS (Debug RPMs)", "releaseVer": null, "requiredTags": "awesome-os-server", "type": "yum", "vendor": "Candlepin" }, "enabled": false } ] }

You get a bunch of files that look like this:

    "attributes": [
            "name": "type",
            "value": "PKT"
            "name": "arch",
            "value": "x86_64,x86"
            "name": "name",
            "value": "Awesome OS"
    "dependentProductIds": [],
    "href": "/products/00",
    "id": "00",
    "multiplier": 1,
    "name": "Awesome OS",
    "productContent": [
            "content": {
                "arches": null,
                "contentUrl": "/content/6/$releasever/$basearch/debug",
                "gpgUrl": "file:///etc/pki/rpm-gpg/RPM-GPG-KEY-awesome-os",
                "id": "FFFF",
                "label": "awesome-os-debug-rpms",
                "metadataExpire": 86400,
                "modifiedProductIds": [
                "name": "Awesome OS (Debug RPMs)",
                "releaseVer": null,
                "requiredTags": "awesome-os-server",
                "type": "yum",
                "vendor": "Candlepin"
            "enabled": false