Skip to content

Conversation

@AntoinePrv
Copy link
Contributor

@AntoinePrv AntoinePrv commented Jul 21, 2025

Rationale for this change

We want the ThreadPool default capacity to follow the CPU affinity set by the user, if any.
For example:

$ python -c "import pyarrow as pa; print(pa.cpu_count())"
24
$ taskset -c 5,6,7 python -c "import pyarrow as pa; print(pa.cpu_count())"
3

What changes are included in this PR?

  • Implement and expose CPU affinity detection as a utility function in arrow/io_util.h; on non-Linux platform, it returns Status::NotImplemented
  • Use CPU affinity count, if available, to choose the default ThreadPool capacity

(note: based on original changes by Zihan Qi in PR #46034)

Are these changes tested?

By unit tests on CI, and by hand locally.

Are there any user-facing changes?

ThreadPool capacity now follows CPU affinity settings on Linux.

Comment on lines 533 to 536
Copy link
Contributor Author

@AntoinePrv AntoinePrv Jul 21, 2025

Choose a reason for hiding this comment

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

Moved from thread_pool.cc to standardize the detection of number of CPUs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The check was and is unused.

@github-actions github-actions bot added awaiting committer review Awaiting committer review and removed awaiting review Awaiting review labels Jul 21, 2025
@pitrou
Copy link
Member

pitrou commented Jul 21, 2025

Just a quick comment here (I'm about to leave on holiday): given that we would like to get rid of CpuInfo, we should put this functionality (affinity detection and concurrency detection) in util/io_util.h instead.

@AntoinePrv
Copy link
Contributor Author

Ha I understood from the previous discussion that this would remain the interface wrapping whichever underlying library.

@pitrou
Copy link
Member

pitrou commented Jul 21, 2025

It might indeed, but I'm not sure anything is settled in that regard. Affinity is also not really a CPU property.

@AntoinePrv AntoinePrv force-pushed the fix-cpu-affinity branch 2 times, most recently from 9625f9c to 44e198d Compare July 21, 2025 16:07
Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

Sorry for the delay @AntoinePrv , as I was on vacation.

Changes look good in principle, you'll find a set of minor comments and suggestions below.

@pitrou pitrou changed the title GH-45860: [C++] Reboot: Respect CPU affinity in cpu_count and ThreadPool default capacity GH-45860: [C++] Respect CPU affinity in cpu_count and ThreadPool default capacity Aug 19, 2025
@pitrou
Copy link
Member

pitrou commented Aug 19, 2025

I have checked locally that it works (Ubuntu 24.04):

$ python -c "import pyarrow as pa; print(pa.cpu_count())"
24
$ taskset -c 5,6,7 python -c "import pyarrow as pa; print(pa.cpu_count())"
3
$ OMP_NUM_THREADS=9 taskset -c 5,6,7 python -c "import pyarrow as pa; print(pa.cpu_count())"
9
$ OMP_THREAD_LIMIT=9 taskset -c 5,6,7 python -c "import pyarrow as pa; print(pa.cpu_count())"
3
$ OMP_THREAD_LIMIT=2 taskset -c 5,6,7 python -c "import pyarrow as pa; print(pa.cpu_count())"
2

@pitrou
Copy link
Member

pitrou commented Aug 19, 2025

@AntoinePrv Please don't mention usernames in the PR description, as they will end up in the final commit message and trigger annoying notifications later on.

Copy link
Member

@pitrou pitrou left a comment

Choose a reason for hiding this comment

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

+1, thanks for the update @AntoinePrv !

@pitrou
Copy link
Member

pitrou commented Aug 20, 2025

CI failure is unrelated.

@pitrou pitrou merged commit 8509ca4 into apache:main Aug 20, 2025
40 of 41 checks passed
@pitrou pitrou removed the awaiting committer review Awaiting committer review label Aug 20, 2025
@AntoinePrv AntoinePrv deleted the fix-cpu-affinity branch August 20, 2025 12:09
@conbench-apache-arrow
Copy link

After merging your PR, Conbench analyzed the 4 benchmarking runs that have been run so far on merge-commit 8509ca4.

There weren't enough matching historic benchmark results to make a call on whether there were regressions.

The full Conbench report has more details.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants