Thursday, May 4, 2023

The insert benchmark, Postgres versions 11 to 15, a big server

This has results for Postgres vs the insert benchmark on a big server. My previous post had results for a small server. The goals are to look for performance changes from PG version 11 to 15 and to determine the impact of compiler optimizations. The context here is a cached workload (reads from cache, writes to storage) with high concurrency.

tl;dr

  • See the Most Important Disclaimer here
  • I accept that tuning might be required to improve throughput and/or reduce response time variance, but I am also wary of a DBMS that requires too much per-workload tuning.
  • The insert rate for l.i1 drops from (420k/s, 400k/s) when the database is cached by Postgres to (150k/s, 200k/s) when the database is cached by the OS but not by Postgres. The two numbers are for (20 tables, 1 table). I don't think this is a problem, but I document it here for comparisons with other DBMS.
  • Per-second response time and insert rates for l.i1 show much variance, aka write stalls. I have yet to explain what causes this. The variance is visible but not as significant for l.i0.
  • the o3_native_lto build has the best perf but the benefit isn't as large here as it was on the small server. The benefit was <= 3% for writes and <= 5% for reads
  • I ignore the create index benchmark step (see l.x below) 
  • For the configuration with a table per client
    • For inserts without secondary indexes version 15.2 is ~2% slower than 11.19 (see l.0 below)
    • For inserts with secondary indexes version 15.2 is ~1% faster than 11.19 (see l.1 below)
    • Reads are ~4% faster in version 12.14 than 11.19 and the perf has not changed since then (see q100.1, q500.1, q1000.1 below)
  • For the configuration with all clients sharing one table
    • For inserts without secondary indexes version 15.2 is ~4% slower than 11.19 (see l.0 below). This is slightly worse than the case above with a table per client.
    • For inserts with secondary indexes perf is the same as above for a table per client
    • Read perf is the same as above for a table per client

Benchmarks

The server is a c2-standard-60 from GCP with 30 cores, hyperthreads disabled, 240G RAM and 3T of NVMe (XFS, RAID 0 across 8 devices). Huge pages were enabled for all benchmark runs.

An overview of the insert benchmark is here and here. The insert benchmark was run for a cached database with 20 clients. The read+write steps (q100.1, q500.1, q1000.1) were run for 1800 seconds each.

Benchmarks were repeated for two configurations:
  • cached by Postgres - all data fits in the Postgres buffer pool and vm.nr_hugepages was 85000
  • cached by OS - all data fits in the OS page cache but not the Postgres buffer pool. The buffer pool size is 4G and the database was ~190G at test end. For huge pages I set vm.nr_hugepages to 4000.
The configuration files are here for:
The benchmark is a sequence of steps:

  • l.i0 - insert 20 million rows without secondary indexes
  • l.x - create 3 secondary indexes. I usually ignore results from this step.
  • l.i1 - insert another 20 million rows with the overhead of secondary index maintenance
  • q100.1 - do queries as fast as possible with 100 inserts/s/thread done in the background
  • q500.1 - do queries as fast as possible with 500 inserts/s/thread done in the background
  • q1000.1 - do queries as fast as possible with 1000 inserts/s/thread done in the background
Builds

For Postgres 15.1 I have results for several builds. A description of the builds is here. For Postgres versions 11.19, 12.14, 13.10, 14.7 and 15.2 I only have results for the o3_native_lto build as that tends to have the best performance.

Reports

Performance summaries generated by shell scripts are below. A short guide to these results is here. There are two types of reports. The version 15.1 builds report compares performance for Postgres 15.1 using different compiler optimizations. The versions 11 to 15 report compares performance for Postgres versions 11.19, 12.14, 13.10, 14.7, 15.1 and 15.2. For each type of report there are two variations:
  • 20 clients, 20 tables - used 20 client & 20 tables with a client per table.
  • 20 clients, 1 table - used 20 clients & 1 table
Reports for cached by Postgres:
Reports for cached by OS:
Response time

Charts with throughput and response time per 1-second intervals are here. First, the disclaimers:
  • The graphs are from just one of the 20 clients.
  • I risk drawing strong conclusions from small samples.
