Benchmark databases in Docker: MySQL, PostgreSQL, SQL Server
By: Petr Jahoda
Tags: MySQL, Benchmark, Docker, Postgres, Sql Server

Benchmark databases in Docker: MySQL, PostgreSQL, SQL Server

Why should you do database benchmark?

I was a long-term SQL Server user. But it was not my decision to use SQL Server. I was young and had to listen older colleagues. If they said, SQL Server is the best, then it was.

Then I was a long-term MySQL user. But it was not my decision to use MySQL. I was older, but my other colleagues were much more experienced. If they said, MySQL is the best, then it was.

I never searched for any other opinions, because at that time, I was learning. How can I argue with my much more experienced colleagues?

Then I found MariaDB. Then I found Percona. And I asked my much more experienced colleagues something like: “Hey, what are they? Why are they?”. The answer was almost always something like: “MySQL is the best, I know MySQL. Do you suppose to use something else? Do you want to break things?”

And of course, I didn’t want to break things.

But curiosity is my second name, so I decided to find out, which database should suits the best for our application. And I hit the perfect time, because Docker was arriving to the scene, so it looked like, it would be easy to start my work.

So, to answer the question “Why should you do database benchmark?” is to say: “Because it turns YOU into that much more experienced colleague”.

How I did my database benchmark?

To benchmark a database can be a tricky thing. Just look around the internet. There are different benchmarks, measuring different things, sometimes parameters, that do not tell you anything meaningful.

From my perspective, I see database as something, that exactly matches its name. A base for a data. Nothing more. So no application logic in database. Database should hold the data and make two main operations as quick as possible: read and write.

I see read as something not changing the database and write as something changing the database. For me, delete and update are both subset of write.

Also, when I read from database, I tend to make my selects as simple as possible. I do not use joins on joins on joins on joins. I prefer reading multiple different tables as quick as possible, and then process the data outside the database. But I use max , avg , min and sum a lot. I use simple things a lot and complicated things as little as possible.

From my perspective, my ideal database should be calmly humming all the time, serving reads and writes as quickly, as possible. Nothing more.

When I decided to make my benchmark I was hunting three things:

Which database has the fastest writes Which database has the fastest reads Which database has the smallest memory and CPU usage

Preparation

As I did my benchmark two years ago in 2019 (resulted into switching to PostgreSQL), it will be wise to repeat it now, in 2021.

At first, we need to run all databases, we want to benchmark. We can run all the major databases in Docker with commands (and a little bit more information) from this article, but you find all those commands below.

I added some popular forks from all three major engine families.

Postgres engine family: PostgreSQL, TimescaleDB

MySQL engine family: MySQL, MariaDB, Percona

SQL Server engine family: SQL Server