Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Performance

One benchmark measures how fast Straum answers and how much memory it takes; Running it yourself has the commands. It sends Straum and PostgreSQL the same asks about six months of New York taxi trips, checks that the answers are equal, then times both. Against a materialized view asks the same of a materialized view and measures its refresh, Transactions what one large transaction costs Straum, Physical write-ahead log (WAL) how fast Straum reads the physical WAL, and Memory how many bytes a cell takes, on the taxi month and on a copy of a warehouse’s tables.

The data is the Taxi and Limousine Commission (TLC) yellow trips of January to June 2024, 20,332,093 trips, and the 265 rows of taxi_zone_lookup.csv. The loader pins each file’s SHA-256 and stops if the TLC republished one, since these counts hold only for those bytes.

Results

Sixteen fixed asks over the benchmark’s two views, each sent to PostgreSQL as SQL over the raw tables and to Straum as an ask over HTTP. Rows are the answer’s. One run on an Apple M2 Pro with 16 GB, on 2026-11-19: PostgreSQL 18.7 in Docker Desktop with 10 CPUs, and Straum’s release build on the same machine. Each time is the median over at least a second and five runs, from one Python client: asyncpg for PostgreSQL, aiohttp and orjson for Straum.

PostgreSQL runs with its defaults, two parallel workers per query, except shared_buffers at 2 GB; the rest of the table comes from the OS cache. The other settings in bench/taxi.py only speed the load. yellow_trips has an index on pickup_at, which the week and day asks use.

AskRowsPostgreSQLStraumFaster
Trips1214.8 ms146 µs1,472x
Card trips1381.8 ms223 µs1,715x
Trips by pickup borough81,058.8 ms269 µs3,938x
Fares by payment type6795.3 ms340 µs2,342x
Fare spread by payment type6839.9 ms437 µs1,921x
Median fare14,839.8 ms25.2 ms192x
p99 fare by payment type68,670.9 ms22.1 ms392x
Most common fare by payment type69,550.7 ms36.2 ms264x
Distinct fares by payment type610,972.6 ms8.2 ms1,336x
Median fare per hour, one day2447.7 ms669 µs71x
Manhattan pickups, one week184.2 ms236 µs356x
Trips per hour, one day2416.8 ms164 µs103x
Trips per hour by borough, one month4,454964.9 ms2.7 ms358x
Trips per day by borough, one month243966.0 ms395 µs2,444x
Fares per week312,154.9 ms233 µs9,260x
Tips by dropoff borough81,746.0 ms225 µs7,754x

The target is under 1 ms for every ask (architecture decision record ADR-0005). The percentile, mode and distinct asks over every trip miss it, as does the month of hourly rows by borough, which writes 4,454 rows.

PostgreSQL’s time follows the rows it reads: every trip, except in the week and day asks, which read a week’s or a day’s through the index and show the smallest gap. Straum’s time hardly changes from ask to ask; most of it is the HTTP round trip, reading the query and writing JSON.

The percentile, mode and distinct asks are the exception. Straum gathers every fare of the cells in range, so their time follows the fares the range holds (Median and percentiles). A group by payment type over six months meets every weekly cell of every zone, 1,426,949 fares in 6,398 cells for the largest group, and marks each in a set of bits from the least fare to the greatest. Count, sum and average of the distinct fares mark them once and share the tally. Merging them in order on a heap, once per measure, took 423.3 ms; marking them once per measure took 24.4 ms.

Straum was ready 16.3 s after it started and held 305 MiB, the 265 zone rows’ projection included; in PostgreSQL the table and its indexes take 2,475 MiB. Runs the same day show where Straum’s memory goes: without the fare’s variance, standard deviation, mode and distinct values it held 190 MiB; with the first two, 205 MiB; with the mode too, 204 MiB. The sums of squares take about 15 MiB, and the mode reads the counts the percentiles keep. The distinct fares took the other 101 MiB, as count(DISTINCT c) kept a count per value of its own. It has read the percentiles’ counts since, and a run on 2026-11-20 held 202 MiB.

On macOS the bench reads what Straum holds from the process’s footprint, which counts the pages the system compressed; on a busy machine one resident set read 21 MiB. Elsewhere it reads the resident set.

Straum answers only what the views keep: these keys, on hour edges. PostgreSQL answers any query over the raw rows. The times above are PostgreSQL reading every trip; a dashboard that can’t wait for that keeps a summary instead. Against a materialized view measures that summary: it answers in milliseconds too, but only as of its last refresh, and it has no answer for the percentile, mode and distinct asks.

Against a materialized view

just taxi materialized builds one materialized view per view of bench/trips.sql, with the same keys at the narrowest bucket, an hour on the epoch grid, and a unique index on them so it can refresh concurrently. bench/materialized.py writes both. The materialized views keep counts and sums only, since those add across buckets: an average is a sum over a count, a variance and standard deviation come from the count, sum and sum of squares. Each ask then goes to PostgreSQL over the raw tables, to the materialized view with the ask’s own range, and to Straum. The materialized view’s answer must equal Straum’s, as the raw table’s must, or the run stops.

A median, percentile, mode or distinct count over a range does not merge from per-bucket rows (Merging), so those asks have no materialized view form here. Straum answers them from the count per value each cell keeps; a materialized view could keep a row per bucket, key and fare to do the same, which this bench does not build.

One run on 2026-11-20, on the machine and PostgreSQL of the Results. Other builds and tests ran on the machine meanwhile, its load average 6.08 when the run began, so these times are rough; the raw-table times differ from the Results’ for that reason.

AskRowsPostgreSQLMaterialized viewStraum
Trips1225.5 ms31.4 ms145 µs
Card trips1413.8 ms27.2 ms225 µs
Trips by pickup borough81,126.3 ms52.2 ms265 µs
Fares by payment type6850.4 ms61.2 ms337 µs
Fare spread by payment type6953.2 ms68.3 ms438 µs
Median fare15,293.9 msneeds the raw rows25.7 ms
p99 fare by payment type69,079.2 msneeds the raw rows21.6 ms
Most common fare by payment type69,661.6 msneeds the raw rows36.4 ms
Distinct fares by payment type611,200.9 msneeds the raw rows8.6 ms
Median fare per hour, one day2449.3 msneeds the raw rows639 µs
Manhattan pickups, one week175.9 ms3.1 ms203 µs
Trips per hour, one day2417.8 ms903 µs162 µs
Trips per hour by borough, one month4,454994.8 ms30.7 ms2.6 ms
Trips per day by borough, one month243982.6 ms27.1 ms387 µs
Fares per week312,619.9 ms61.6 ms234 µs
Tips by dropoff borough81,814.2 ms58.0 ms216 µs

The materialized view reads its rows in the ask’s range: every hour of six months for the asks over all time, a day’s or a week’s through its index for the rest. It answers in 903 µs to 68.3 ms, faster than the raw tables and slower than Straum, which reads cells of the widest width that fits. This bench builds one materialized view per view. One per ask, grouped by that ask’s keys alone, would hold fewer rows and answer sooner, and need a refresh of its own.

What keeps it current is the refresh. Each one reads every trip again:

Materialized viewRowsSizeBuildRefreshRefresh concurrently
trips_hourly1,157,581153 MiB9,171.5 ms7,855.1 ms10,819.7 ms
dropoffs_hourly713,45791 MiB6,794.4 ms6,934.4 ms9,320.0 ms

Build is the CREATE and its index; each refresh time is the median of three. A plain refresh locks the materialized view, so asks wait for it; a concurrent one lets them read the old rows and takes longer. Between refreshes every answer is as old as the last refresh’s start, and the server pays a refresh’s read of every trip each time, whether a trip changed or not. Straum applies a commit in milliseconds (Transactions), and an ask after it reads the change.