The charts:
  • cached by Postgres
    • 20 clients, 20 tables: l.i0, l.i1, q100.1, q500.1, q1000.1
      • For l.i0 there are regular drops in the insert rate from X to X/2 per second. 
      • For l.i1 there is a sawtooth pattern where the insert rate drops to near zero every ~300 seconds.
      • For q500.1 there is much noise on the per-second insert rate graphs and the per-second response time graphs have a sawtooth pattern. For this test the background insert rate is 10000/s from 500 inserts/s/client.
      • The q1000.1 results are similar to q500.1 -- much variance for inserts.
    • 20 clients, 1 table: l.i0, l.i1, q100.1, q500.1, q1000.1
      • Results are similar to 20 clients, 20 tables above
  • cached by OS: 
    • 20 clients, 20 tables: l.i0, l.i1, q100.1, q500.1, q1000.1 
      • Results for l.i0 are similar to the results for cached by Postgres
      • Results for l.i1 are much worse than for cached by Postgres. While they have a similar sawtooth pattern there is a much larger drop between 1500 and 2000 seconds.
      • For q500.1 and q1000.1 the per-second insert rates are similar to cached by Postgres but the per-second query rates have more variance.
    • 20 clients, 1 table: l.i0, l.i1, q100.1, q500.1, q1000.1
      • Results for l.i0 are similar to the results for cached by Postgres
      • Results for l.i1 are similar to the results for cached by OS above
      • Results for q100.1, q500.1 and q1000.1 are similar to the results for cached by OS above
Up next are tables with response time details per benchmark step -- both histograms and the max. Note that ms means milliseconds, by insert I mean a multi-row insert statement and the use of brackets ([]) below indicates the range of the max response time over multiple results (1 result per build). It can be risky to draw strong inferences from a small sample (one run per build).
  • cached by Postgres
    • 20 clients, 20 tables
      • l.i0 - the max is [410ms, 1234ms]. Version 11.19 has the largest max.
      • l.i1 - the max is [1045ms, 1255ms].
      • q100.1 - the max is [27ms, 129ms] for queries and [36ms, 778ms] for inserts.
      • q500.1 - the max is [45ms, 285ms] for queries and [230ms, 399ms] for inserts.
      • q1000.1 - the max is [58ms, 113ms] for queries and [199ms, 254ms] for inserts.
    • 20 clients, 1 table
      • l.i0 - the max is [612ms, 1883ms]. Version 14.7 has the largest max.
      • l.i1 - the max is [884ms, 2045ms].
      • q100.1 - the max is [23ms, 1654ms] for queries and [45ms, 1807ms] for inserts.
      • q500.1 - the max is [35ms, 352ms] for queries and [171ms, 473ms] for inserts.
      • q1000.1 - the max is [33ms, 54ms] for queries and [163ms, 216ms] for inserts.
  • cached by OS
    • 20 clients, 20 tables
      • l.i0 - the max is [386ms, 682ms]. Results here are better than cached by Postgres. The worst-case stall might be a function of the buffer pool size.
      • l.i1 - the max is [722ms, 1055ms].
      • q100.1 - the max is [137ms, 372ms] for queries and [38ms, 292ms] for inserts.
      • q500.1 - the max is [65ms, 158ms] for queries and [219ms, 318ms] for inserts.
      • q1000.1 - the max is [76ms, 134ms] for queries and [205ms, 489ms] for inserts.
    • 20 clients, 1 table
      • l.i0 - the max is [366ms, 928ms]. Results here are better than cached by Postgres.
      • l.i1 - the max is [539ms, 753ms].
      • q100.1 - the max is [15ms, 24ms] for queries and [39ms, 318ms] for inserts.
      • q500.1 - the max is [25ms, 270ms] for queries and [103ms, 377ms] for inserts.
      • q1000.1 - the max is [48ms, 238ms] for queries and [217ms, 344ms] for inserts.
















The insert benchmark, Postgres versions 11 to 15, a small server

I used the insert benchmark to search for CPU regressions in Postgres. The workload is CPU bound, fits in the Postgres buffer pool and has low concurrency. I used Postgres versions 11.19, 12.14, 13.10, 14.7, 15.1 and 15.2.

