1

I've set up a systemd timer to trigger a service every minute on Ubuntu 22.04, but I'm encountering an issue where the execution time of the service significantly increases after the first run. The service simply logs some text using /bin/echo. Here are the details:

Service file (testA.service):

[Unit]
Description=Sample Service A

[Service]
ExecStart=/bin/echo "Hello from Service A"

Timer file (testA.timer):

[Unit]
Description=1min timer

[Timer]
OnCalendar=*-*-* *:*:00

[Install]
WantedBy=timers.target

Observed Behavior:

The first execution of the service completes in 6 seconds. Subsequent executions take 17 seconds.

System logs:

Feb 16 10:47:06 test systemd[923]: Started Sample Service A.
Feb 16 10:47:06 test echo[2740609]: Hello from Service A
Feb 16 10:48:17 test echo[2740652]: Hello from Service A
Feb 16 10:48:17 test systemd[923]: Started Sample Service A.
Feb 16 10:49:17 test systemd[923]: Started Sample Service A.
Feb 16 10:49:17 test echo[2740691]: Hello from Service A
Feb 16 10:50:17 test systemd[923]: Started Sample Service A.
Feb 16 10:50:17 test echo[2740731]: Hello from Service A

Another test even slower - 58 seconds:

Feb 19 13:43:58 test systemd[917]: Started Sample Service A. 
Feb 19 13:43:58 test echo[119031]: Hello from Service A

System Details:

Ubuntu 22.04.2 8 Processors 8GB RAM Ample disk space Monitoring with htop shows the system is not overloaded.

Question: How can I diagnose and optimize the execution time of this systemd service to ensure it consistently completes quickly? Why might the execution time increase after the first run?

I've checked for common issues like system load and disk space but haven't found anything that would explain this behavior.

2

1 Answer 1

1

Thanks to @AlexD for the hint. Adding the AccuracySec= option to the timer makes the magic of running the service in the right time every run.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .