A container for my databases

Playing with databases in containers.


Who doesn’t like containers? Anyone doesn’t like to have most of the benefits of virtual machines with much, much less overhead?

They’ve been around since forever (anyone still remember chroot?) but only in recent years their popularity boomed, mainly due to cloud computing, I’m sure.

I’ve been running databases in docker for a while now. I was curious about other alternatives, so I did a bit of benchmarking.

Containers tested

Docker

It’s not a coincidence that Docker appeared around the same time container technology began its popularity rise.

It’s main selling point is its easy of use and an enormous ecosystem of ready to use images.

rkt

rkt is an interesting alternative to Docker. rkt has the same features and can even download and run Docker images.

rkt takes security-minded approach to containers. It supports signed images, a feature sorely needed in Docker.

LXC

LXC (linux containers) is the technology that was originally behind docker.

LXC just runs containers, that’s it. We can regain some of Docker-like features if we mix in some additional components like LXD (hypervisor and management) and LXCFS (an overlay filesystem). For snapshots we can use LVM or an snapshot-capable filesystem.

systemd-spawn

systemd-nspawn is “chroot on steroids”. A much simpler tool, it doesn’t provide any form of image management. It requires a more DIY approach, we need to set up everything by ourselves.

nspawn, unlike chroot, does provide a network virtualization and it’s capable of fully booting a linux container.

It’s a lightweight alternative worth considering if your linux distribution uses systemd.

Benchmarks

The databases tested are MariaDB 10.3.12 and Postgres 11.1.

I’m using sysbench’s OLTP read+write test, using 1 and 10 threads. I’ve run each test 3 times, 20 minutes each test. The graph consists of the max, median and min average TPS values.

Single thread

Figure 1: MariaDB - 1 thread

Figure 1: MariaDB - 1 thread

Figure 2: PostgreSQL - 1 thread

Figure 2: PostgreSQL - 1 thread

I was surprised that docker did so well, I wouldn’t have been shocked if it were the worst, but it performed best.

10 Threads

How does performance change with a higher thread count?

Figure 3: MariaDB - 10 threads

Figure 3: MariaDB - 10 threads

Figure 4: PostgreSQL - 10 threads

Figure 4: PostgreSQL - 10 threads

A higher load tends to even out things. Docker suffers a bit more with MariaDB. All in all it doesn’t look like there is much of a speed difference between container types.

That’s it

Hope you enjoyed this post. It was fun for me playing around with containers.

Given that there is not a clear winner yet, I think I’ll stick with Docker for now.

Have a good one.

Tomas


See also