-
Notifications
You must be signed in to change notification settings - Fork 868
[configuration] Allow to specify a list of CPUs to bind H2O to #2017
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
Conversation
|
Thank you for the PR. I think this is a nice enhancement. That said, I think we might want to consider extending Regarding listing the CPU cores, I think we might want to use a YAML sequence here. Just naming all the CPU core IDs in numbers could be fine, or if we want to support range expressions, we could support YAML expression like |
|
That's a good idea, thanks for suggesting it. IIUC,
Is that correct? |
`num-threads` will treat it as a list of CPUs to bind to, instantiation one thread per CPU.
kazuho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for the changes. I've read the code, I think the PR would be ready for merge once we resolve the issues below.
src/main.c
Outdated
| } | ||
| return 0; | ||
| InvalidSeq: | ||
| h2o_configurator_errprintf(cmd, node, "cpus must be specified as sequence of positive integers or a ranges low-high"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would appreciate it if you could generate more specific errors, by calling h2o_configurator_err_printf(cmd, node->data.sequence.elements + i, ...) within the loop.
That would provide users the actual location (i.e. line number and column number) where the error exists.
src/main.c
Outdated
| } | ||
| } | ||
| #else /* H2O_HAS_PTHREAD_SETAFFINITY_NP */ | ||
| fprintf(stderr, "[warning] ignoring CPU list, this platform doesn't support `pthread_setaffinity_np`\n"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we generate the error in on_config_num_threads? Then we can guide users how to address the issue.
src/main.c
Outdated
| *num_threads += 1; | ||
| (*cpu_list) = realloc(*cpu_list, sizeof(**cpu_list) * (*num_threads + 1)); | ||
| (*cpu_list)[*num_threads - 1] = cpu; | ||
| (*cpu_list)[*num_threads] = -1; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you concerned about having overruns here?
I ask this because, if you are concerned about that, then I might suggest doing a refactor. Replace conf.num_threads and conf.cpu_list with a H2O_VECTOR(int). The size of the vector indicates the number of threads, and each value of the vector indicates the CPU id (if non-negative) to be pinned to, or if it's not pinned (if -1). By taking that approach, there would be no fear of losing synchronization between num_threads and cpu_list, and you'd also be able to use things like h2o_vector_reserve.
I am not saying that we should make such change, but it's generally the case that I prefer avoiding having extra complexity for making the code "fail-safe."
array that maps threads to CPUs. - Have specific error messages - Error out in num-threads if pthread_setaffinity_np is not available
kazuho
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you very much for the changes, I like how isolated yet integrated the code that deal with the feature is.
Below are my refinement suggestions. Please let me know what you think.
[configuration] Allow to specify a list of CPUs to bind H2O to
|
Thank you for the changes. I've merged the PR with some tweaks. I believe that the changes are not disputable (mostly refactor and editorial changes), but please let me know if you have concerns. |
Changes look great to me, thank you. |
Modify
num-threadsto accept a sequence. If passed a sequence,num-threadswill treat it as a list of CPUs to bind to, instantiation one thread per CPU.