Article 55ZJM How to improve Python script performances when launched from systemd?

How to improve Python script performances when launched from systemd?

by
rbrue
from LinuxQuestions.org on (#55ZJM)
I have a Raspberry Pi (there is a Debian-based distro) which needs to keep running a service based on a Python script.

What I have done so far has been to create the .service file added to the /lib/systemd/system/ folder, now it is run automatically at the system boot and it is able to be restarted if any crash occurs, furthermore, a little logging system has been added based on syslog.

The content of the .service file looks like this so far:

Code:[Unit]
Description=My_Service
After=network.target network-online.target
After=local-fs.target

[Service]
Type=simple
Restart=always
ExecStartPre=/bin/mkdir -p /home/user/log
ExecStart=/usr/local/bin/python3 -u /home/user/my_service.py
SyslogIdentifier=My_Service
StandardOutput=syslog
StandardError=syslog

[Install]
WantedBy=multi-user.target
Now I've noticed that the script is slighlty less performant than when it is run by terminal.Because it is the only one script that the system should keep running, I was trying to set it with the highest priority but I am not sure how to do that. So far I've added the following lines in the [Service] section but I'm not sure if it is ok or if it could be the best practice.

Code:CPUSchedulingPolicy=rr
CPUSchedulingPriority=99
Nice=-20The question is: How can I set the maximum priority and maximum usage of the system resources for such service in order to maximise its performances?

I'm also trying to disable other system services which are not useful for my embedded system, such as the bluetooth.service, could this kind of work be a good practice?latest?d=yIl2AUoC8zA latest?i=Cq8sEvG7eMY:eW4PhoOfrHY:F7zBnMy latest?i=Cq8sEvG7eMY:eW4PhoOfrHY:V_sGLiP latest?d=qj6IDK7rITs latest?i=Cq8sEvG7eMY:eW4PhoOfrHY:gIN9vFwCq8sEvG7eMY
External Content
Source RSS or Atom Feed
Feed Location https://feeds.feedburner.com/linuxquestions/latest
Feed Title LinuxQuestions.org
Feed Link https://www.linuxquestions.org/questions/
Reply 0 comments