Once again, Postgres has done a great job at avoiding performance regressions.

tl;dr

  • From version 11.19 to 12.14
    • Write throughput is similar to 4% better in 12.14 (see l.i0, l.i1 below)
    • Read throughput is ~10% better in 12.14 (see q100.1, q500.1, q1000.1 below)
  • From version 12.14 to 15.2 performance is similar
  • The o3_native_lto build has the best performance and is from 5% to 20% faster than the def build. The o3_native_lto build benefits a little bit from -O3 and CPU specific optimizations, but mostly from link time optimization

Benchmarks

An overview of the insert benchmark is here and here. The insert benchmark was run for a cached database with both 1 and 4 clients. For 1 client the benchmark used 1 table. For 4 clients the benchmark was first run with 4 tables (1 client/table) and then again with 1 table (all clients shared the table). The read+write steps (q100.1, q500.1, q1000.1) were run for 1800 seconds each.

The benchmark server is a Beelink SER 4700u described here with 8 AMD cores, 16G of RAM and 1T of NVMe SSD. The OS is Ubuntu 22.04 and the filesystem is XFS.

Benchmarks were repeated for two configurations:
  • cached by Postgres - all data fits in the Postgres buffer pool
  • cached by OS - all data fits in the OS page cache but not the Postgres buffer pool. The buffer pool size is 1G and the database was ~10G at test end. 
The configuration files are here for:
The benchmark is a sequence of steps:

  • l.i0 - insert 20 million rows without secondary indexes
  • l.x - create 3 secondary indexes. I usually ignore results from this step.
  • l.i1 - insert another 20 million rows with the overhead of secondary index maintenance
  • q100.1 - do queries as fast as possible with 100 inserts/s/thread done in the background
  • q500.1 - do queries as fast as possible with 500 inserts/s/thread done in the background
  • q1000.1 - do queries as fast as possible with 1000 inserts/s/thread done in the background
Builds

For Postgres 15.1 I have results for several builds. A description of the builds is here. For Postgres versions 11.19, 12.14, 13.10, 14.7 and 15.2 I only have results for the o3_native_lto build as that tends to have the best performance.

Reports

Performance summaries generated by shell scripts are below. A short guide to these results is here. There are two types of reports. The version 15.1 builds report compares performance for Postgres 15.1 using different compiler optimizations. The versions 11 to 15 report compares performance for Postgres versions 11.19, 12.14, 13.10, 14.7, 15.1 and 15.2. For each type of report there are three variations:
  • 1 client, 1 table - used 1 client & 1 table. This is best for spotting CPU regressions.
  • 4 clients, 4 tables - used 4 clients & 4 tables, each client has their own table
  • 4 clients, 1 table - used 4 clients sharing 1 table
Reports for cached by Postgres:
Reports for cached by OS:



Wednesday, April 26, 2023

Time to compile Postgres, MySQL and MyRocks

I measured the time it takes to build Postgres, upstream MySQL and FB MySQL from source on my home servers (Beelink, see here) using Postgres 15.2, upstream MySQL 8.0.32 and FB MySQL 8.0.28. 

tl;dr

  • Build times in seconds: 619 for Postgres, 5294 for upstream MySQL, 8443 for FB MySQL
  • Postgres is by far the fastest to compile. Reasons for that include that it uses C and has fewer things to compile
  • FB MySQL spends ~2700 seconds compiling RocksDB related things. Without that overhead the FB MySQL build would be 5601 seconds vs 5294 for upstream MySQL. For reasons I don't understand yet, most of the RocksDB source files are compiled 3 times (for the storage engine, ldb binary and sst_dump binary). If that could be avoided then the build time would be reduced by ~20%.

Setup

While the server has 8 cores I did a non-parallel make (make -j1). 

The build configuration (configure & CMake command lines) for each DBMS is here.

Methods

For Postgres I just measure the total time to build. For upstream and FB MySQL I also measure the time for each build target. That is done in two steps.

  1. Run make and add timestamps to the output. Smart people on Twitter explained how to do that.
  2. Parse the output from make to get per-target compile times
