Skip to content

Restore Server CPU affinity - #6226

Open
binaryfire wants to merge 2 commits into
swoole:6.1from
binaryfire:fix/server-cpu-affinity-runtime
Open

binaryfire wants to merge 2 commits into
swoole:6.1from
binaryfire:fix/server-cpu-affinity-runtime

Conversation

@binaryfire

Copy link
Copy Markdown
Contributor

open_cpu_affinity and cpu_affinity_ignore are still accepted and documented, but #5320 removed the code that applied them, so enabling them has had no effect since 6.0.

This restores the previous binding at the current startup points. Process-mode and base-mode event workers use the process affinity call, and reactor threads use pthread_setaffinity_np(). Thread-mode workers run in the reactor thread entry, so they are bound there instead of through the process call. Configurations that already enable open_cpu_affinity will bind workers and reactor threads again.

The regressions start a base-mode worker and a thread-mode worker with cpu_affinity_ignore set to [0] and check that each is bound to CPU 1.

Apply the existing Server CPU affinity settings at the current event-worker and reactor-thread startup boundaries. Keep thread-mode workers on the pthread path so process affinity is never applied to the entire threaded server process.
Verify that cpu_affinity_ignore selects the expected CPU for base-mode event workers and thread-mode workers. The regressions fail against the unchanged 6.1 branch because both workers retain the inherited affinity mask.
@codecov

codecov Bot commented Sep 11, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 68.75000% with 5 lines in your changes missing coverage. Please review.
✅ Project coverage is 86.22%. Comparing base (07606e5) to head (95c103c).

Files with missing lines Patch % Lines
src/server/reactor_thread.cc 66.66% 3 Missing ⚠️
src/server/master.cc 71.42% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##              6.1    #6226      +/-   ##
==========================================
- Coverage   86.24%   86.22%   -0.03%     
==========================================
  Files         110      110              
  Lines       16790    16806      +16     
  Branches     2980     2986       +6     
==========================================
+ Hits        14481    14491      +10     
- Misses       2309     2315       +6     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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