This blog compares how PostgreSQL and MySQL handle millions of queries per second.

Anastasia:Can open source databases cope with millions of queries per second? Many open source advocates would answer “yes.” However, assertions aren’t enough for well-grounded proof. That’s why in this blog post, we share the benchmark testing results from Alexander Korotkov (CEO of Development, Postgres Professional) and Sveta Smirnova (Principal Technical Services Engineer, Percona). The comparative research of PostgreSQL 9.6 and MySQL 5.7 performance will be especially valuable for environments with multiple databases.

The idea behind this research is to provide an honest comparison for the two popular RDBMSs. Sveta and Alexander wanted to test the most recent versions of both MySQL and PostgreSQL with the same tool, under the same challenging workloads and using the same configuration parameters (where possible). However, because both PostgreSQL and MySQL ecosystems evolved independently, with standard testing tools (pgbench and SysBench) used for each database, it wasn’t an easy journey.

The task fell to database experts with years of hands-on experience. Sveta has worked as a Senior Principal Technical Support Engineer in the Bugs Verification Group of the MySQL Support Group at Oracle for more than eight years, and since 2015 has worked as a Principal Technical Services Engineer at Percona. Alexander Korotkov is a PostgreSQL major contributor, and the developer of a number PostgreSQL features – including the CREATE ACCESS METHOD command, generic WAL interface, lockfree Pin/UnpinBuffer, index-based search for regular expressions and much more. So we have a pretty decent cast for this particular play!

Sveta: Dimitri Kravtchuk regularly publishes detailed benchmarks for MySQL, so my main task wasn’t confirming that MySQL can do millions of queries per second. As our graphs will show, we’ve passed that mark already. As a Support Engineer, I often work with customers who have heterogeneous database environments in their shops, and want to know about the impact of migrating jobs from one database to another. So instead, I found the chance to work with the Postgres Professional company and identify both the strong and weak points of the two databases an excellent opportunity.

We wanted to test both databases on the same hardware, using the same tools and tests. We expected to test base functionality, and then work on more detailed comparisons. That way we could compare different real-world use case scenarios and popular options.

Spoiler: We are far from the final results. This is the start of a blog series.

OpenSource Databases on Big Machines, Series 1: “That Was Close…”

Postgres Professional together with Freematiq provided two modern, powerful machines for tests.

Note that machines with smaller numbers of CPU cores and faster disks are more common for MySQL installations than machines with larger numbers of cores.

The first thing we needed to agree on is which tool to use. A fair comparison only makes sense if the workloads are as close as possible.

The standard PostgreSQL tool for performance tests is pgbench, while for MySQL it’s SysBench. SysBench supports multiple database drivers and scriptable tests in the Lua programming language, so we decided to use this tool for both databases.

The initial plan was to convert pgbench tests into SysBench Lua syntax, and then run standard tests on both databases. After initial results, we modified our tests to better examine specific MySQL and PostgreSQL features.

I converted pgbench tests into SysBench syntax, and put the tests into an open-database-bench GitHub repository.

And then we both faced difficulties.

As I wrote already, I also ran the tests on a Percona machine. For this converted test, the results were almost identical:

Percona machine:

Percona Machine

Shell

1

2

3

4

OLTP teststatistics:

transactions:1000000(28727.81per sec.)

read/writerequests:5000000(143639.05per sec.)

other operations:2000000(57455.62per sec.)

Freematiq machine:

Shell

1

2

3

4

OLTP teststatistics:

transactions:1000000(29784.74per sec.)

read/writerequests:5000000(148923.71per sec.)

other operations:2000000(59569.49per sec.)

I started investigating. The only place where the Percona machine was better than Freematiq’s was disk speed. So I started running the pgbench read-only test, which was identical to SysBench’s point select test with full dataset in memory. But this time SysBench used 50% of the available CPU resources:

Shell

1

2

3

PID USER PRNI VIRT RES SHRS%CPU%MEM TIME+COMMAND

4585smirnova2000,157t0,041t9596S72261,412:27.16mysqld

8745smirnova20012662126291481824S71260,09:22.78sysbench

Alexander, in turn, had issues with SysBench, which could not create a high load on PostgreSQL when prepared statements were used:

Start both SysBench and mysqld with the jemalloc or tmalloc library pre-loaded

A fix for PostgreSQL is on the way. For now, Alexander converted a standard SysBench test into pgbench format and we stuck with it. Not much new for MySQL, but at least we had a baseline for comparison.

The next difficulty I faced was the default operating system parameters. To make the long story short, I changed them to the recommended ones (described below):

Shell

1

2

3

4

5

6

7

vm.swappiness=1

cpupower frequency-set--governor performance

kernel.sched_autogroup_enabled=0

kernel.sched_migration_cost_ns=5000000

vm.dirty_background_bytes=67108864

vm.dirty_bytes=536870912

IO scheduler[deadline]

The same parameters were better for PostgreSQL performance as well. Alexander set his machine similarly.

After solving these issues we learned and implemented the following:

We cannot use a single tool (for now)

Alexander wrote a test for pgbench, imitating the standard SysBench tests

We are still not able to write custom tests because we use different tools

