Skip to content

fix: in microbench, hash LRU caches with fixed seed - #2008

Open
jkaczman wants to merge 1 commit into
mainfrom
jk-bench-lru-fixed-seed
Open

jkaczman wants to merge 1 commit into
mainfrom
jk-bench-lru-fixed-seed

Conversation

@jkaczman

Copy link
Copy Markdown
Contributor

Follow up work to try to improve accuracy of microbench instructions in reference to #2003 seeing a +1.54% increase for a measure that shouldn't have been affected by that PR.

After some investigation, this seems to be because our LRU caches hash with foldhash, which builds a hash seed from code addresses (as a source of randomness). My guess is that this can change the order that we free cache entries in, and with that differs the work of all subsequent malloc calls.

Reference to their code that does this: https://github.com/orlp/foldhash/blob/77d8e3dae0d43abe65753e888b9e74efbe4ee3f7/src/seed.rs#L150-L156

Now, in the microbench, the LRU caches hash with a fixed seed (via foldhash::fast::FixedState, which they recommend for determinism).

This doesn't affect production builds.

@codecov

codecov Bot commented Nov 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Comment thread pgdog/Cargo.toml
bench = []

[dependencies]
foldhash = { version = "0.2", default-features = false }

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could make it conditional, i.e., only if bench feature is enabled. Although LLVM will probably remove it anyway during compilation / dead code elimination.

@github-actions

Copy link
Copy Markdown
Contributor

Metal bench (arm64) passed. All 475 measures within bounds.

suite throughput cpu/txn user cycles/txn user instr/txn kernel cycles/txn kernel instr/txn ctx/txn
pooler 19.65 (-0.6% ± 1.4%) 19,416 (-1.3% ± 0.8%) 32,015 (+0.0% ± 0.04%) 31,180 (-0.2% ± 3.0%) 50,961 (+0.3% ± 0.5%)
lb 20.46 (-0.3% ± 1.8%) 20,141 (-0.2% ± 1.0%) 32,911 (+0.0% ± 0.04%) 32,371 (-0.3% ± 3.4%) 52,107 (+0.0% ± 0.4%)
sharding-w2 33.49 (+0.3% ± 2.7%) 45,322 (-0.0% ± 2.3%) 97,446 (+0.0% ± 0.04%) 42,176 (+0.9% ± 4.2%) 53,584 (-0.0% ± 0.2%) 1.532 (-0.2% ± 0.5%)
sharding-w8 240,426 (+1.7% ± 2.0%) 29.89 (-2.0% ± 2.1%) 45,329 (-1.1% ± 2.0%) 52,993 (-0.0% ± 0.1%) 37,308 (-3.0% ± 2.2%) 42,390 (+0.1% ± 0.05%) 0.165 (+2.7% ± 0.5%)
Counters per txn
suite frontend stall l1i refill backend stall
pooler 8,992 (-3.7% ± 2.0%) 2,806 (-1.6% ± 1.1%)
lb 9,493 (-1.5% ± 2.1%) 2,882 (-0.7% ± 1.1%)
sharding-w2 19,697 (+0.1% ± 5.7%) 4,323 (+0.2% ± 3.9%)
sharding-w8 21,497 (-2.5% ± 2.7%) 4,335 (-0.5% ± 1.7%)

Microbench: all 462 measures within bounds.

Hot code per txn
path base head change
pooler 113.1 KB 112.6 KB -0.5 KB
sharding-w2 166.8 KB 165.5 KB -1.3 KB

pooler:

crate base head change
pgdog::frontend::client::query_engine 19.8 KB 20.0 KB +0.2 KB
tokio 18.5 KB 18.8 KB +0.2 KB
pgdog::backend::pool 17.6 KB 17.6 KB +0.0 KB
aws-lc (TLS crypto) 10.4 KB 10.2 KB -0.2 KB
rustls (TLS) 8.4 KB 8.4 KB -0.1 KB
pgdog::frontend (other) 8.0 KB 8.0 KB +0.0 KB
pgdog::backend::server 7.1 KB 7.2 KB +0.1 KB
other 6.6 KB 6.5 KB -0.1 KB
everything else 16.6 KB 15.9 KB -0.8 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 5.6 KB +0.0 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 5.4 KB +0.0 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.0 KB +0.1 KB
tokio::runtime::task::raw::poll 3.2 KB +0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 3.0 KB +0.1 KB

sharding-w2:

crate base head change
pgdog::frontend::router 28.8 KB 28.8 KB +0.0 KB
pgdog::frontend::client::query_engine 21.1 KB 20.9 KB -0.2 KB
pgdog::backend::pool 18.1 KB 18.4 KB +0.4 KB
tokio 18.9 KB 18.4 KB -0.4 KB
aws-lc (TLS crypto) 13.2 KB 13.1 KB -0.2 KB
other 9.8 KB 9.6 KB -0.2 KB
pgdog::frontend (other) 8.8 KB 8.6 KB -0.2 KB
rustls (TLS) 8.1 KB 8.4 KB +0.2 KB
everything else 40.0 KB 39.3 KB -0.7 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 6.0 KB -0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 5.3 KB -0.1 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.1 KB -0.1 KB
pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que 3.5 KB +0.2 KB
tokio::runtime::task::raw::poll 3.1 KB -0.1 KB
lb flamegraph vs 81a9f08

lb

Open interactive for hover, zoom and search.

lb removed

Open interactive.

microbench flamegraph vs 81a9f08

microbench

Open interactive for hover, zoom and search.

microbench removed

Open interactive.

pooler flamegraph vs 81a9f08

pooler

Open interactive for hover, zoom and search.

pooler removed

Open interactive.

sharding-w2 flamegraph vs 81a9f08

sharding-w2

