Configuration attached below does not be reflected in
docker service inspect hello
provider:
name: faas
gateway: http://127.0.0.1:8080
functions:
hello:
lang: python3
handler: ./hello
image: hello:latest
labels:
"com.openfaas.scale.min": "2"
# "com.openfaas.scale.max": "40"
limits:
cpu: 1000m
# memory: 1000m
requests:
cpu: 1000m
# memory: 400m
currently inspect returns "Resources": {}, I will paste below results from the code with uncommented memory params.
limits:
cpu: 1000m
memory: 1000m
requests:
cpu: 1000m
memory: 400m
Reservations for CPU in a service parameters
"Resources": {
"Limits": {
"MemoryBytes": 1048576000
},
"Reservations": {
"MemoryBytes": 419430400
}
},
CLI:
commit: a141dedf94ffeed84412365fd591bdc8999c5a1b
version: 0.8.3
Gateway
uri: http://127.0.0.1:8080
version: 0.9.11
sha: 78a4584019a2a5d86b606a00b4fba979930cc2a7
commit: Add sha256 hashgen for watchdog to ci config
Provider
name: faas-swarm
orchestration: swarm
version: 0.5.0
sha: 4269ab15673ad883bfdce4df47c055588e8e86b2
Docker version docker version Version: 18.09.0
Operating System and version (e.g. Linux, Windows, MacOS): Fedora
IMO it is caused by different notation in CPU limits / requests in a docker swarm
it is not cpu: 1000m but cpus: 0.5
Derek add label: support
Derek add label: question
https://github.com/openfaas/faas/issues/1026#issuecomment-453748305
Sounds like it might be right. Where did you get the values from that you used?
I used config described in the docs https://docs.openfaas.com/reference/yaml/#function-memorycpu-limits
I checked version with:
provider:
name: faas
gateway: http://127.0.0.1:8080
functions:
hello:
lang: python3
handler: ./hello
image: hello:latest
readonly_root_filesystem: true
environment:
read_timeout: 3600s
write_timeout: 3600s
labels:
"com.openfaas.scale.min": "2"
# "com.openfaas.scale.max": "40"
limits:
cpus: 1
memory: 1000m
requests:
cpus: 0.5
memory: 400m
and the result in my local swarm is the same
"Resources": {
"Limits": {
"MemoryBytes": 1048576000
},
"Reservations": {
"MemoryBytes": 419430400
}
},
what is proper way to limit cpus for the function if I use OpenFaaS and swarm? I was trying different combinations :)
There are links on the page for both systems so that you can pick the correct option.
Here's the link from through page for Swarm https://docs.docker.com/config/containers/resource_constraints/
Alex
Yes I know I wanted to add it in subcomment ;) https://docs.docker.com/config/containers/resource_constraints/ - but even if I use cpus option it does not work in OpenFaaS as you can see in my previous comment. (I have check cpu-period and so on also ...)
The code and docs say "cpu" is the name of the field but your example says "cpus". I'm guessing that may be the problem?
https://github.com/openfaas/faas-cli/blob/master/stack/schema.go
Alex
Yes in L61, I used cpu also as you can see in my first post. So it sounds like a bug in OpenFaaS - do you agree?
The example you are using is wrong and can't work:
provider:
name: faas
gateway: http://127.0.0.1:8080
functions:
hello:
lang: python3
handler: ./hello
image: hello:latest
readonly_root_filesystem: true
environment:
read_timeout: 3600s
write_timeout: 3600s
labels:
"com.openfaas.scale.min": "2"
# "com.openfaas.scale.max": "40"
limits:
cpus: 1
memory: 1000m
requests:
cpus: 0.5
memory: 400m
If there were an issue it would be with the openfaas/faas-swarm repo.
Have you looked at the logs of faas-swarm? docker service logs func_faas-swarm
Alex
The documentation doesn't explain whether to use CPUs / CPU quota or CPU period in the field for Swarm. It just mentions Kubernetes.
From looking at the code I'd say it's CPU quota
From the Swarm docs:
Specify how much of the available CPU resources a container can use. For instance, if the host machine has two CPUs and you set --cpus="1.5", the container is guaranteed at most one and a half of the CPUs. This is the equivalent of setting --cpu-period="100000" and --cpu-quota="150000". Available in Docker 1.13 and higher.
@alexellis yes you are right it is a problem with faas-swarm
func_faas-swarm.1.[email protected] | 2019/01/12 21:09:18 Error parsing cpu limit: *strconv.NumError
func_faas-swarm.1.[email protected] | 2019/01/12 21:09:18 Error parsing cpu reservations: *strconv.NumError
limits:
cpu: 1.1
That's not a problem with faas-swarm, you've just specified the limits wrong. See above.
@alexellis sorry for my hasty answer. I have not seen your response :)
yes your assumtion based on the code was correct.
limits:
cpu: 1000000
causes in docker service inspect hello
"Resources": {
"Limits": {
"NanoCPUs": 1000000,
"MemoryBytes": 1048576000
},
}
It would be great if somebody can mention about it in a docs as like memory case.
thanks a lot @alexellis we can close the ticket. I will create another one, but it will be question / feature request ;)