Skip to content

Instantly share code, notes, and snippets.

@antoinerg
Last active August 29, 2015 14:25
Show Gist options
  • Save antoinerg/040d35cf08ae68cae14e to your computer and use it in GitHub Desktop.
Save antoinerg/040d35cf08ae68cae14e to your computer and use it in GitHub Desktop.
Docker run overhead

Docker run overhead

Measures the average execution time (N=20) of a Ruby program printing out "Hello, world!" launched via "docker run", "docker exec" and without container management overhead.

  • time docker run ruby:latest ruby -e "puts 'Hello, world!'"

  • time docker exec $CID ruby -e ...

  • docker run ruby:latest /bin/bash -c "time ruby -e ..."

Why?

I wanted to know how slow it would be to spawn a new Docker container to run a CGI script. Unfortunately, "docker run" takes almost 0.5s to complete, whereas "docker exec" takes 0.1s. If container management is not taking into account, it runs in less than 0.05s.

#!/bin/bash
N=20
average_time () {
i=1
while [ "$i" -le $N ];
do eval $1
i=$(($i+1))
done 2>&1 | grep ^real | sed -e s/.*m// | awk '{sum +=$1} END {print sum / NR "s"}';
}
echo "docker run"
average_time "time docker run ruby:latest ruby -e \"puts 'Hello, world!'\""
echo "docker exec"
CID=$(docker run -d ruby:latest /bin/sh -c "sleep 100")
average_time "time docker exec $CID ruby -e \"puts 'Hello, world!'\""
echo "no docker overhead"
average_time "docker run -it ruby:latest /bin/bash -c \"time ruby -e \"puts 'Hello, world!'\"\""
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment