systemctl takes too much CPU
use systemctl.py After replacing /usr/bin/ststemctl, systemctl takes too much CPU. PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+COMMAND 1 root 20 0 187080 31872 3756 S 9.3 0.0 131:32.44 systemctl
@teafull Just out of curiosity, did you physically replace one script with the other in /usr/bin/systemctl as opposed to leaving that one alone and placing systemctl3.py in /usr/local/bin/systemctl and ensuring that comes first in your PATH?
I did the latter without issue.
There is no problem with the systemctl.py path for the time being, the whole is inside the container of docker. I'm dealing with cpu occupancy, and it consistently occupies 9.3% of the CPU.I don't know how to troubleshoot this problem, I am not very familiar with Python.
I guess the "1" in the description says that you are running systemctl.py as the init-daemon of the container.
When the InitLoop in the code is activated then it does a few extra things than just being a service manager. Every few seconds it will check for zombie processes, and it will collect log output from services into the docker log stream. That's a good thing as it makes the container look a bit more like a real system inside while still being a containerization in external usage.
I guess it does not have to do with Python in itself which can sit idle on a sleep() steps and open()ed input streams. It relates to the services you are actually running - and the idea would be to optimizel the InitLoop steps and to divert all StandardOutput of the services to a log file instead of expecting the service journal() to show a thing.
@gdraheim By the way, I use tini (a tiny init deamon) to start my main container service. Then, I use your systemctl tool to manually start services. Of course, I can use a wrapper script that tini can call to automate this if I wanted to.
BTW : It never occurred to me to overwrite the stock systemctl binary with yours. Is that how to use it?
@nmvega - yes, that's how I do usually use it.
Have a look at the examples in https://github.com/gdraheim/docker-systemctl-images
@gdraheim Ah, okay. Thank you for the examples. :laughing:
It uses systemctl.py as the init-daemon of the container. I just don't know where so much CPU is occupied. @gdraheim
It seems like there might be an issue with the replacement of the systemctl file on your system. High CPU usage can indicate a problem with the system process or a misconfigured service.If you haven't already, I recommend trying to revert back to the original systemctl file or reinstalling it. Additionally, you may want to check the logs to see if there are any error messages or relevant information that can help you troubleshoot the issue.If you continue to experience high CPU usage even after reverting to the original file, you may want to consider reaching out to the Smithfield Replacement support team for further assistance.