Open interactive for hover, zoom and search.

sharding-w2 removed

Open interactive.

sharding-w8 flamegraph vs 81a9f08

sharding-w8

Open interactive for hover, zoom and search.

sharding-w8 removed

Open interactive.

Logs

lb, microbench, pooler, sharding-w2, sharding-w8, verdict.json

Compared 13b6db7 with 81a9f08 on m8g.metal-24xl (spot).

@github-actions

Copy link
Copy Markdown
Contributor

Metal bench (x86) passed. All 475 measures within bounds.

suite throughput cpu/txn user cycles/txn user instr/txn kernel cycles/txn kernel instr/txn ctx/txn
pooler 25.93 (+0.3% ± 0.2%) 19,167 (+0.6% ± 0.10%) 33,948 (-0.0% ± 0.1%) 33,317 (+0.3% ± 0.4%) 36,534 (+0.1% ± 0.8%)
lb 26.31 (+0.2% ± 0.2%) 19,660 (+0.6% ± 0.1%) 34,932 (+0.1% ± 0.07%) 33,429 (+0.1% ± 0.3%) 37,306 (+0.4% ± 0.4%)
sharding-w2 42.01 (+0.1% ± 1.2%) 47,516 (+0.1% ± 0.8%) 101,365 (-0.0% ± 0.07%) 38,067 (+0.2% ± 1.7%) 40,189 (-0.0% ± 0.1%) 1.528 (-0.2% ± 0.6%)
sharding-w8 207,984 (-0.2% ± 0.4%) 32.73 (+0.2% ± 0.7%) 45,625 (+0.2% ± 1.5%) 55,678 (+0.0% ± 0.05%) 31,204 (+0.1% ± 0.5%) 32,504 (+0.0% ± 0.07%) 0.1721 (-0.1% ± 2.6%)
Counters per txn
suite frontend stall l1i refill backend stall
pooler 3,875 (+3.6% ± 0.6%) 1,208 (+1.6% ± 0.6%) 36,860 (-0.3% ± 0.5%)
lb 3,982 (+3.5% ± 0.8%) 1,236 (+1.2% ± 1.2%) 37,737 (-0.3% ± 0.6%)
sharding-w2 6,582 (-5.1% ± 0.9%) 1,676 (-0.2% ± 0.9%) 112,486 (+2.2% ± 2.4%)
sharding-w8 3,592 (-2.9% ± 0.8%) 1,030 (-0.2% ± 1.4%) 170,747 (+0.7% ± 2.6%)

Microbench: all 462 measures within bounds.

Hot code per txn
path base head change
pooler 111.3 KB 111.2 KB -0.1 KB
sharding-w2 164.6 KB 165.0 KB +0.4 KB

pooler:

crate base head change
pgdog::frontend::client::query_engine 21.0 KB 21.1 KB +0.1 KB
tokio 18.4 KB 18.6 KB +0.2 KB
pgdog::backend::pool 18.5 KB 18.1 KB -0.4 KB
pgdog::frontend (other) 9.4 KB 9.5 KB +0.1 KB
aws-lc (TLS crypto) 8.9 KB 8.8 KB -0.1 KB
rustls (TLS) 7.9 KB 7.9 KB +0.0 KB
pgdog::backend::server 7.0 KB 7.0 KB +0.0 KB
other 6.0 KB 5.9 KB -0.1 KB
everything else 14.2 KB 14.4 KB +0.2 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 7.3 KB +0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 6.1 KB +0.0 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 5.0 KB +0.2 KB
tokio::runtime::task::raw::poll 3.6 KB -0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 3.1 KB -0.2 KB

sharding-w2:

crate base head change
pgdog::frontend::router 28.6 KB 28.9 KB +0.3 KB
pgdog::frontend::client::query_engine 22.4 KB 22.2 KB -0.1 KB
tokio 18.2 KB 18.8 KB +0.6 KB
pgdog::backend::pool 18.6 KB 18.6 KB +0.1 KB
other 10.2 KB 10.6 KB +0.4 KB
pgdog::frontend (other) 10.4 KB 10.6 KB +0.1 KB
aws-lc (TLS crypto) 10.4 KB 10.4 KB +0.0 KB
pgdog::backend::server 7.9 KB 7.8 KB -0.1 KB
everything else 38.0 KB 37.2 KB -0.8 KB
function head change
pgdog::frontend::client::Client::run::{{closure}} 8.1 KB +0.1 KB
pgdog::frontend::client::query_engine::query::<impl pgdog::frontend::client::query_engine: 6.1 KB +0.1 KB
pgdog::frontend::client::query_engine::QueryEngine::handle::{{closure}} 4.6 KB -0.1 KB
pgdog::frontend::router::parser::query::select::<impl pgdog::frontend::router::parser::que 4.3 KB +0.1 KB
tokio::runtime::task::raw::poll 4.2 KB +0.4 KB
lb flamegraph vs 81a9f08

lb

Open interactive for hover, zoom and search.

lb removed

Open interactive.

microbench flamegraph vs 81a9f08

microbench

Open interactive for hover, zoom and search.

microbench removed

Open interactive.

pooler flamegraph vs 81a9f08

pooler

Open interactive for hover, zoom and search.

pooler removed

Open interactive.

sharding-w2 flamegraph vs 81a9f08

sharding-w2

Open interactive for hover, zoom and search.

sharding-w2 removed

Open interactive.

sharding-w8 flamegraph vs 81a9f08

sharding-w8

Open interactive for hover, zoom and search.

sharding-w8 removed

Open interactive.

Logs

lb, microbench, pooler, sharding-w2, sharding-w8, verdict.json

Compared 13b6db7 with 81a9f08 on m7i.metal-48xl (spot).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants