Skip to content

perf(parallelism): default the pool to physical cores, not SMT siblings - #2380

Open
ArthurZucker wants to merge 1 commit into
feat/train_encode_splitfrom
perf/physical-core-pool
Open

ArthurZucker wants to merge 1 commit into
feat/train_encode_splitfrom
perf/physical-core-pool

Conversation

@ArthurZucker

Copy link
Copy Markdown
Collaborator

Split out of #2361, which bundled it with the flat batch path. It is a change to pool
sizing and shares no code with that work, so it reviews and measures on its own.

available_parallelism() counts SMT siblings, and filling them costs throughput on this
encode path. Two workers on one physical core share a front-end and an L1, and this path
is branchy and L1i-hungry, so it feels that sharing more than most workloads do.

Capped by available_parallelism(), so a cgroup quota or an affinity mask still wins —
this only ever lowers the thread count, never raises it. set_num_threads still overrides.

Brings three tests, including parses_thread_siblings_lists, which is compiled everywhere
rather than only on Linux: the kernel writes thread_siblings_list as a list ("0,88"),
a range ("0-1"), or a mix ("0-1,4-5"), and a silent misparse would divide the pool
size by the wrong number on every box.

Numbers are in the commit message. I have not re-measured them — this is an extraction, not
a new claim, and I do not have the two machines they were taken on.

`num_threads()` defaulted to `available_parallelism()`, which counts SMT
siblings. Filling them costs throughput on the encode path: on medium
documents (~8 KiB) throughput peaks at the physical core count and then falls
off, -20% going 88 -> 176 threads on aarch64 and -47% going 128 -> 512 on a
two-socket Granite Rapids. Two workers on one physical core share a front-end
and an L1, and this path is branchy and L1i-hungry, so it feels that more than
most workloads do.

Default to physical cores instead, read from sysfs on Linux and sysctl on
macOS, and clamp to `available_parallelism()` so a cgroup quota or an affinity
mask still wins -- this only ever lowers the count. Platforms that will not
report a physical count keep the old behaviour. `set_num_threads()` still
overrides.

The sibling-list parser is compiled and tested on every platform, not just
Linux: a misparse there would divide the pool size by the wrong number
everywhere, and it is the only real logic here.

(cherry picked from commit e1cd411)
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.

1 participant