Mar 22

Consul for Raspberry Pi is Alive

This version is forked from http://github.com/progrium/docker-consul and runs on the Raspberry Pi. Thanks to Jeff Lindsay for all his hard work. I am merely standing on the shoulders of giants.

This initial version is a bit largish — ~500Mb; I think it’s mostly due to needing a go build environment. I think I can use dockerize or another tool to get it down much further. Barring that, I should be able to take the output from the compile and then build a container from a stripped down image.

But… it works. And that’s a great first start.

And the web user interface is working, too….

Mar 22

Docker Cleanup

After a time, Docker containers and images build up and can eat disk space. Failed docker build invocations can leave a lot of artifacts behind.

The following commands can help. Many of them say ‘not all containers could be removed’; this has to do with the header from docker ps. Usually this can be ignored.

Caveat: Docker images cannot be removed if they are in use by a container.

Remove Ended Containers Which Match a Pattern

Remove All Containers Which Match a Pattern

Remove Images Matching a Pattern

Remove Incomplete Images

Remove all containers except those currently running

Mar 21

Swarming Raspberry Pi – Part 1

Here’s the first in a series of building a robust docker swarm of raspberry pi hosts. This installment goes through installing the Pi(s), modifiying the Docker Daemon config, and starting up a test to verify that everyone can join the cluster.

The cluster which I am using consists of

  • Raspberry Pi B+ x 5
  • Raspberry Pi 2 B x 5

In order to verify that the cluster is working properly, there should be ten (10) members, five (5) of which have 4 cores.

Obtaining the OS and Setup

The wonderful folks at Hypriot have produced a raspberry image based on Raspbian, but with Docker 1.5.0. The image and instructions can be found at Heavily ARMed after major upgrade: Raspberry Pi with Docker 1.5.0 – Docker Pirates ARMed with explosive stuff.

Note: The image resizes itself to fit the card upon the first boot and then reboots. This takes a little bit (minutes at most). Just don’t be surprised when it reboots.

Hostnames

In order for this to work properly, the hosts need a unique name. It’s sometimes possible to configure DHCP to do this, but I went ahead and edited /etc/hostname myself since I wanted the most portability possible.

Like all good sysadmins, I am lazy. Doing the same thing over and over is boring. Besides, that’s what computers are for. So I wrote a script to make copies of the image and then edit the hostnames. Once that’s done I can then proceed to write the images to the SD cards.

The following script takes one argument, the location of the image you wish to modify — this should work for more than just Hypriot; it should work for just about any Rasberry Pi image. At present, it creates 10 instances and the NAME starts with apis-rpi- — you will likely want to change those. I may make the file a bit more generic at some point.

The Pi instances all need network connectivity which can be seen by the swarm manager; a switch works well. You can either physically assign IP addresses or use DHCP.

Updating Docker

In order for swarm instances to communicate, the docker daemon needs to be bound to a TCP port.

  1. sudo service docker stop
  2. Edit /etc/default/docker (vi is installed on the image) and replace DOCKER_OPTS="--storage-driver=overlay -D" with DOCKER_OPTS="--storage-driver=overlay -D -H tcp://0.0.0.0:2375 -H unix:///var/run/docker.sock"
  3. sudo service docker restart

Docker should be running once again. I’ve left the unix socket enabled so that the “default” behaviour still works.

WARNING There are some security issues with this; a port is opened to anyone who can reach the host at which point they can start containers, etc.. Other than using this for play/testing on a private network, TLS needs to be configured.

To verify that the daemon is running with both the port and the socket, do docker info and docker -H 127.0.0.1:2375. You should see something like the following for both:

Obtaining Swarm

I’ve created a Raspberry Pi docker container for swarm. To install it, you can simply pull nimblestratus/rpi-swarm. With more than a couple Raspberry Pis, this can be a bit tedious. clusterssh makes this a lot easier — it allows you to type in the same commands to multiple servers at once.

Discovery Service

In future installments I’ll be getting a different discovery service running, but for this test the default works.

Starting the Nodes

On each node, execute the following: (this assumes that you’re using wired ethernet; for wireless you’ll need to change eth0 to most likely wlan0)

It can be helpful to verify that the agent has started with docker ps. If you don’t see it running, then there’s a problem somewhere.

