As I understand it (please correct me if I'm wrong),
systemctl set-property ... CPUShares=some_value
limits the cpu time for an entire cgroup unit. If we instead want to limit cpu time for a process within that unit, we can run the process with
systemd-run ... nice=some_value
I'm wondering if there's some intrinsic difference between the concepts of the nice-value of a process and the CPUShares-value of a group of processes? Can we limit CPUShares of a process, or set the nice-value of a cgroup unit? When would we want to do one or the other?
Best Answer
From reading
man systemd-run
, it will create aservice
and thus acgroup
on the fly. From readingsystemd.exec
, theNice=
directive will apply to all executed processes, so the way thatsystmd
handles the concepts ofNice=
andCPUShares=
are very similar.My understanding of the relationship is that it has to do with history.
nice
has existed for a listed a couple of decades and always applied to specific processes.On the other hand, the concept of
cgroups
and the idea of applyingCPUShares=
to a process group is much a newer concept but accomplishes the same goal.I expect
systemd
supportsNice=
for historical compatibility.I would use whichever one you are comfortable with, but not both to avoid confusion. If you have no preference, I would use the newer
CPUShares=
concept.