The rows match the cells Straum keeps at its hour width (The views). The two materialized views took 245 MiB on disk with their indexes; Straum held 201 MiB in memory in the same run, both views with every measure, the fares’ counts per value included.

Running it yourself

just taxi

It needs Docker, a Rust toolchain, just and uv. The recipe runs bench/taxi.py. The first run downloads the six months into bench/data/, which git ignores. Then it builds Straum, starts a throwaway postgres:18 (or another major, as just postgres=17 taxi picks), loads the months with bench/load_taxi_trips.py, runs the SQL straum plan prints and starts straum run. Last, it sends each ask to both sides and stops at the first answer that differs.

Answers are equal when every decimal matches to the last digit, with PostgreSQL’s avg, variance and standard deviation rounded half to even at the places Straum gives them. A run takes about 80 seconds once the data is there.

The recipe has four modes, each after the same setup. just taxi or just taxi asks gives the Results. just taxi materialized builds and refreshes the materialized views, then asks all three sides (Against a materialized view). just taxi transactions runs one transaction of 1,000 to 1,000,000 changed rows while a client asks Straum back to back (Transactions). just taxi shell opens straum shell at the trips in place of the asks; leaving the shell removes PostgreSQL.

Each mode takes wal=physical, as in just wal=physical taxi shell, to have Straum read the physical WAL in place of logical decoding. The script then turns full_page_writes back on after the load and takes a checkpoint, since the physical stream needs page images.

The views

bench/trips.sql holds two views. trips is the quick start’s view with more measures over the fare: variance, standard deviation, median, p99, mode, and the count, sum and average of distinct fares. It is what a dashboard over these trips would declare. dropoffs is the other end of the same trips: tips, the average distance and fares per hour and dropoff zone.

CREATE VIEW dropoffs AS
SELECT buckets(dropoffs.pickup_at, '1 hour', '1 day', '7 days') AS bucket,
       dropoffs.do_location_id AS do_location_id,
       dropoff.borough AS borough,
       count(*) AS trips,
       sum(dropoffs.tip_amount) AS tips,
       avg(dropoffs.trip_distance) AS avg_distance,
       sum(dropoffs.fare_amount) AS fare
FROM public.yellow_trips AS dropoffs
LEFT OUTER JOIN public.taxi_zones AS dropoff ON dropoff.location_id = dropoffs.do_location_id
GROUP BY 1, 2, 3;

Over the 20,332,093 trips, trips keeps 1,157,581 cells at its hour width and dropoffs 713,457. Neither keeps bound cells: each joins on one of its own keys, so bound cells would double them.

The asks

PostgreSQL gets the query anyone would write over the raw tables, in a session whose time zone is New York’s, as the TLC’s times are.

-- Trips
SELECT count(*) FROM yellow_trips;

-- Card trips
SELECT count(*) FROM yellow_trips WHERE payment_type = 1;

-- Trips by pickup borough
SELECT z.borough, count(*)
  FROM yellow_trips t
  LEFT JOIN taxi_zones z ON z.location_id = t.pu_location_id
 GROUP BY z.borough;

-- Fares by payment type
SELECT payment_type, count(*), sum(fare_amount), avg(fare_amount)
  FROM yellow_trips
 GROUP BY payment_type;

-- Fare spread by payment type
SELECT payment_type, var_samp(fare_amount), stddev_samp(fare_amount)
  FROM yellow_trips
 GROUP BY payment_type;

-- Median fare
SELECT percentile_disc(0.5) WITHIN GROUP (ORDER BY fare_amount) FROM yellow_trips;

-- p99 fare by payment type
SELECT payment_type,
       percentile_disc(0.99) WITHIN GROUP (ORDER BY fare_amount)
  FROM yellow_trips
 GROUP BY payment_type;

-- Most common fare by payment type
SELECT payment_type, mode() WITHIN GROUP (ORDER BY fare_amount)
  FROM yellow_trips
 GROUP BY payment_type;