Starting the Manager

I’m running the manager on my laptop; consequently I’m using the swarm container instead of nimblestratus/rpi-swarm:

Once this comes back, let’s check out the swarm:

Ok, let’s test…

You can find the url like this:

At this point there isn’t any service discovery; that’s for the next increment….

Pop the URL into a browser and you should see:

swarm-result

It's Alive!

It’s Alive!

Next time… setting up a discovery service…

Mar 20

Nifty Things for Week Ending 20 March

Welcome to the Vernal Equinox. Hopefully this means that Fimbulwinter is averted once more!

Blast from the Past

Data Visualization

Data

Monitoring

3D Printing

Raspberry Pi

Docker

Programming

  • Introducing Tweet a Program — Some truly amazing programs, written in the space of a tweet. Admittedly, they are leveraging Wolfram Alpha (such as one to plot known shipwrecks in the Atlantic Ocean), but they are still amazing.

Tools

Geekiness

Philosophy

Site of the Week

This week I’d like to send a shout-out to One Thing Well. It advertises itself as

One Thing Well isn’t just about software that adheres strictly to the Unix philosophy, though; instead it aims to showcase the applications, tools and utilities that—you guessed it— do one thing well, with or without a graphical user interface, on any platform, be they commercial, free or open source.

Everyday there are about three tools added to the site. Some are Apple focused, others unix/linux, and others are generic. However, there’s usually something for everyone. It’s on my list of sites to visit every day!

Mar 19

Pi on a Pi Followup

The particular algorithm used in calculating Pi is one which converges to Pi as you add terms; it’s not calculating out to a number of digits, although I might try that one as well at some point.

Here’s the output from a run; it’s interesting how it gets closer and closer, but… Another interesting thing is how, say, in the run with 10K terms it is off by a digit in the middle and subsequent ones are correct — 3.14149265359 instead of 3.141592653589.

Mar 17

Lost in a Maze of Twisty Little Java Classes: How often is “infinite scalability” and extensibility really needed?

But look, you found the notice, didn’t you?

Yes yes I did. It was on display at the bottom of a locked filing cabinet stuck in a disused lavatory with a sign on the door saying Beware of the Leopard. — Mr. Prosser and Arthur Dent, The Hitchhiker’s Guide to the Galaxy

While digging through someone’s code to find proof of an observed behaviour, I was caught up in the maze that is Java inheritance. I really believe that many Java API’s suffer from a serious rejection of YAGNI. When I have to trace through fifty gazillion (yes, it really seemed like there were that many!) classes, interfaces, factories, and abstract classes just to find a particular flavour of a HTTP client (which, by the way, is deprecated) in order to discover that it attempts by default to reuse a connection, I feel as though I’ve entered the depths of Vogon Bureaucracy.

“With simplicity, portability, scalability, and legacy integration, the J2EE platform is the platform for enterprise solutions.” — Sun Microsystems

“With great scalability comes great complexity” — Not Stan Lee

“With great complexity comes great consultant fees” — Yoyodyne Consulting

As it turns out, the calling class of the class in question is not threadsafe. This does not lend itself to scalability.

I think part of the frustration for me here is one of philosophy. I do find it ironic that these complex systems grew out of a company which was an early champion of UNIX. I sense in the rush to be “enterprise”, Java lost sight of the UNIX Philosophy.

… UNIX programs do quite trivial things in isolation, but, combined with other programs, become general and useful tools. — Kernighan and Pike, The UNIX Programming Environment

So instead of something like this:

513uh-JhKzL._SY450_

we get:

ultimate-swiss-army-knife1-640x533

Going back to the original point, all of this is in an effort to provide a “Full implementation of all HTTP methods (GET, POST, PUT, DELETE, HEAD, OPTIONS, and TRACE) in an extensible OO framework.” How often is extensibility really needed for something as fundamental as HTTP? When was the last time a new method was added to the specification? Is a framework really needed for something as fundamental as HTTP? I can understand creating an abstraction layer, but in the course of this archeological quest, I found myself digging through layer after layer in order to reach the core. Inanna only had to pass through seven gates; I investigated over a score of Java classes! Each layer adding its own complexity and overhead. Function calls are not free, nor are layers of abstraction.

Yagni, the Development Assistant

