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

Support for cpu_shares #267

Closed
sstarcher opened this issue Nov 3, 2016 · 19 comments
Closed

Support for cpu_shares #267

sstarcher opened this issue Nov 3, 2016 · 19 comments

Comments

@sstarcher
Copy link

It would be nice to have resources limits for cpu_shares and mem_limits.

@concaf
Copy link
Contributor

concaf commented Jan 6, 2017

It would be great to have support for mem_limit which should translate to a pod's spec like -

spec:
  containers:
  - image: nginx
    imagePullPolicy: Always
    name: nginx
    resources:
      limits:
        memory: 200Mi
    terminationMessagePath: /dev/termination-log
    volumeMounts:

@kadel imo, mem_limit can be mapped directly, not sure about cpu_shares.

@surajssd
Copy link
Member

surajssd commented Jan 6, 2017

@containscafeine 👍

@cdrage
Copy link
Member

cdrage commented Jan 11, 2017

I'll start working on this. I'll assign myself to this issue!

@cdrage cdrage self-assigned this Jan 11, 2017
@cdrage
Copy link
Member

cdrage commented Jan 11, 2017

Assigning to @containscafeine instead.

@cdrage cdrage removed their assignment Jan 11, 2017
@concaf
Copy link
Contributor

concaf commented Jan 11, 2017

Sigh, okay, so taking a look at the mem_limit part, and having implemented it, turns out that if the docker-compose.yaml looks like -

web:
  image: tuna/docker-counter23
  ports:
    - "5000:5000"
  links:
    - redis
  mem_limit: 500m

i.e., has a non integer value, then, kompose convert fails with -

ERRO[0000] Could not parse config for project tmp : strconv.ParseInt: parsing "500m": invalid syntax 
FATA[0000] Failed to load compose file: strconv.ParseInt: parsing "500m": invalid syntax 

Tracking this down further, this is a libcompose issue and libcompose up fails with -

ERRO[0000] Failed to unmarshall: strconv.ParseInt: parsing "500m": invalid syntax
web:
  image: tuna/docker-counter23
  links:
  - redis
  mem_limit: 500m
  ports:
  - 5000:5000 
ERRO[0000] Could not parse config for project tmp : strconv.ParseInt: parsing "500m": invalid syntax 
FATA[0000] Failed to read project: strconv.ParseInt: parsing "500m": invalid syntax 

However, trying libcompose up with the latest release works fine.

So, for this to work fine, libcompose version has to be bumped, which is being tracked at #374

@kadel
Copy link
Member

kadel commented Jan 12, 2017

@containscafeine can you test it with #356?

@concaf
Copy link
Contributor

concaf commented Jan 12, 2017

@cdrage just tried this with #356, and mem_limit fails. This is fixed in the latest release of libcompose, can we upgrade to that?

cdrage added a commit to cdrage/kompose that referenced this issue Feb 6, 2017
This commit adds mem_limit support. Taking the value from
docker-compose.yaml and converting it to it's associative value in
Kubernetes artifacts.

Closes (half) of
kubernetes#267
cdrage added a commit to cdrage/kompose that referenced this issue Feb 21, 2017
This commit adds mem_limit support. Taking the value from
docker-compose.yaml and converting it to it's associative value in
Kubernetes artifacts.

Closes (half) of
kubernetes#267
cdrage added a commit to cdrage/kompose that referenced this issue Feb 22, 2017
This commit adds mem_limit support. Taking the value from
docker-compose.yaml and converting it to it's associative value in
Kubernetes artifacts.

Closes (half) of
kubernetes#267
@surajnarwade
Copy link
Contributor

@cdrage @surajssd we can close this issue, as mem_limit is now supported

@cdrage
Copy link
Member

cdrage commented Apr 3, 2017

@surajnarwade cpu_shares is still an issue. So let's leave this open.

@surajnarwade
Copy link
Contributor

@cdrage oh my bad, got it

@surajssd surajssd changed the title Support for cpu_shares and mem_limit Support for cpu_shares Apr 4, 2017
@surajssd
Copy link
Member

surajssd commented Apr 4, 2017

@cdrage mem_limit is supported right now so edited the title

@surajssd
Copy link
Member

surajssd commented Apr 4, 2017

@cdrage @surajnarwade we can officially declare that we don't support cpu_shares becasue there is no way we can map it to anything in k8s.

cpu_shares talks in terms of percentage of cpu to give to any container, this is feasible on a single machine but does not make sense on multi-node cluster where we dont know the entire cpu number.

TLDR: this is not easy to map to k8s cpu resources.

more info about cpu shares: https://docs.docker.com/engine/admin/resource_constraints/#cpu

@surajssd
Copy link
Member

surajssd commented Apr 4, 2017

So the PR that closes this issue should remove all the code which tries to read this info from docker compose file and adds it to ServiceConfig and also give warning as this is unsupported.

@cdrage
Copy link
Member

cdrage commented Apr 4, 2017

@surajssd Adding this to unsupportedkeys sounds like the best viable option considering the complexity of implementing cpu_shares. I agree.

@surajnarwade
Copy link
Contributor

@surajssd @cdrage , I am onto this.

surajnarwade added a commit to surajnarwade/kompose that referenced this issue Apr 5, 2017
Resolves kubernetes#272 and kubernetes#267

As there is no direct mapping of `cpushares` and `cpuset` to kubernetes,
it should not be read and should be moved to unsupported keys.
surajnarwade added a commit to surajnarwade/kompose that referenced this issue Apr 5, 2017
Resolves kubernetes#272 and kubernetes#267

As there is no direct mapping of `cpushares` and `cpuset` to kubernetes,
it should not be read and should be moved to unsupported keys.
qujinping pushed a commit to qujinping/kompose that referenced this issue Apr 25, 2017
Resolves kubernetes#272 and kubernetes#267

As there is no direct mapping of `cpushares` and `cpuset` to kubernetes,
it should not be read and should be moved to unsupported keys.
@surajnarwade
Copy link
Contributor

we can close this now

@cdrage cdrage closed this as completed Apr 26, 2017
@gitlawr
Copy link
Contributor

gitlawr commented May 18, 2017

Hope not to be pedantic here, but I think for cpu_shares and cpu_quota there are highly relevant concepts in Kubernetes: see.
These two keys in compose file are analogous to docker run counterpart, while in k8s requests.cpu maps to docker run --cpu-shares and limits.cpu maps to --cpu-quota(involving simple computations and pre-condition that --cpu-period=100000 though)
A user case I can come up with is that we may use daemonset or pod affinity to run one instance on every node and keep dedicated share/quota of CPU for it.
As for cpuset key I agree that it is pointless in a cluster environment as we usually don't care which cpu is used.
WDYT? @surajssd @cdrage @surajnarwade

@surajnarwade
Copy link
Contributor

@gitlawr , but there is no direct mapping for cpu_shares and quotas

@gitlawr
Copy link
Contributor

gitlawr commented May 18, 2017

@surajnarwade For example,setting cpu resource such as:

apiVersion: v1
kind: Pod
metadata:
  name: one
spec:
  volumes:
  containers:
  - name: busysleep
    image: busybox
    command: ["sleep","3000"]
    resources:
      requests:
        cpu: 100m
      limits:
        cpu: 0.5

Then the container will be run with CpuShares==102(which is 0.1*1024) and CpuQuota=50000(which is half of CpuPeriod given CpuPeriod= 100000). Is it kind of direct mapping I think?

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

No branches or pull requests

8 participants