-- Distinct fares by payment type
SELECT payment_type, count(DISTINCT fare_amount), sum(DISTINCT fare_amount),
       avg(DISTINCT fare_amount)
  FROM yellow_trips
 GROUP BY payment_type;

-- Median fare per hour, one day
SELECT date_trunc('hour', pickup_at),
       percentile_disc(0.5) WITHIN GROUP (ORDER BY fare_amount)
  FROM yellow_trips
 WHERE pickup_at >= '2024-01-17' AND pickup_at < '2024-01-18'
 GROUP BY 1;

-- Manhattan pickups, one week
SELECT count(*)
  FROM yellow_trips t
  JOIN taxi_zones z ON z.location_id = t.pu_location_id
 WHERE z.borough = 'Manhattan'
   AND t.pickup_at >= '2024-01-08' AND t.pickup_at < '2024-01-15';

-- Trips per hour, one day
SELECT date_trunc('hour', pickup_at), count(*)
  FROM yellow_trips
 WHERE pickup_at >= '2024-01-17' AND pickup_at < '2024-01-18'
 GROUP BY 1;

-- Trips per hour by borough, one month
SELECT date_bin('1 hour', t.pickup_at, timestamptz 'epoch'), z.borough, count(*)
  FROM yellow_trips t
  LEFT JOIN taxi_zones z ON z.location_id = t.pu_location_id
 WHERE t.pickup_at >= '2024-01-01T00:00:00Z' AND t.pickup_at < '2024-02-01T00:00:00Z'
 GROUP BY 1, 2;

-- Trips per day by borough, one month
SELECT date_bin('1 day', t.pickup_at, timestamptz 'epoch'), z.borough, count(*)
  FROM yellow_trips t
  LEFT JOIN taxi_zones z ON z.location_id = t.pu_location_id
 WHERE t.pickup_at >= '2024-01-01T00:00:00Z' AND t.pickup_at < '2024-02-01T00:00:00Z'
 GROUP BY 1, 2;

-- Fares per week
SELECT date_bin('7 days', pickup_at, timestamptz 'epoch'), count(*),
       sum(fare_amount)
  FROM yellow_trips
 WHERE pickup_at IS NOT NULL
 GROUP BY 1;

-- Tips by dropoff borough
SELECT z.borough, count(*), sum(t.tip_amount), avg(t.trip_distance),
       sum(t.fare_amount)
  FROM yellow_trips t
  LEFT JOIN taxi_zones z ON z.location_id = t.do_location_id
 GROUP BY z.borough;

Straum gets the same asks over the views, every value a parameter; bench/taxi.py holds both. Where the SQL has no range, the ask’s is 2000 to 2030, which holds every trip; Fares per week leaves its range open instead, so it reads every bucket Straum holds. An example:

-- Trips by pickup borough
SELECT borough, trips FROM trips
 WHERE bucket >= $1 AND bucket < $2
 GROUP BY borough

Transactions

Straum holds a transaction until its commit and applies it whole under its write lock: its rows wait in memory, and every ask waits for the apply. just taxi transactions updates the fare of the first N trips, which both views follow, in one transaction, while a client asks for one day of hour buckets as fast as the answers come. It measures the time from the commit until Straum has applied it, the longest ask meanwhile (the lock hold as a client feels it), and how much Straum’s resident set grew. After each transaction it checks the fares by payment type against PostgreSQL; an answer that differs ends the run.

One run on 2026-11-17, on the machine and PostgreSQL of the Results. synchronous_commit is back on once the trips are loaded, so a commit counts from its flush, as on a real server. Straum held 121 MiB after the load, and an idle ask took 204 µs.

Rows changedCommit to appliedLongest ask meanwhileMemory grown
1,00011.7 ms1.8 ms1 MiB
10,00093.3 ms12.4 ms3 MiB
100,000827.5 ms118.1 ms56 MiB
1,000,0008.5 s1,238.7 ms457 MiB

Most of the time goes to PostgreSQL decoding the transaction and Straum reading it, outside the lock. The lock itself is held for about 1.2 ms per 1,000 rows, half of it moving each changed fare between the percentiles’ value counts. Memory is what grows: the rows of a transaction wait in Straum until its commit, about 480 bytes each, so a million-row transaction holds nearly four times what both views do.

That sets the default of --max-transaction-rows at 100,000: a transaction at the limit holds the lock for 118 ms, and anything larger is cheaper to stop and load again, which takes the rows through the bulk COPY instead. The bench raises the limit out of the way, since it measures what the limit prevents.

Physical WAL

just wal-bench

It measures how fast Straum reads physical WAL.

It loads the taxi month with bench/load_taxi_trips.py, so it needs uv, into a PostgreSQL under wal_level = replica, takes a checkpoint and opens a physical replication slot. Four phases each change 1,000,000 trips of yellow_trips: COPY in transactions of 250,000 rows, then INSERT, UPDATE and DELETE in transactions of 10,000. The slot streams the WAL, and Straum keeps it in memory. Autovacuum is off and the checkpoint interval is an hour, so each run writes the same records. postgres picks the major, as in just postgres=17 wal-bench.

Straum then reads the captured WAL again, with no socket in the way, three times each way (just runs=6 wal-bench for six); the fastest read counts. “Records read” only splits pages into records. “Pipeline read” goes all the way to the commits for crates/straum-notation/tests/taxi.sql; every row changed must come out, and nothing may be unfit. “Pass-through read” goes through a pipeline that reads no table, as the WAL of every other table and database does. The reader skips those records by their block headers, without copying or checksumming them, so it outruns splitting every record.

One run on 2026-11-16, on the machine of the Results, one thread, PostgreSQL 18, six reads each way:

PhaseWALRecordsImagesPostgreSQL wroteRecords readPipeline readRows/sAgainst PostgreSQLPass-through read
copy128.1 MiB1,044,744101.6 s2,989 MiB/s525 MiB/s4,100,2086.4x7,411 MiB/s
insert173.3 MiB2,033,14831.1 s2,100 MiB/s538 MiB/s3,104,6313.4x5,386 MiB/s
update356.9 MiB3,008,77413,4472.3 s2,332 MiB/s538 MiB/s1,507,1473.5x6,401 MiB/s
delete137.7 MiB1,010,91110,712480.2 ms2,977 MiB/s457 MiB/s3,321,7731.6x5,945 MiB/s
all795.9 MiB5.4 s2,452 MiB/s520 MiB/s2,613,4593.5x6,200 MiB/s

Images are full-page images. “Against PostgreSQL” divides the time PostgreSQL took to write a phase’s WAL by the time the pipeline took to read it. Below 1x, a writer that keeps that pace for long leaves Straum behind, and once the lag passes --max-lag, /readyz turns off. The pipeline held at most 429.5 MiB of rows, most of them the open COPY transactions’ rows, which wait for their commit.

Timings drift with the machine, so two tests in crates/straum-pg/src/wal/pipeline/tests.rs hold what this bench gained by counting allocations instead: a row of a spec table may allocate three times, for its page’s slot list, its bytes and its decoded values, and a row of another table allocates nothing.

Memory

Memory follows cells, and the rollup key, the columns in GROUP BY, decides how many there are.

Two runs on 2026-11-11 measure it: the taxi month under a wide key, and a warehouse’s tables under a narrow one whose dims carry the ids. The resident set came to 177 and 104 bytes a cell, measures and projections included, before bound cells.

A cell has taken fewer bytes since (ADR-0003). The benchmark’s two views held 65 MiB for their 2,078,586 cells, 33 bytes a cell, before trips kept its fares for the percentiles; with them, 113 MiB on 2026-11-15. With the measures the Results add, they held 305 MiB on 2026-11-19, then 202 MiB on 2026-11-20 once the distinct values read the percentiles’ counts.

The taxi month under a wide key

just taxi-month

It loads the month with bench/load_taxi_trips.py, so it needs uv, and reads it with crates/straum-notation/tests/taxi.sql, a wider view than the benchmark’s: 15 minute buckets with day and week widths, keyed by payment type, vendor, pickup zone, dropoff zone and the pickup zone’s borough, zone and service zone, with two filtered counts.

The test compares asks with the view body in PostgreSQL six times: after the load, after 200 streamed commits, after an update, after a zone is renamed, after a zone moves to a new key, and after a trip in the renamed zone changes. Nothing stops. Release build, Docker on the same laptop:

Step or askGroupsStraumPostgreSQL
Load2.0 s
200 streamed commits5.1 s
A zone renamed, one commit2.4 ms
A zone moved to a new key, one commit2.1 ms
A trip in the renamed zone, one commit2.4 ms
Every key2,322,783 to 2,329,7152.7 to 3.2 s6.3 to 6.4 s
By pickup borough811.3 to 16.3 ms4.1 to 4.3 s

The ask over every key reads every 15 minute cell, maps each through the zones’ projection and answers nearly as many groups, so it is only 2.0 to 2.4 times faster than the view in PostgreSQL.

Cells per width, each a count(DISTINCT ...) of that key and the bucket over the month:

RollupCellsTrips a cell
Raw trips2,964,6241.0
15 minutes2,322,7831.3
1 hour1,685,7311.8
15 minutes, no dropoff zone568,6125.2
1 day519,7265.7
7 days199,39814.9

Pickup and dropoff zone together are nearly unique per trip, so this spec collapses little at 15 minutes; without the dropoff zone it collapses 5.2 times.

A warehouse’s tables

The view keys tasks by organization, whether the task is live, its group’s category and its storage location’s type, over hour buckets with a day width beside them. The category and the type are columns of two dims, so the cells are keyed by the group and location ids, and Straum holds each dim’s projection beside them: its key and the one column the view reads.

The tables are a copy of a production database and are not in the repository: 13,116,878 tasks, 5,690,651 task groups and 851,964 storage locations, 2,645 MiB of tasks in PostgreSQL. The machine and build are those of the Results.

RollupCells
1 hour11,932,307
1 day11,930,678

A group holds one task or two, and every task has its own hour, so both widths hold about a cell a task. The day width collapses nothing, since the group id is in its key. Keyed by the category and the type instead, as a view that never followed a dim change could be, the widths would hold 311,969 and 66,107 cells.

Straum was ready 10 s after it started and held 2,378 MiB: the cells and the two projections, 6,542,615 dim rows. A run right before held 1,998 MiB. That is 88 to 104 bytes a cell, projections included.

Every ask equalled PostgreSQL after the load and after each streamed change. Each change is one transaction; the time runs from the commit until Straum had applied it:

ChangeRowsApplied
New tasks for one organization, completed now1,00099 ms
Open tasks completed, one in fifty19,0245.9 s
Completed tasks of one day cancelled, one in twenty1,873111 ms
Tasks of one day deleted, one in thirty7,42695 ms
Task groups of one day recategorised3,365208 ms
Storage locations retyped, one in ten85,1961.1 s
Task groups deleted, one in a hundred56,8753.8 s

The last three change dims: each is applied to the projection, no cell moves, and the next ask reads the new category or type. Straum never stopped.

The asks, with PostgreSQL run twice on the loaded tables and Straum the better of two:

AskRowsPostgreSQL, firstPostgreSQL, secondStraum
Picks by organization, one day4433 ms15 ms0.9 ms
Picks by organization and category, one week1101,448 ms751 ms89.2 ms
Live picks by location type, one day3127 ms100 ms6.7 ms
Picks per hour for one organization, one day1614 ms5 ms0.6 ms

PostgreSQL has an index on completed here, and the SQL is the plain queries the asks mirror, not a dashboard’s own. Straum reads the cells of one width in the range, about a cell a task, and maps each through the projections, so an ask over a week costs more than one over a day.

Every rule of a spec, every ask and endpoint and every command and flag are in the reference.