To run make I did:
make 2>&1 | ts '[%s]' | tee o.time
To parse the output I did:
grep "Built target" o.time | tr '[]' ' ' | \
awk '{ $2=""; $3=""; $4=""; print $0 }' | \
awk '{ if (NR==1) { printf "%s\t%s\n", $1 - itime, $2 } else { printf "%s\t%s\n", $1 - lastTS, $2 };  lastTS=$1 } ' itime=$firstTS | \
sort -rnk 1,1 | head -10
Results: summary

Legend

* Time(s) - total time for build in seconds
* Targets - number of build targets, only printed for MySQL

Time(s) Targets DBMS
619     NA      Postgres
5294    255     upstream MySQL
8443    251     FB MySQL

Results: detailed

The time in seconds for the top-20 build targets

For upstream MySQL 8.0.32:

1035    sql_main
636     innobase
433     sql_gis
393     sql_dd
301     group_replication
294     perfschema
209     icui18n
190     mysqld
153     libprotoc
128     icuuc
123     libprotobuf
99      slave
96      binlog
65      mysql_server_component_services
65      mysqlgcs
54      mysys_objlib
49      myisam_library
44      mysqlpump_lib
33      libprotobuf-lite
30      mysqlbinlog

For FB MySQL:

The RocksDB related build targets are rocksdb_se, ldb and sst_dump. From the output it looks like each of those repeats the same work -- as all or most of the RocksDB source files are recompiled for each. That explains why each target takes ~900 seconds. If the recompile could be avoided then the build time would be reduced by ~20%.

1201    sql_main
993     rocksdb_se
932     ldb
917     sst_dump
598     innobase
462     sql_dd
411     sql_gis
334     group_replication
332     perfschema
227     mysqld
212     icui18n
153     libprotoc
131     slave
129     icuuc
123     libprotobuf
97      binlog
65      mysqlgcs
57      mysys_objlib
54      mysql_server_component_services
47      myisam_library

Tuesday, April 25, 2023

Perf regressions in MySQL/InnoDB, a big server & sysbench, part 2

My last post has results for MySQL/InnoDB on a big server and the database fit in the InnoDB buffer pool. Here I have results where the database fits in the OS page cache but not the InnoDB buffer pool.

The context for the results is short-running queries, in-memory (cached by the OS) with high-concurrency (20 clients) on a big server (30-cores). The goals are:

  1. Understand the impact of compiler optimizations
  2. Document how performance has changed from MySQL 5.6 to 5.7 to 8.0
  3. Document performance with fast storage (reading from the OS page cache is fast)
tl;dr
  • The rel_lto build improves QPS by up to 3%
  • 8.0 releases look much better here with a big server & high-concurrency than on the small server with low-concurrency.
  • For changes from 5.6 to 8.0
    • Point queries - version 8.0.32 gets about 3X more QPS than 5.6.51 on most of the microbenchmarks. This is much better than the previous result where the database fits in the buffer pool.
    • Range queries - version 8.0.32 gets about 14% more QPS than 5.6.51. This is much better than the previous result where the database fits in the buffer pool.
    • Writes - version 8.0.32 gets the same QPS as version 5.6.51. This is much worse than the previous result where the database fits in the buffer pool.
Benchmark

A description of how I run sysbench is here. Tests use the a c2-standard-60 server on GCP with 30-cores, hyperthreading disabled, 240G RAM and 3TB of local attached NVMe. The sysbench tests were run for 20 clients, 600 seconds per microbenchmark using 4 tables with 50M rows per table. All tests use the InnoDB storage engine. The test database fits in the InnoDB buffer pool.

I used a similar configuration (my.cnf) for all versions which is here for 5.6, 5.7, 8.0.2x and 8.0.3x.

Builds

I tested MySQL versions 5.6.51, 5.7.40, 8.0.22, 8.0.28, 8.0.31 and 8.0.32 using multiple builds for each version. For each build+version the full set of sysbench microbenchmarks was repeated. More details on the builds are in the previous post. To save time I only tested all builds for 8.0.31 and for other versions used the rel_lto build.

Results: all versions

The spreadsheet is here. See the 56_to_80.redo.4g tab.

