-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
using lxc_conf in start #79
Comments
This doesn't seem to error out but I it doesn't work either (takes all CPUs): self.client.start(container, lxc_conf = self.get_lxc_conf())
def get_lxc_conf(self):
return[
#All containers get the same share
{'lxc.cgroup.cpu.shares':1},
#Restrict container to a core
{'lxc.cgroup.cpuset.cpus':self.cpu_number}
] The CLI counterpart is able to limit this CPU-intensive script to a single CPU:
|
Interestingly, after running
I can just do
And the previous resource limits are applied. However if I do afterwards the equivalent (I think) with docker-py, the resource limits are ignored: self.docker_client.start('104059c2e613') |
@ureyes84 When using the docker CLI the run command has a -c flag that's used for setting CPU shares. As for docker-py. the lxc_conf param in the Client.start method expects a list of dicts like so: [{"Key":"lxc.cgroup.cpu.shares","Value":"1"}, {"Key": ..., "Value": }] And, both methods (CLI and docker-py) set that correctly in the lxc config (you can verify this in /var/lib/docker/containers/{container_id}/config. You can test with: client.create_container('ubuntu', '/bin/bash -c "dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null | dd if=/dev/zero of=/dev/null"') and then: c.start('04095d4fc948', lxc_conf=[{'Key': 'lxc.cgroup.cpuset.cpus', 'Value': '1'}]) Note that the restriction we use to restrict the number of cores to be used is 'lxc.cgroup.cpuset.cpus' I hope this helps. |
Thank you very much! They Key Value syntax helped. I didn't see that coming though, do you think the docs should be updated? Also, thank you for explaining the cpu shares. My intent is to limit resources, I think restricting the number of cores is the way to go. Quick question regarding this, say I have a dedicated server that creates ALL containers with: [{"Key":"lxc.cgroup.cpu.shares","Value":"1"}] Does it really make a difference adding this parameter? I was wondering whether this is useful only when you need to give more "weight" to a specific container and set the Value parameter to something higher. |
You are right about the docs. And tnx for the pull request, I've commented there. Regarding cpu.shared, you are right, it's suited for giving priority to certain containers by setting a higher value. |
I think we can close this. |
Thanks again for your help |
How do I use
lxc_conf
instart
?I'd like to set cpu and cpu shares, something like this:
According to the documentation I should be able to pass a dictionary:
So my code looks like this:
However, I can't get it work, I keep getting the following error message:
I get the same error even with the dictionary example in the API docs:
I've tried passing lists and strings
Thanks!
The text was updated successfully, but these errors were encountered: