https://github.com/lchsk/postgresql_transactions
Benchmarking concurrent operations in PostgreSQL
https://github.com/lchsk/postgresql_transactions
benchmark cpp cpp17 isolation-level postgres postgresql sql transaction transactions
Last synced: about 1 month ago
JSON representation
Benchmarking concurrent operations in PostgreSQL
- Host: GitHub
- URL: https://github.com/lchsk/postgresql_transactions
- Owner: lchsk
- Created: 2020-05-05T21:09:30.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2020-05-29T13:41:05.000Z (about 6 years ago)
- Last Synced: 2025-10-04T02:50:28.637Z (9 months ago)
- Topics: benchmark, cpp, cpp17, isolation-level, postgres, postgresql, sql, transaction, transactions
- Language: C++
- Homepage: https://lchsk.com
- Size: 154 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# PostgreSQL concurrent transactions benchmark
Benchmark a number of different operations in Postgres. It simulates a concurrent environment with different transaction isolation levels.
- Article describing the results of this benchmark: https://lchsk.com/benchmarking-concurrent-operations-in-postgresql.html
- Context about transactions and concurrent behavior in PostgreSQL: https://lchsk.com/database-transactions-concurrency-isolation-levels-and-postgresql.html
## Application
It's written in C++ and user pqxx library to connect to Postgres. It requires C++17 compiler (tested with gcc 10). It's been tested with PostgreSQL 12.3.
It has a number of parameters to change its behavior. You can run it with `--help` options to see them all.
## Parameters
`--threads` option tells the program how many threads it should run. By default, the application will open 10 connections to Postgres (it can be changed with `--connections`) and run threads to simulate the concurrent access to the database. At the end of a run, it prints the timings for each operation.
To gather benchmarks it's useful to run it with `--repetitions [n]` which will run every test `n` times and compute average timings.
## Isolation levels
The transaction isolation level used in tests must be changed in the source code (`src/tasks.hpp` - `isolation` constant). Available options include: `read_committed`, `repeatable_read`, and `serializable`.
## Compilation
It needs `pqxx` to talk to Postgres, make sure it's installed (https://github.com/jtv/libpqxx), I've tested it with version 7.07.
You also need a compiler supporting at least C++17, I've tested it with gcc 10.
Run `make` in the main directory. That should give you a binary in `./bin/txn`.
## Running tests
You need a Postgres database. You can spin one up with `docker-compose` by running
```
docker-compose up
```
You can quickly open shell with `./open_shell.sh`.
A quick test can be run with `./bin/txn` which should run a test with 100 threads.
You can increase the number of threads with `--threads` and repeat tests with `--repetitions`. By default, it uses 10 connections to Postgres, this can be changed with `--connections`.
E.g. to run 500 threads with 5 connections and repeat each test 3 times:
```
./bin/txn --threads 500 --repetitions 3 --connections 5
```