Skip to content

feat(utils): introduce utils crate with compio utilities #444

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

Closed
wants to merge 3 commits into from

Conversation

numinnex
Copy link
Contributor

@numinnex numinnex commented Jul 3, 2025

monoio has an utility module, one of the methods that it exposes is bind_to_cpu_set. It's a simple wrapper around nix crate with sched feature flag, that allows to pin thread to cpu cores.

This PR creates a compio-utils module, that exposes bind_to_cpu_set method (the code is identical to what monoio does).

If you don't feel like creating such module and would rather that not be part of compio feel free to close this PR, it's not a blocker for us rather a convenience.

@Berrysoft
Copy link
Member

Well, it seems that this functionality is independent to compio.

@numinnex
Copy link
Contributor Author

numinnex commented Jul 3, 2025

It is independent, but it's very common with thread per core runtimes to pin threads to individual cores. Both monoio and glommio have that utility method, that's why I thought maybe as part of API compatibility it would be nice to expose it directly and in the future use the utils crate for some extra stuff.

Right now, we have to take an external dependency in order to do that, where compio internally uses nix already, so it's just matter of proxying it.

@Berrysoft
Copy link
Member

I mean, as it is independent to runtime, it doesn't have to be in compio. It's OK just to be an independent crate. Furthermore, it seems that there already has been one: https://crates.io/crates/core_affinity

@numinnex
Copy link
Contributor Author

numinnex commented Jul 3, 2025

I mean, as it is independent to runtime, it doesn't have to be in compio. It's OK just to be an independent crate. Furthermore, it seems that there already has been one: https://crates.io/crates/core_affinity

Yeah core_affinity is what we are using right now as a replacement for monoio::utils::bind_to_cpu_set.

As I've said it's not a must have, but rather a convenience for us. Maybe the Dispatcher could use it as well and provide an flag in it's builder that allows to pin threads.

@Berrysoft
Copy link
Member

Yes, you mentioned dispatcher - I would prefer a PR for compio-dispatcher, adding functionality to pin cpu core for each worker thread.

@numinnex
Copy link
Contributor Author

numinnex commented Jul 3, 2025

So, just a builder flag in the dispatcher, No compio-utils and re-exporting it via compio for users ?

@Berrysoft
Copy link
Member

Acceptable:

  • Builder flag for compio-runtime.
  • Builder flag for compio-dispatcher.

Not recommended:

  • A crate with compio-* name but does nothing with compio.

@numinnex
Copy link
Contributor Author

numinnex commented Jul 3, 2025

Closing as #445 reworks the whole feature according to feedback from this PR.

@numinnex numinnex closed this Jul 3, 2025
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.

2 participants