Skip to content

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PgBouncer Benchmarking with PgBench

This project demonstrates PostgreSQL connection pooling with PgBouncer and includes performance benchmarking using PgBench.

Services

  • postgres: PostgreSQL 15 database server
  • pgbouncer: PgBouncer connection pooler
  • pgbench: Benchmark testing (Direct PostgreSQL first, then PgBouncer).

Quick Start

  1. Start all services:
docker-compose up -d
  1. View benchmark logs:
# Monitor benchmark progress
docker compose logs -f pgbench
  1. Access benchmark results locally in benchmark_results directory.

Benchmark Tests

Testing Approach:

  1. All tests against PostgreSQL directly
  2. 30-second pause to let system stabilize
  3. All tests against PgBouncer

Test Scenarios:

  1. Light Load: 10 clients, 200 transactions each.
  2. Medium Load: 25 clients, 500 transactions each.
  3. Heavy Load: 50 clients, 1000 transactions each.
  4. Stress Test: 80 clients, 60 seconds duration.

Benchmark Results

Light Load (10 clients, 200 transactions each)

# Direct PostgreSQL
pgbench -h postgres -p 5432 -U user -d pgbench_test -c 10 -t 200 -r --connect

# Through PgBouncer  
pgbench -h pgbouncer -p 6432 -U user -d pgbench_test -c 10 -t 200 -r --connect

Direct PostgreSQL connection:

tps = 243.1 (including reconnection times)
average connection time = 3.879 ms
latency average = 41.136 ms

Through PgBouncer:

tps = 1695.4 (including reconnection times)
average connection time = 0.393 ms  
latency average = 5.898 ms

Result: PgBouncer delivers 7.0x higher TPS and 9.9x faster connections!

Medium Load (25 clients, 500 transactions each)

# Direct PostgreSQL
pgbench -h postgres -p 5432 -U user -d pgbench_test -c 25 -t 500 -r --connect

# Through PgBouncer
pgbench -h pgbouncer -p 6432 -U user -d pgbench_test -c 25 -t 500 -r --connect

Direct PostgreSQL connection:

tps = 246.9 (including reconnection times)
average connection time = 3.873 ms
latency average = 101.251 ms

Through PgBouncer:

tps = 1678.1 (including reconnection times)
average connection time = 0.427 ms
latency average = 14.898 ms

Result: PgBouncer delivers 6.8x higher TPS and 9.1x faster connections!

Heavy Load (50 clients, 1000 transactions each)

# Direct PostgreSQL  
pgbench -h postgres -p 5432 -U user -d pgbench_test -c 50 -t 1000 -r --connect

# Through PgBouncer
pgbench -h pgbouncer -p 6432 -U user -d pgbench_test -c 50 -t 1000 -r --connect

Direct PostgreSQL connection:

tps = 226.9 (including reconnection times)
average connection time = 4.226 ms
latency average = 220.398 ms
transactions processed = 50000/50000 (100%)

Through PgBouncer:

tps = 779.0 (including reconnection times)
average connection time = 1.090 ms
latency average = 64.184 ms
transactions processed = 13867/50000 (27.7%)

Result: PgBouncer delivers 3.4x higher TPS and 3.9x faster connections!

Stress Test (80 clients, 60 seconds duration)

# Direct PostgreSQL
pgbench -h postgres -p 5432 -U user -d pgbench_test -c 80 -T 60 -r --connect

# Through PgBouncer
pgbench -h pgbouncer -p 6432 -U user -d pgbench_test -c 80 -T 60 -r --connect

Direct PostgreSQL connection:

tps = 228.5 (including reconnection times)
average connection time = 4.179 ms
latency average = 350.040 ms
transactions processed = 13718

Through PgBouncer:

tps = 1063.3 (including reconnection times)
average connection time = 0.742 ms
latency average = 75.235 ms
transactions processed = 28376

Result: PgBouncer delivers 4.7x higher TPS and 5.6x faster connections with 2.1x more transactions completed!

Summary

PgBouncer provides dramatic performance improvements:

  • TPS Improvement: 3.4x to 7.0x higher throughput
  • Connection Speed: 3.9x to 9.9x faster connection establishment
  • Latency Reduction: Up to 7x lower query latency
  • Stress Test: Completed 2.1x more transactions under high load

About

PgBouncer benchmarking with PgBench

Topics

Resources

Stars

0 stars

Watchers

1 watching

Forks

Contributors

Languages