TL;DR: get me to the diagram
» Introduction
Recently, I read about CockroachDB which is a so-called NewSQL database, trying to combine the benefits of relational SQL databases and NoSQL databases. Since a few months, I’m dealing with Cassandra as a distributed database, which is also my first real usage of NoSQL databases. In my opinion, it adds quite some complexity to the development process for the sake of scalability or availability. So, I was very enthusiastic about CockroachDB and thought it would be cool to have a database combining the best of two worlds. I checked the Docker image and immediately tested converting a side project which was using PostgreSQL to CockroachDB, which went quite nice as it only uses very simple SQL statements.
So, what about the performance? I found this issue on GitHub, with a simple benchmark, comparing PostgreSQL and CockroachDB. The result shows, PostgreSQL is 2-3x faster, but on the other hand, you can easily scale CockroachDB (according to the devs).
I liked the idea of this simple benchmark and wanted to check how other databases perform in this apple and oranges comparison, that’s why I wrote dbbench. It’s a simple Go application. Thank’s to the work of several DB driver authors, it can be used with SQLite, MySQL, PostgreSQL, Cassandra, MS SQL, and compatible databases (e.g. MariaDB, TiDB, CockroachDB, ScyllaDB).
For each of these databases, there are simple INSERT
, SELECT
, UPDATE
, and DELETE
queries, which are run in a loop for a specific amount of iterations.
A goal for the future is to add more, database specific benchmarks, e.g. testing the performance of queries with relations to other tables.
But enough of the introduction, you want to see the results of this unfair benchmark which is totally not comparable and I’m even running the databases in Docker on the same host as the benchmark tool, and you shouldn’t use the results to make any conclusions out of it? Here we go! Kids, don’t try this at home.
» SQLite vs PostgreSQL vs MySQL vs MariaDB vs CockroachDB vs Cassandra vs ScyllaDB
» Setup
Hardware
MacBook Pro 15" 2017
2,8 GHz Intel Core i7
16 GB RAM
Software
MacOS 10.14.2
dbbench 0.6.0 / 0.6.1
|
|
|
|
» SQLite
SQLite is the only database which is not running in a Docker container in this comparison.
|
|
|
|
» Update SQLite
I got an email from Dwayne Richard Hipp, the architect and primary author of SQLite 😮
He was curious, how the results would look like if I set PRAGMA journal_mode=WAL
(documentation) instead of the default journal mode (DELETE
).
Initially, I didn’t want to tune the databases and just use the out of the box settings, as you can always tune something to exactly match the given benchmark. But he wrote, that this is almost the universal default mode, also on iOS and Android (and an email from such a big name in the database business is a great honour for me, suddenly I also feel a bit ashamed for this post, who would expect such a prominent visitor).
Here are the results with the WAL
mode enabled:
|
|
|
|
That’s crazy, isn’t it? SQLite became easily the fastest of all tested databases! Check the new diagram in the summary. \end update
» PostgreSQL
Starting the container
|
|
Printing the version
|
|
|
|
Running the benchmark
|
|
|
|
» MySQL
Starting the container
|
|
Printing the version
|
|
|
|
Running the benchmark
|
|
|
|
» MariaDB
Starting the container
|
|
Printing the version
|
|
|
|
Running the benchmark
|
|
|
|
» CockroachDB
Starting the container
|
|
Printing the version
|
|
|
|
Running the benchmark
|
|
|
|
» Cassandra
Because I made a mistake in the flag parsing, I had to release version 0.6.1 of dbbench
, which is used for the Cassandra and ScyllaDB benchmark. Furthermore, the built-in benchmark uses the IF [NOT] EXISTS
condition for the Cassandra/Scylla inserts, updates, deletes. Later I’ve seen that this is not yet supported for ScyllaDB and has a significant influence on the benchmark results. So, I decided to show both results here but only use the run without the condition in the resulting diagram at the end.
Starting the container
|
|
Printing the version
|
|
|
|
Running the benchmark
with IF [NOT] EXISTS
|
|
|
|
without IF [NOT] EXISTS
(used in the results diagram)
|
|
|
|
» ScyllaDB
As already explained in the Cassandra benchmark, ScyllaDB does not support Lightweight Transactions yet, which will result in an error. Thus, the IF [NOT] EXISTS
statements were removed in this benchmark.
Starting the container
|
|
Printing the version
|
|
|
|
Running the benchmark
|
|
|
|
» Benchmark Summary
The interesting parts I can see from the diagram is, that SQLite is the slowest in all benchmarks except the SELECT
where it is the fastest by distance.
PostgreSQL is probably the overall winner, only SQLite and MySQL are faster in the SELECT
benchmark.
About 9 years ago, MariaDB started as a fork of MySQL and the results show the have diverged quite heavily from a performance perspective, in favour of MariaDB – except for SELECT
.
ScyllaDB is faster than Cassandra but lacks features as explained in their sections.
Remember: The purpose of distributed databases is to run in a cluster, and not as done here, running only a single node!
» Summary Update
SQLite is the fastest when the default journal mode is set to Write-Ahead Logging
(last bar on the right side). See SQLite update.
When another database author writes me such a simple performance optimization, I will update this blog post again ;-) \end update
As described in the introduction, it’s a very unfair comparison. Even changing the hardware or the operating system might lead to completely different results. Furthermore, each database has it’s very specific advantages and disadvantages and can not only be compared by this simple benchmark. Maybe I’ve even manipulated the results, can you trust me? Inform yourself about the databases, their use cases, and draw your own conclusions!
The Following chapter will compare PostgreSQL on bare metal vs inside a Docker container.
» PostgreSQL: Metal vs Docker
Here is another benchmark which might make a bit more sense. Comparing the same database (PostgreSQL) on bare metal hardware vs. inside a Docker container.
» Setup
Hardware
Dell XPS 13 9370
Intel i7-8650U CPU @ 1.90GHz
16 GB RAM
Software
Kubuntu 18.10
dbbench version 0.6.0
» Metal Benchmark
Getting the version of the apt installed Postgres package with apt show postgresql-10
:
|
|
Running the benchmark:
|
|
|
|
» Docker Benchmark
The installed docker version:
|
|
|
|
Running the Docker image with the same version as the apt package.
|
|
Running the benchmark:
|
|
|
|
» Summary: Metal vs Docker
Docker adds quite some overhead in this particular setup. The bare metal benchmark runs are up to twice as fast for the INSERT
and DELETE
statements, and a third faster for the SELECT
statements. Only the UPDATE
statements are almost equally fast.