Adventures in Go and File Handles | Performance Magic

Ramblings from a Sysadmin

June 22, 2014

Adventures in Go and File Handles

I’ve been mucking a bit with go recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with go recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`

``I’ve been mucking a bit with go recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with go recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`

``

But this wouldn’t use all the inodes. Why not?

Let’s add some debug:

```I’ve been mucking a bit with go recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with go recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`

``I’ve been mucking a bit with go recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with go recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`

``

But this wouldn’t use all the inodes. Why not?

Let’s add some debug:

  
````I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
```I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
  
Ahh there we go, we are running out of open file descriptors. Of course.
  
So the final code becomes:
  
`````I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
```I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
``` 
  
````I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
```I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
``` 
  

Ahh there we go, we are running out of open file descriptors. Of course.

So the final code becomes:

  
and we can compile it like so:
  
``````I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
```I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
``` 
  
````I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
```I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
``` 
  
```` 
  
Ahh there we go, we are running out of open file descriptors. Of course.
  
So the final code becomes:
  
`````I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
```I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
``` 
  
````I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
```I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

``I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

`I’ve been mucking a bit with [go][1] recently. Nothing special, just doing some small problems that I needed to solve.

At work, I have built up a challenge for new candidates.  One of them is the old trick of using all the inodes on a file-system.  This is a quick one to rule out the ones who have real world experience.

So I wrote some code:

` 

`` 

But this wouldn't use all the inodes. Why not?
  
Let's add some debug:
  
``` 
  
```` 
  
Ahh there we go, we are running out of open file descriptors. Of course.
  
So the final code becomes:
  

and we can compile it like so:

``````

© Greg Cockburn