The graphs use relative throughput which is throughput for me / throughput for base case. When the relative throughput is > 1 then my results are better than the base case. When it is 1.10 then my results are ~10% better than the base case. The base case here is MySQL 5.6.51 using the rel_lto build.

There are three graphs per version which group the microbenchmarks by the dominant operation: one for point queries, one for range queries, one for writes. There is much variance within each of the microbenchmark groups:
  • Point queries - most of the microbenchmarks get about 3X more QPS in 8.0 than 5.6. The exceptions are hot-points_range=100, point-query.pre_range=100 and point-query.range=100. Two of the exceptions select one row per query while the microbenchmarks that are 3X faster tend to have a large in-list.
  • Range queries - most of the microbenchmarks have a relative throughput between 0.8 and 1.2 with 8.0 compared to 5.6.51. There are two outliers that are more than 3X faster in 8.0 -- range-notcovered-si.pre_range=1000 and range-notcovered-si_range=1000 which use oltp_points_covered.lua. The two exceptions do a range scan on a non-covering secondary index so there will be more reads from the OS page cache for these.
  • Writes - there is not much variance in the microbenchmarks except for read-write* which use the classic sysbench transaction that includes range queries. Perhaps their improvement in 8.0 vs 5.6 is mostly do to the improvements in range queries, but their cousin (read-only*) which uses the same SQL excluding the writes doesn't show such an improvement. This is a mystery.
Summary statistics:

my5651_relmy5740_rel_ltomy8022_rel_ltomy8028_rel_ltomy8031_rel_ltomy8032_rel_lto
Point: avg1.712.672.752.712.70
Point: median1.582.882.983.153.19
Point: min1.031.021.010.990.98
Point: max5.113.733.763.703.37
Point: stddev0.8970.7940.8610.8440.840
Range: avg1.291.471.501.421.42
Range: median1.251.241.191.151.14
Range: min0.810.710.730.680.62
Range: max2.293.473.603.443.44
Range: stddev0.3680.8340.8970.8470.858
Write: avg1.221.091.071.061.06
Write: median1.181.021.011.001.01
Write: min0.980.890.950.940.95
Write: max1.521.551.331.331.33
Write: stddev0.2000.2200.1420.1340.132

Results: MySQL 8.0.31

The spreadsheet is here. See the my8031.redo.4g tab.

The graphs use relative throughput which is throughput for me / throughput for base case. When the relative throughput is > 1 then my results are better than the base case. When it is 1.10 then my results are ~10% better than the base case. The base case here is MySQL 8.0.31 using the rel_withdbg build.

There are three graphs per version which group the microbenchmarks by the dominant operation: one for point queries, one for range queries, one for writes. For each group of microbenchmarks:
  • Point queries - there is little variance across the microbenchmarks
  • Range queries - the full table scan test (scan_range=10) shows the best improvement from the rel_lto build. I don't understand the noisy result for the read-only_range=10000 microbenchmark. Perhaps buffer pool writeback was still in progress as that microbenchmark is run shortly after the write-heavy microbenchmarks.
  • Writes -  there is little variance across the microbenchmarks
Summary statistics:

rel_withdbgrel_o2rel_nativerelrel_o2_ltorel_native_ltorel_lto
Point: avg0.981.021.021.011.031.03
Point: median0.991.021.021.011.031.03
Point: min0.950.960.971.001.011.01
Point: max1.011.031.031.021.061.05
Point: stddev0.0170.0210.0180.0070.0110.011
Range: avg0.980.980.981.001.001.01
Range: median0.970.980.981.011.011.02
Range: min0.960.890.860.930.900.81
Range: max1.071.061.031.021.041.11
Range: stddev0.0280.0400.0380.0210.0340.061
Write: avg0.980.980.990.990.991.00
Write: median0.980.980.990.980.980.99
Write: min0.970.980.980.980.980.99
Write: max0.980.991.001.001.011.01
Write: stddev0.0030.0050.0060.0070.0110.008

    CPU-bound sysbench on a large server: Postgres 12 to 19 beta1

    This has results from sysbench on a small server with Postgres versions 12 through 19 beta1. Sysbench is run with high concurrency (40 conne...