-
Notifications
You must be signed in to change notification settings - Fork 61
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
Builder pattern for creating control groups #5
Comments
It does look a lot cleaner! One thing I've noticed about the current API is that if you only set up You'll need a function for moving the current process into a cgroup as well. I'd do something like this for spawning commands: use std::process::Command;
use std::os::unix::process::CommandExt;
pub trait ComandCgroup {
fn cgroup(&mut self, &Cgroup) -> &mut Self;
}
impl CommandCgroup for Command {
fn cgroup(&mut self, cgroup: &Cgroup) -> &mut Self {
self.before_exec(|| {
unimplemented!()
})
}
} |
Yeah, lazily creating the controllers is on my TODO list (which I really really should convert into Issues here). Your suggestion for the trait seems great, I'll add that. BTW, the current state-of-the-art for the builder pattern is on |
@levex I would love to use the new API. Are there any roadblocks? Can I help with sorting them out? |
Hi @frol, great! No there aren't any. I just need to make a cargo release. I'll make one tomorrow, as I'm unable to do that from this machine. |
@levex I want to let you know that I ended up implementing my own
Here is what I, essentially, wanted (and built): let my_cgroup = cgroups_fs::CgroupName::new("my-cgroup");
let my_memory_cgroup = cgroups_fs::AutomanagedCgroup::init(&my_cgroup, "memory").unwrap();
use cgroups_fs::CgroupsCommandExt;
let output = std::process::Command::new("echo")
.arg("Hello world")
.cgroups(&[&my_memory_cgroup])
.output()
.expect("Failed to execute command");
println!(
"The echo process used {} bytes of RAM.",
my_memory_cgroup.get_value::<u64>("memory.max_usage_in_bytes").unwrap()
); |
cfs_quota can be set to -1 to indicate no limit Fixes: levex#5 Signed-off-by: bin liu <[email protected]>
I've started working on an API that looks like this:
Thoughts?
In particular, I'd prefer to leave out an API that adds a
pid
to the control group. That's racy and it might introduce subtle race conditions into applications depending on this crate. Instead, the API will likely include aninclude_command()
build that starts theCommand
in the control group. This would be done via a trait ideally, so people can extend it.The text was updated successfully, but these errors were encountered: