12

I have a docker image that hosts a web server and another that runs background tasks. Most of the time the web server is idle, and the background tasks should be allowed to use 100% of the CPUs, but any time the web server needs resources, it should have priority on the CPUs so it can respond quickly.

If everything was running on one linux machine, I could use something like nice -n19 background-task to run the tasks, and they would allow the web server as much CPU as it needed.

Is there a way to run the whole container at a nice level? I know I can restrict the amount of CPU time available to each background task with cpu_quota, but this doesn't solve the problem. If the web server wants to use all 4 CPU cores to serve a client it should be allowed. If the web server is not busy, all 4 CPU cores should work on the background task.

If I change the command in the Dockerfile to:

nice -n19 background-task

Will this work between containers? Processes inside containers are all kind of normal processes running on the same kernel, so it seems like it will, but I'm not sure.

This seems like something fairly obvious to do. Am I missing something?

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240
rjmunro
  • 27,203
  • 20
  • 110
  • 132
  • Do you mean `--cap-add=sys_nice` https://docs.docker.com/config/containers/resource_constraints/ ? – Alex Yu Jan 15 '19 at 19:19
  • @ingaz It's not clear what adding that option does. I want a process in one container to be nice relative to a process in another container. I don't particularly want the container to be able to adjust it's own internal niceness levels, in fact I'd rather it didn't and i could control niceness from the outside of the container. – rjmunro Jan 15 '19 at 19:57
  • `docker`-processes are usual OS processes. So `nice`/`renice` must work for them in the same way. Docker or not is not a concern for scheduler. Maybe I don't understand your question – Alex Yu Jan 15 '19 at 21:04
  • @ingaz That is the answer I was hoping for, but it would good if there was some actual documentation to say this clearly somewhere. Could you expand your comment into an answer? I don't think you need `--cap-add=sys_nice` to increase niceness, only to reduce it. – rjmunro Jan 16 '19 at 10:28

1 Answers1

9

docker-processes are usual OS processes.

Docker or not is not a concern for process scheduler.

So nice/renice works for docker-processes in the same way as for others.

Alex Yu
  • 3,412
  • 1
  • 25
  • 38
  • 1
    Original Poster: Please make your comment an answer so I can accept it. Commenter: Makes it into an answer. OP: Doesn't accept it. – absmiths Apr 05 '21 at 00:40