Benchmarks¶
Gres reached 28,000 pooled queries per second (up to 2.5× the throughput of asyncpg and Psycopg), 52.1 µs median single-read latency, 5.01 ms for 8,192-row binary COPY (up to 2.4× the speed of asyncpg and Psycopg), and 216 ms / 82 MiB peak client memory growth for 524,288 rows.
Reading the charts. Values are medians. Capped whiskers show 95% confidence intervals across process blocks; the latency chart instead shows the median and p95 of individual reads. A dagger (†) or a note of no clear difference means the paired runs did not resolve a difference.
Inventory reservations¶
Time to commit 128 inventory reservations on local PostgreSQL 19. Sixteen tasks share each driver's default pool. Each reservation updates stock and inserts a row in one transaction on logged tables. Lower times are better.
| Deployment | Gres | asyncpg | Psycopg |
|---|---|---|---|
| Direct PostgreSQL128 committed writes · 16 pooled tasks | 13.9 msup to 1.44× faster | 20.0 ms | 19.8 ms |
| PgBouncer transaction pooling128 committed writes · transaction mode | 13.5 ms1.51× faster | 20.2 ms | 20.3 ms |
The second deployment uses PgBouncer 1.25.2 in transaction mode with named-statement tracking; Gres declares that capability with auto_prepare=True. Client pinned to CPUs 12,14,28,30 and server to CPUs 13,15,29,31. PgBouncer runs on CPUs 13,15,29,31 (shared with PostgreSQL). Cgroup CPU budget (client, proxy, server): 400000 µs per 100000 µs period. See Workload notes.
Pooled query throughput¶
Sixteen tasks share four connections using default pool settings. Each query checks out a connection, reads one value, and returns the connection to the pool.
- Gres28,048
- asyncpg11,271
- Psycopg14,714
Single-read latency¶
One connection reads one primary key at a time and returns a typed Python row with decoded JSONB. The solid bar ends at the median. The line ends at p95: 95% of reads in a process finished within that time.
Median and p95: Gres is faster than asyncpg and Psycopg.
384 reads per process, 36 fresh processes per driver.
Time and memory for a large result¶
Lower left means a faster fetch and less client memory. Time measures a warmed fetch; memory is the increase in peak resident set size during the first fetch, excluding PostgreSQL.
| Driver | Fetch (ms) | Growth (MiB) |
|---|---|---|
| Gres | 216 | 82.2 |
| asyncpg | 306 | 119.1 |
| Psycopg | 229 | 101.9 |
Fetch time: Gres is faster than asyncpg and Psycopg. Memory growth: Gres uses less memory than asyncpg and Psycopg.
One client process versus 8¶
The client CPU set stays fixed. Each process runs its own batch: 256 queries through a pool, or 128 lookups on a dedicated connection. Values are milliseconds per batch, not aggregate throughput. Each pair compares the two measured process counts.
1 process8 processes
1 process8 processes
Workload timings¶
One client process, median milliseconds per batch. Lookups return 128 typed rows. Writes include commit; spatial exports preserve point order and nulls. A dagger (†) marks a comparison with no clear difference from Gres.
Application lookups¶
| Workload | Gres | asyncpg | Psycopg |
|---|---|---|---|
| Primary-key lookup128 typed dataclass rows · parsed JSONB | 6.89 msup to 1.09× faster | 7.46 ms | 7.41 ms |
| UUID-key lookup128 typed rows · UUID key & JSONB | 7.01 msup to 1.08× faster | 7.59 ms | 7.62 ms |
Bulk writes¶
| Workload | Gres | asyncpg | Psycopg |
|---|---|---|---|
| 2,048 batched inserts2,048 parameterized inserts · 1 transaction | 6.34 msup to 1.87× faster | 7.73 ms | 11.91 ms |
| COPY of 8,192 rows8,192 Python rows · binary COPY & commit | 5.01 msup to 2.4× faster | 12.25 ms | 11.50 ms |
PostGIS exports¶
| Workload | Gres | asyncpg | Psycopg |
|---|---|---|---|
| 8,192 points as EWKB8,192 nullable points · ST_AsEWKB tuples | 2.89 msup to 1.39× faster | 4.01 ms | 3.33 ms |
| 8,192 points as GeoArrow8,192 nullable points · Arrow batches | 3.56 msup to 1.92× faster | 6.49 ms | 6.78 ms |
Preparation controls¶
| Workload | Gres | asyncpg | Psycopg |
|---|---|---|---|
| Prepared lookup128 typed rows · explicitly prepared | 6.26 msup to 1.13× faster | 7.06 ms | 7.17 ms |
| Lookup, statement cache off128 typed rows · automatic reuse disabled | 13.04 ms1.47× vs asyncpg | 19.07 ms | 10.90 ms |
Test environment¶
Gres 1.0.0, asyncpg 0.32.0, Psycopg 3.3.9. PostgreSQL 19.0 with PostGIS 3.6.4 over a Unix socket. CPython 3.15.1 on Linux-7.3.6-x86_64-with-glibc2.44.
AMD Ryzen 9 5950X 16-Core Processor. Client pinned to CPUs 12,14,28,30 and server to CPUs 13,15,29,31. Cgroup CPU budget (client, server): 400000 µs per 100000 µs period.
Gres used the release profile with profile-guided optimization.
CPU contention check: 2 of 590 three-driver blocks were discarded and retried as whole blocks. The decision used CPU load, not benchmark timings.
Measurement method¶
Each block runs the drivers in fresh processes. Every round uses all six driver orders. Each process warms up once, then times three batches. Batch results show the median of the block medians; individual-read latency is measured separately. Setup and correctness checks are outside the timer. Ratios divide peer time by Gres time within a block; intervals apply to individual comparisons.
The eight clients share the same CPU allocation as the one-process run. See Test environment for the recorded placement. Each eight-process block includes 24 batch timings per driver. The results are per-batch times under contention, not aggregate throughput.
Workload notes¶
- Inventory service. Each request updates stock and inserts a reservation in one transaction on logged tables. PostgreSQL keeps
fsync,synchronous_commitandfull_page_writesenabled. A separate connection verifies both tables after commit. Client pools keep their native sizes, reset policies, and statement caches. PgBouncer runs in transaction mode with named-statement tracking and its default backend pool size. Measurements use local Unix sockets, not a remote network. - Fixed-size pool throughput. Gres resets the session before its next query and can keep automatically prepared statements. asyncpg runs its reset query on release. Psycopg uses autocommit here, with no custom reset.
- Lookups return frozen dataclasses with parsed JSONB using Gres's default connection. Explicit preparation prepares the statement before timing; the cache-off case disables automatic reuse in each driver.
- Bulk writes use temporary tables. Timings include client encoding and acknowledged commit, not durable table writeback.
- Spatial exports return the same points as EWKB or GeoArrow. The EWKB query calls
ST_AsEWKBon the server and times fetching(id, bytea)tuples; it does not measure geometry-object decoding. Gres produces GeoArrow directly; asyncpg and Psycopg read through cursors and convert with gometry.
Data and reproduction¶
Run the Gres benchmark harness
against a disposable local PostgreSQL database. Follow its setup to install the
measurement wheels and configure the database socket, then run benchmark.py
collect and benchmark.py report from the repository root as shown there.
The harness also gives the commands for the PgBouncer and eight-process runs.