| From: | "Kim, Andrew" <andrew(dot)kim(at)intel(dot)com> |
|---|---|
| To: | "pgsql-hackers(at)lists(dot)postgresql(dot)org" <pgsql-hackers(at)lists(dot)postgresql(dot)org> |
| Cc: | "tomas(at)vondra(dot)me" <tomas(at)vondra(dot)me>, "jakub(dot)wartak(at)enterprisedb(dot)com" <jakub(dot)wartak(at)enterprisedb(dot)com>, "greg(at)burd(dot)me" <greg(at)burd(dot)me>, "andres(at)anarazel(dot)de" <andres(at)anarazel(dot)de>, "a(dot)makhmutov(at)postgrespro(dot)ru" <a(dot)makhmutov(at)postgrespro(dot)ru> |
| Subject: | Re: Adding basic NUMA awareness |
| Date: | 2026-12-04 22:56:12 |
| Message-ID: | DS4PR11MB6754432B371F0FC03A85AADDC2854A2@DS4PR11MB675443.namprd11.prod.outlook.com |
| Views: | Whole Thread | Raw Message | Download mbox | Resend email |
| Thread: | |
| Lists: | pgsql-hackers |
Hi all,
I would like to contribute measurements of NUMA placement effects on
multi-node machines, responding to the question in this thread of what
master should be benchmarked against on such hardware. Thanks to Tomas
for the series, to Jakub for the benchmark scripts and the CPU-less node
analysis, and to Greg for the postmaster pinning observation, which the
results below reproduce.
These are measurements of unmodified PostgreSQL 18.4, not of this
series. Confinement is applied with numactl, or with an equivalent
affinity call before the first fork, which measured the same throughput.
Three machines: machine A is 2 sockets / 384 threads with 6 NUMA nodes,
about 500 GB per node, node distances 10 local, 15/17 within a socket
and a uniform 29 across, NIC on node 0. Machine B is 1 socket / 192
threads, 3 nodes, 257 GB per node, so no cross-socket link. Machine C is
an AWS r8i.96xlarge, 2 sockets / 384 threads, 6 nodes, 508 GB per node,
where the cross-socket distances are 21-28 rather than uniform.
Compilers differ per machine, so only within-machine comparisons are
meaningful.
HammerDB TPROC-C and pgbench, driver always on a separate host, 2 or 3
runs per arm with the arm order rotated so no arm is systematically
later in a campaign, kernel NUMA balancing enabled, WAL on tmpfs, no
checkpoints inside the measurement windows, and the reported measurement
interval checked against wall-clock on every run.
pgbench -S on machine C, scale 2000, 29 GB against 32 GB
shared_buffers so the set is resident and storage drops out, 30 s runs,
3 runs per point, in tps:
Clients 6 nodes 2 nodes of one socket
------- ------- ---------------------
128 226,809 223,008
256 455,197 458,953
512 857,113 931,240
1024 828,913 1,762,649
Below 512 clients placement does not matter; all six arms tried are
within 2% of each other. At 1024 clients the 6-node server returns less
than it did at 512, with a 23% spread across runs, while the confined
one roughly doubles at a 1% spread. On machine A, HammerDB TPROC-C at
256 virtual users gives +121.2% at 250 warehouses and +115.7% at 1536
warehouses, so on that machine the effect is not an artifact of a
dataset that fits in shared buffers.
The variable is the socket boundary rather than the node count. Eight
node sets on machine A, stock server, numactl only, mean NOPM:
Nodes Span NOPM vs unconfined
----- ---- ---- -------------
1,2 one socket, no NIC 2,472,576 +112.2%
0,1 one socket, NIC 2,350,448 +101.7%
0 one node 2,183,527 +87.4%
0,1,2 one socket, all 2,035,681 +74.7%
0,1,2,3 two sockets 1,401,627 +20.3%
0,3 two sockets 1,223,814 +5.0%
none unconfined 1,165,415 -
0,1,2,3,4,5 two sockets, all 1,123,628 -3.6%
Everything inside one socket lands at 2.04-2.47M and everything spanning
two lands at 1.12-1.40M. Nodes 0,3 against nodes 0,1 is the clearest
case: same node count, same 128 threads, 1.92x apart. Adding the 64
threads of a node across the boundary is negative, 0,1,2 to 0,1,2,3
being -31.1%. An explicit 6-node set is no better than no policy.
CPU and memory placement separate cleanly. Machine A, node set 1,2:
Policy NOPM vs unconfined
------ ---- -------------
--cpunodebind=1,2 --membind=1,2 2,448,935 +110.1%
--cpunodebind=1,2 only 2,420,414 +107.7%
--membind=1,2 only 1,102,146 -5.4%
none 1,165,415 -
The memory-only arm's -5.4% is inside its own 10.3% run-to-run spread,
so that arm is indistinguishable from applying no policy rather than
worse than it. With the CPUs confined and no memory policy at all,
first-touch placed 68%/31% of the pages across that pair by itself. The
memory-only arm is the worst arrangement, backends spread over 6 nodes
with memory on one, and its WALInsert share of waits returns to 51-54%
against 32-34% for the CPU arms.
Profiling that comparison on machine A, unconfined against nodes 1,2,
with perf stat TopdownL1 and VTune memory-access in separate passes
because they contend for the PMU, 60 s inside the window:
Metric 6 nodes nodes 1,2
------ ------- ---------
Interconnect single-link utilization 14.1% 0.000%
DRAM Bound, % of clockticks 20.8% 10.7%
Local memory access count 401M 3,501M
Cycles per transaction 10.77M 8.14M
Instructions per transaction 5.56M 5.27M
Backend bound 66.6% 45.6%
Remote DRAM access per transaction 1.519 0.854
Remote HITM per transaction 0.561 0.531
Cycles per transaction fall 24% while instructions fall 5%, so this
removes stalls rather than work. No memory controller exceeded 12% of
its peak bandwidth in any configuration measured, and cache-to-cache
transfers per transaction barely move, while remote DRAM accesses fall
44% and DRAM Bound halves. The cost is remote memory latency more than
coherence traffic on contended lock words, which is what I had assumed
before measuring. On this topology perf c2c's notion of remote appears
to be cross-node rather than cross-socket, since the confined arm still
shows substantial remote HITM while interconnect utilization is zero,
so I do not read that row as a socket boundary.
Placement also moves which lock is the bottleneck. Share of LWLock wait
time on machine A: unconfined is WALInsert 94.1%, WALWrite 5.1%,
ProcArray 0.6%; confined to nodes 1,2 it is WALInsert 77.2%, WALWrite
20.9%, ProcArray 0.8%. ProcArray did not exceed 5.1% in any arm,
including arms with 64 insertion locks. Correcting placement partly
relieves WALInsert on its own, and what it exposes is the WAL flush
path.
A single socket is not a null, which I had expected it to be. Machine B,
3 nodes, HammerDB, mean NOPM: all 3 nodes unconfined 1,632,465 at 45.6%
busy; nodes 0,1 2,214,682 at 46.3% busy, +35.7%; node 1 alone 1,928,581
at 28.8% busy, +18.1%. The within-socket component looked small on
machine A because that machine was only 15-22% busy at its operating
point, while machine B is at 46%. The effect scales with load, which is
what contention rather than bandwidth predicts.
The NIC's node does not generalize, and I would caution against making
it a rule. Excluding it was 5.2% better on machine A; including it was
6.0% better on machine B.
On pinning, one result may be useful. I tried a dynamic scheme in which
the postmaster watches load in ServerLoop() and widens its own CPU
affinity from one node to two once it sees many backends. It logged
success and the postmaster's mask did widen, but throughput was 19.4%
below applying the same policy once before the first fork. Sampling
masks inside the measured window showed 265 of 266 backends still
holding the single-node mask inherited at fork, because
sched_setaffinity() affects only the calling process. With a connection
pool there are no new backends after ramp-up, so the widening reached
nothing that mattered. That scheme also scaled measured CPU utilization
by total CPUs over active-node CPUs using the intended node set as the
denominator, so with the work really on 64 threads it reported about 41%
while that node was near 90% saturated, below its own 70% expansion
threshold: the actuator failure fed back into the sensor and froze the
loop. Two conclusions: decide placement before the first fork or per
backend at fork time rather than later from the postmaster, and do not
infer backend placement from the postmaster's mask. This agrees with
Greg's figures of -7.5% unpinned becoming +1.27% with the postmaster
pinned.
What remains unverified: all the above is PostgreSQL 18.4 rather
than master, one OLTP workload plus pgbench -S, Intel parts only, and
socket 1 of machine A was never tested alone.
I can run v20261023 on any of these machines, master both with and
without numactl --interleave=all. The comparison I would most like to
see is whether the pool partitioning still pays once the instance is
confined, since 0002 and 0003 assume an instance spanning every node.
Separately, I have a patch adding one PGC_POSTMASTER parameter,
numa_nodes, which restricts the postmaster's CPU affinity to the CPUs of
a list of nodes before the first child is forked, so children inherit
it. It is 368 insertions of which 72 lines are executable, it sets no
memory policy, and it is empty by default. It uses
numa_run_on_node_mask(), which honours an enclosing cpuset rather than
overriding it, and numa_parse_nodestring(), so the syntax is numactl's
and a node outside the permitted set is a startup error rather than
silently dropped. That addresses the request in this thread that
externally applied masks be respected, and it could feed the node set
that BufferPartitionsCalcuate() currently infers from
numa_num_configured_nodes(), which would cover the CPU-less node case
without auto-detection. It deliberately has no automatic node selection:
the data says two nodes of one socket is best on these machines but not
why two, and the only rule the data supports is not to span sockets.
In fairness, the same throughput is available today by starting the
server under numactl. In five head-to-head comparisons on three machines
the two were indistinguishable, the largest gap being 1.6% and inside
both arms' run-to-run spread. What the parameter adds is that placement
is stated with the rest of the configuration, visible in pg_settings,
validated against the running topology at startup, and applied however
the server is started. That is a manageability argument rather than a
performance one.
I have attached it for reference rather than as a proposed addition to
the series. If an attachment in this thread interferes with CFBot's
testing of commitfest entry 6049, say so and I will withdraw it and post
it in a separate thread with its own entry.
I would appreciate guidance on which configurations to run, and whether
the confined-instance comparison above is worth adding to the series'
own benchmarks.
Regards,
Andrew Kim
| Attachment | Content-Type | Size |
|---|---|---|
| v1-0001-Add-numa_nodes-to-restrict-the-server-to-a-set-of-NUMA-nodes.patch | application/octet-stream | 20.9 KB |
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Tatsuo Ishii | 2026-12-04 22:58:12 | Re: Row pattern recognition |
| Previous Message | Masahiko Sawada | 2026-12-04 22:03:45 | Re: Streamed transactions lose replication origin when first change is not a row change |