You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What I am saying is that when you write a systemd service file, in addition to ExecStart=/usr/local/bin/mydaemon you can add CPUQuota=20% without having to call cpulimit separately in the service.
A fuller example (although where I cut Unit.{After,Wants} and Service.{Environment,WorkingDirectory,PIDFile,ExecReload,Restart,RestartSec}) would be
I think what you should do is systemctl edit whatever-starts-fah.service and there add the
[Service]CPUQuota=20%
and it should just work without having to even touch the actual service file (as this creates a drop-in file e.g. /etc/systemd/system/whatever-starts-fah.service.d/override.conf).
I don't understand what is going on there, but I do have another idea (that actually includes cpulimit this time 😅)
Check what is the service that starts fah in /usr/lib/systemd/system/whatever.service and take note on the ExecStart= line.
sudo systemctl edit whatever.service
Add the following override
[Service]# Empty ExecStart erases whatever ExecStart has been specified beforeExecStart=
# and do adjust the flags to be more suitable for youExecStart=/usr/bin/cpulimit --lazy --include-children --limit=30 /usr/bin/fahcore-or-whatever
sudo systemctl daemon-reload
sudo systemctl restart whatever.service
My third idea would be creating a systemd oneshot service and a timer for running cpulimit with --pid or --exe, but at that point it would be shorter to just use crontab for it assuming it was available and I am still unconvinced about it being a systemd service file for cpulimit, while I guess my second idea could be documented somewhere.
PS. Sorry for long response time, I seem to have went a couple of days without reading my email.
Activity
Freso commentedon Jan 28, 2024
What would you want a service file for this to do/provide?
Mikaela commentedon Apr 27, 2024
I am also curious considering systemd service files can already do this for what it manages.
See also
man systemd.resource-controlpromeneur commentedon Apr 27, 2024
Sorry @Freso I am late.
In the past, before systemd, we put the statement cpulimit in a special system file according to start it during system startup.
With systemd now all is started with a systemd service file. I speak about a service file to start cpulimit.
Please I am not a techie person about systemd so a ref to systemd doc is not for me.
Thanks
Mikaela commentedon Apr 27, 2024
What I am saying is that when you write a systemd service file, in addition to
ExecStart=/usr/local/bin/mydaemonyou can addCPUQuota=20%without having to callcpulimitseparately in the service.A fuller example (although where I cut
Unit.{After,Wants}andService.{Environment,WorkingDirectory,PIDFile,ExecReload,Restart,RestartSec}) would bepromeneur commentedon Apr 27, 2024
@Mikaela thanks
But the problem is a way complex for my case.
An app FAH is started by systemd service file.
FAH launches randomly others app named "FahCore_a8", "Fahcore_22".
So we must launch a service file which detects that "Fahcore_a8" and "Fahcore_22" are running and limits their cpu consumption to 20 %.
Mikaela commentedon Apr 27, 2024
I think what you should do is
systemctl edit whatever-starts-fah.serviceand there add theand it should just work without having to even touch the actual service file (as this creates a drop-in file e.g.
/etc/systemd/system/whatever-starts-fah.service.d/override.conf).promeneur commentedon Apr 27, 2024
@Mikaela
thanks
I will try this as soon as I have some time.
promeneur commentedon Apr 28, 2024
20% is not enough according Fahcore_a8 consumes 20 %.
We need CPUQuota=200%.
More
With CPUQuota=200% FahCore_22 consumes only 5 % instead of 20 % !
My conf is :
I choose how many cores are used, but Fah decides how to dispatch them between Fahcore_a8 and Fahcore_22.
Mikaela commentedon Apr 30, 2024
I don't understand what is going on there, but I do have another idea (that actually includes
cpulimitthis time 😅)/usr/lib/systemd/system/whatever.serviceand take note on theExecStart=line.sudo systemctl edit whatever.servicesudo systemctl daemon-reloadsudo systemctl restart whatever.serviceMy third idea would be creating a systemd oneshot service and a timer for running
cpulimitwith--pidor--exe, but at that point it would be shorter to just usecrontabfor it assuming it was available and I am still unconvinced about it being a systemd service file forcpulimit, while I guess my second idea could be documented somewhere.PS. Sorry for long response time, I seem to have went a couple of days without reading my email.
promeneur commentedon Apr 30, 2024
@Mikaela
No problem.
The ExecStart of Fah-client service :
ExecStart=/usr/local/bin/fah-client --config=/etc/fah-client/config.xml --log=/var/log/fah-client/log.txt --log-rotate-dir=/var/log/fah-client/
Are you sure the new ExecStart runs without any problem ?
ExecStart=/usr/bin/cpulimit --lazy --include-children --limit=30 /usr/local/bin/fah-client --config=/etc/fah-client/config.xml --log=/var/log/fah-client/log.txt --log-rotate-dir=/var/log/fah-client/
promeneur commentedon Apr 30, 2024
I created a cpulimit service.
[Unit]
Description=Run cpulimit
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=cpulimit --include-children --exe fah-client --limit 75
[Install]
WantedBy=multi-user.target
--include-children is not an option of cpulimit. This lead to an exit code when sarting cpulimit service.
promeneur commentedon Apr 30, 2024
I discovered a big problem.
openSUSE supplies a cpulimit package which is in fact Limitcpu 3.0
see
https://limitcpu.sourceforge.net/
it is not the original cpulimit from here
promeneur commentedon Apr 30, 2024
i keep my previous solution.
a script cpulimit.sh
cpulimit --exe FahCore_a7 --limit 50 &
cpulimit --exe FahCore_a8 --limit 50 &
cpulimit --exe FahCore_22 --limit 75 &
cpulimit --exe FahCore_23 --limit 75 &
when it is needed
a service to launch the script
[Unit]
Description=Run cpulimit
[Service]
Type=oneshot
RemainAfterExit=yes
ExecStart=/home/roubach/bin/cpulimit.sh
[Install]
WantedBy=multi-user.target
Anyway, thanks.