Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make CPU affinity used for CPU pinning configurable via json file #1136

Merged
merged 15 commits into from
Dec 18, 2024

Conversation

Raghav-NI
Copy link
Contributor

@Raghav-NI Raghav-NI commented Dec 3, 2024

What does this Pull Request accomplish?

We want to configure cpu affinity used for cpu pinning for different process configurable via json file.

Why should this Pull Request be merged?

  1. User-Configurable CPU affinity:

    • Users can explicitly assign processor for:

      • Sideband stream read/write thread
      • Stream write threads
    • Why?

      • Some systems have more CPUs available, while others have fewer CPUs with shared workloads.
      • Configurability allows users to optimize CPU usage based on their system constraints or dedicated tasks.
      • It gives users control to explicitly decide how resources are distributed rather than relying on the scheduler.
  2. Default Behavior: "No Affinity" (-1):

    • By default, threads are not pinned to any specific CPU, allowing the OS scheduler to decide the CPU assignment
      dynamically.
  3. Separate CPU Cores for Critical Threads:

    • Users can assign separate CPU cores for non- sideband threads, sideband-read/write, and server threads.

    • Why?

      • To isolate performance-critical sideband operations (e.g., low-latency tasks) from server threads to minimize contention.
      • Separating cores ensures better performance for threads that are sensitive to cache invalidation, refreshes, or CPU contention.
  • Best Practices for configuration:

    • Use Default (-1): For general systems where CPU pinning is unnecessary, default "no affinity" provides broad compatibility.
    • Assign Dedicated Cores: On systems with more CPUs, pin performance-critical threads (e.g., sideband tasks) to isolated cores.
    • Avoid Contention: Separate sideband and server threads onto different cores to reduce interference, particularly for real-time or low-latency workloads.

What testing has been done?

I am able to build grpc-server and run it successfully with and without cpu pinning configuration in json file.

@Raghav-NI Raghav-NI changed the title Make CPU cores used for CPU pinning configurable via json file Make CPU used for CPU pinning configurable via json file Dec 3, 2024
@Raghav-NI Raghav-NI changed the title Make CPU used for CPU pinning configurable via json file Make cores used for CPU pinning configurable via json file Dec 3, 2024
source/config/localhost_config.json Outdated Show resolved Hide resolved
source/config/localhost_config.json Outdated Show resolved Hide resolved
@Raghav-NI Raghav-NI requested a review from asumit December 5, 2024 11:07
@Raghav-NI Raghav-NI changed the title Make cores used for CPU pinning configurable via json file Make CPU affinity used for CPU pinning configurable via json file Dec 6, 2024
@Raghav-NI Raghav-NI requested a review from doshirohan December 6, 2024 06:22
@Raghav-NI Raghav-NI marked this pull request as ready for review December 6, 2024 06:22
source/server/server_configuration_parser.cpp Outdated Show resolved Hide resolved
@Raghav-NI Raghav-NI requested a review from maxxboehme December 10, 2024 12:09
Copy link
Collaborator

@astarche astarche left a comment

Choose a reason for hiding this comment

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

Please respond to questions about server affinity and the high level question about clarifying the purpose/priorities for this change. Also consider that this PR is the first-pass documentation for HOW to use the feature, so include details about best practices for config.

source/server/core_server.cpp Outdated Show resolved Hide resolved
source/server/data_moniker_service.cpp Outdated Show resolved Hide resolved
source/config/localhost_config.json Outdated Show resolved Hide resolved
source/config/localhost_config.json Outdated Show resolved Hide resolved
@christag-ni
Copy link
Contributor

We are planning to create a release branch on the 18th, and your PR will need to be completed before then for the changes to be in effect. Do you want these changes included in this release?

@Raghav-NI
Copy link
Contributor Author

Raghav-NI commented Dec 16, 2024

We are planning to create a release branch on the 18th, and your PR will need to be completed before then for the changes to be in effect. Do you want these changes included in this release?

Yes, I was on leave, will be resolving comments and this PR should be completed today (17th Dec).

@Raghav-NI
Copy link
Contributor Author

Raghav-NI commented Dec 17, 2024

Please respond to questions about server affinity and the high level question about clarifying the purpose/priorities for this change. Also consider that this PR is the first-pass documentation for HOW to use the feature, so include details about best practices for config.

Addressed all the questions and updated PR description.

@Raghav-NI Raghav-NI requested a review from astarche December 17, 2024 12:28
source/server/data_moniker_service.cpp Outdated Show resolved Hide resolved
source/server/data_moniker_service.cpp Outdated Show resolved Hide resolved
source/server/data_moniker_service.cpp Outdated Show resolved Hide resolved
source/server/data_moniker_service.cpp Outdated Show resolved Hide resolved
source/server/data_moniker_service.cpp Outdated Show resolved Hide resolved
@Raghav-NI Raghav-NI requested a review from asumit December 18, 2024 11:24
Copy link
Contributor

@doshirohan doshirohan left a comment

Choose a reason for hiding this comment

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

I have commented only in few places, but anywhere you are using "stream processor" replace with "cpu affinity", "cpu affinity configuration" or equivalent. "stream processor" sounds like something that is responsible for processing streams.

source/config/localhost_config.json Outdated Show resolved Hide resolved
source/server/moniker_stream_processor.h Show resolved Hide resolved
source/server/data_moniker_service.cpp Outdated Show resolved Hide resolved
source/server/server_configuration_parser.cpp Show resolved Hide resolved
@Raghav-NI Raghav-NI requested a review from doshirohan December 18, 2024 14:14
@christag-ni
Copy link
Contributor

I'll be creating the release branch at 11:30 CST.

@reckenro reckenro dismissed stale reviews from astarche and maxxboehme December 18, 2024 17:13

Comments addressed and OOO rest of year.

@doshirohan doshirohan dismissed their stale review December 18, 2024 17:17

Sumit has reviewed and comments address

@Raghav-NI Raghav-NI merged commit a3d5698 into main Dec 18, 2024
10 checks passed
@Raghav-NI Raghav-NI deleted the users/rrawat/cpu_pinning branch December 18, 2024 17:19
doshirohan added a commit that referenced this pull request Dec 30, 2024
### What does this Pull Request accomplish?

For core server thread, there were hardcoded values for setting cpu affinity. This change removes that code.

### Why should this Pull Request be merged?

Earlier change which made some of the [cpu affinity settings configurable](#1136) through `server_config.json` left out making server thread pinning configurable because this code just sets affinity for main thread that launches server. This doesn't really change anything performance-wise apart from server launch time.

CPU pinning for main server thread was added when we added support for moniker based streaming and was taken as is from prototype branch for moniker streaming. This code is not needed.

### What testing has been done?

Build passes and able to launch grpc-device server
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.

7 participants