Yagni, the Development Assistant

Il semble que la perfection soit atteinte non quand il n’y a plus rien à ajouter, mais quand il n’y a plus rien à retrancher. — Antoine de Saint Exupéry

A good discussion of complexity and whether or not it is truly needed can be found in Neal Ford’s Emergent Design and Evolutionary Architecture.

Mar 17

Mounting Images on Linux

This is mostly for reference, but may be of use to others.

In order to mount an image (in order to be able to edit it), you can execute the following code:

This is useful for editing one or more files in an image without needing to copy it to a device or card.

Mar 17

Pi on a Pi for Pi Day

EDIT: The metrics below are skewed. Not all JVM’s are created equal. For updated metrics on the Pi, please see JVM Choice Matters (a lot!).

What better thing to do on Pi Day than to calculate Pi? I figured while I’m at it, I might as well do some performance testing of the Raspberry Pi 2 B. I’m using the following for my comparisons:

Host Description Bits
Pi 2B Quad Core, 900 MHz ARM 7, 1G ram 32
Pi B+ Single core, 700 MHz ARM 6, 512M ram 32
Argentum Quad core AMD A10-5757M at 1400MHz (variable clocking, can be higher), 12G ram 64
Nimbus Eight core AMD FX-8320 running at 3515MHz, 32G ram 64

I’m using a variant of the code at Calculate Pi Inefficiently — I’ve edited it to allow to specify the number of terms on the commandline:

I am using the following script to calculate:

I’m running the script seven (7) times in order to let the host warm up some.

I don’t expect there to be any garbage collections, but just in case ;-). One difference between the original version and the current is the IO — the version I’m running here prints a lot less (and runs much more quickly as a result).

Results (Real time Median in seconds)

Number of Terms Argentum Nimbus Pi 2B Pi B+
1000 0.124 0.075 0.706 1.42
10000 0.131 0.075 0.729 1.426
100000 0.144 0.081 0.664 1.512
1000000 0.143 0.088 0.726 2.195
10000000 0.1995 0.1145 1.5165 9.217
100000000 0.5355000000000001 0.3835 8.2345 79.5255
1000000000 3.8884999999999996 3.062 74.68549999999999 781.9705

Interpreting the results, I observe the following

  • It looks as though the majority of the time for terms up to 1000000 is the JVM initialization. Around 100000000 the 64 bit hosts start to be more efficient — they do not have the huge jump in elapsed time.
  • Garbage Collection is not invoked
  • Since the code is single threaded, the extra cores shouldn’t make much of a difference.
  • The Pi 2B is running Oracle Java 1.8 from the Raspbian distribution; the other three are running OpenJDK 1.7.0_75. I may re-run on Pi B+ using Oracle Java 1.8; I halfway expect an improvement in performance there. Until 10000000, the Pi 2 is running at ~2-3x the performance of the Pi B+. After that it goes to ~9x performance.
  • I think that the HotSpot compiler is kicking in around 100000000 which could explain the radical divergence in runtime.
  • I think that the floating point support for the ARM is not as good as for AMD64 — additionally ARM 6 and ARM 7 have different floating point capabilities.

This was a fun little diversion for Pi Day!

Mar 13

Nifty Things for Week Ending 13 March

AT LAST, SIR TERRY, WE MUST WALK TOGETHER

Philosophy & Lessons Learned

Monitoring

Blast from the Past

Raspberry Pi

Docker

Programming

Mar 11

Pi Metrix

I really like that go can produce static executables which do not require any dynamic libraries; this is especially useful for sysadmin tools.

Metrix is one such tool — it is a single executable which is able to gather a variety of metrics and send them to different aggregators (by default it is sent to STDOUT):

I compiled the binary using hypriot’s rpi-golang container; and followed the directions in Metrix’ Github repo, adding in commands as needed. I will likely create a container to automate these steps. One quirk, if anyone wishes to try building — I used the last “release” version of metrix; there were issues doing a git clone and trying to build.

This has been tested on both HypriotOS and Raspbian, on a Pi B+ and Pi 2B.

If you try to run this within a Docker container your results will be mixed at best due to Docker’s isolation.

To use, download from the link below and place on a Pi, then do the following:

Download: metrix.bz2

Older posts «

» Newer posts