But we could use these tests as a baseline. After work done by Alexander, we stuck with the standard SysBench tests. I converted them to use prepared statements, and Alexander converted them into pgbench format.

I should mention that I was not able to get the same results as Dimitri for the Read Only and Point Select tests. They are close, but slightly slower. We need to investigate if this is the result of different hardware, or my lack of performance testing abilities. The results from the Read-Write tests are similar.

Another difference was between the PostgreSQL and MySQL tests. MySQL users normally have many connections. Setting the value of the variable
max_conenctions, and limiting the total number of parallel connections to thousands is not rare nowadays. While not recommended, people use this option even without the thread pool plugin. In real life, most of these connections are sleeping. But there is always a chance they all will get used in cases of increased website activity.

For MySQL I tested up to 1024 connections. I used powers of two and multiplies of the number of cores: 1, 2, 4, 8, 16, 32, 36, 64, 72, 128, 144, 256, 512 and 1024 threads.

For Alexander, it was more important to test in smaller steps. He started from one thread and increased by 10 threads, until 250 parallel threads were reached. So you will see a more detailed graph for PostgreSQL, but no results after 250 threads.

Here are our comparison results.

Point SELECTs

pgsql-9.6 is standard PostgreSQL

pgsql-9.6 + pgxact-align is PostgreSQL with this patch (more details can be found in this blog post)

MySQL-5.7 Dimitri is Oracle’s MySQL Server

MySQL-5.7 Sveta is Percona Server 5.7.15

OLTP RO

OLTP RW

Sync commit in PostgreSQL is a feature, similar to
innodb_flush_log_at_trx_commit=1 in InnoDB, and async commit is similar to
innodb_flush_log_at_trx_commit=2.

You see that the results are very similar: both databases are developing very fast and work with modern hardware well.

MySQL results which show 1024 threads for reference.

Point SELECT and OLTP RO

OLTP RW with innodb_flush_log_at_trx_commit set to 1 and 2

After receiving these results, we did a few feature-specific tests that will be covered in separate blog posts.

Related

Stacy (Anastasia Raspopina) works for Percona as a Marketing Specialist responsible for internal company communication, event management, promotional activities, content generation and other special projects.

Sveta joined Percona in 2015. Her main professional interests are problem solving, working with tricky issues, bugs, finding patterns that can solve typical issues quicker and teaching others how to deal with MySQL issues, bugs and gotchas effectively. Before joining Percona Sveta worked as a Support Engineer in the MySQL Bugs Analysis Support Group in MySQL AB-Sun-Oracle.

She is the author of the book “MySQL Troubleshooting” and JSON UDF functions for MySQL.

15 Comments

Sveta and Anastasia, Thanks for posting! I found a couple of broken links. Could you fix:
* sysbench ConcurrencyKit https://github.com/akopytov/sysbench/tree/concurrency_kit
* https://blogs.oracle.com/mysqlinnodb/entry/transaction_life_cycle_improvements_in links to “http://innodb%20team%20blog%20post/”

> Any reason for testing with a different number of tables? (1 for Postgres vs 8 for mysql)
> Is it just the price to pay for having to convert sysbench tests to pgbench?

I believe number of tables does not much a lot for these tests. It certainly has not effect at all for RO tests for MySQL (I tested). But this is good point and I make sure in the next round of tests we will have same number of tables.

> Wondering how much of this could be re-used for an Aurora Mysql vs Aurora Pgsql benchmark…

You can certainly use tests for these benchmarks. These are standard MySQL tests for now anyway. But you will need to tune Aurora instances differently.

Well, idea of these particular benchmarks is to compare databases, setup by their experts. I did not touch PostgreSQL and Alexander did not touch MySQL. If we decide to include MS SQL or Oracle (thought they are not Open Source databases) we need to find partner(s) who are known modern expert(s) with them. This person is also should not be somebody who used MS SQL/Oracle 10 years ago =)

This branch uses LuaJIT instead of Lua and has scaling improvements. Actually looks like while this post was under review Alexey merged concurrency_kit into upstream. At least this is that commit logs say.

> Is prepared statement support in sysbench now?

You can use prepared statements with any version of SysBench! Difference between 0.4 and 0.5/1.0 versions is that 0.4 had –oltp-ps-mode option while in 0.5/1.0 you have to implement prepared statements in Lua code. Alexey wants to re-implement –oltp-ps-mode for modern versions: https://github.com/akopytov/sysbench/issues/95 I believe this is the reason why he does not advertise prepared statements support. But I did not wait and just re-wrote standard tests. You may use them as a workaround for now: https://github.com/akopytov/sysbench/pull/94

> What features do you and Alexey want to add to sysbench?

To be able to continue collaboration with PostgreSQL we need to solve SysBench+PostgreSQL issue. For MySQL I am happy so far.

All the credits should go to Sveta, actually. All the tests are hers, my assistance was minor and was mainly about organizational things, intros and such. Thank you for supporting the idea though – hopefully we’ll see more open source databases tested under the umbrella of this project.

In the graph of “OLTP RW”,why the performance of MySQL-5.7 trx=1 Dimitri is better than MySQL-5.7 trx=2 Dimitri ?
why the the performance of MySQL-5.7 trx=2 Sveta is better than MySQL-5.7 trx=1 Sveta ?