Systemd.timer 定时任务每秒执行的精度问题

2019-07-28 18:44:20 +08:00
 Ho

目的:每秒执行定时任务

环境:CentOS

使用绝对时间参数 OnCalendar 来设定每秒执行就会出现停顿 6,7 秒的情况。看下面执行结果

如果是每 2 秒执行就是正常的。

service:

[Unit]
Description=startup Matlab model

[Service]
ExecStart=echo `date` >> /tmp/timer.log

timer:

[Unit]
Description=Runs matlab script every time

[Timer]
OnCalendar=*:*:0/1
Unit=test.service
Persistent=yes
AccuracySec=1us

[Install]
WantedBy=multi-user.target

执行结果:


[root@izj6cb0qckkiraesjuawcnz system]# tail -f /tmp/timer.log
Sun Jul 28 18:49:34 CST 2019
Sun Jul 28 18:49:35 CST 2019
Sun Jul 28 18:49:36 CST 2019
Sun Jul 28 18:49:37 CST 2019
Sun Jul 28 18:49:38 CST 2019
Sun Jul 28 18:49:45 CST 2019
Sun Jul 28 18:49:46 CST 2019
Sun Jul 28 18:49:47 CST 2019
Sun Jul 28 18:49:48 CST 2019
Sun Jul 28 18:49:49 CST 2019
Sun Jul 28 18:49:55 CST 2019
Sun Jul 28 18:49:56 CST 2019
Sun Jul 28 18:49:57 CST 2019
Sun Jul 28 18:49:58 CST 2019
Sun Jul 28 18:49:59 CST 2019
Sun Jul 28 18:50:06 CST 2019
Sun Jul 28 18:50:07 CST 2019
Sun Jul 28 18:50:08 CST 2019
Sun Jul 28 18:50:09 CST 2019
Sun Jul 28 18:50:10 CST 2019
Sun Jul 28 18:50:16 CST 2019
Sun Jul 28 18:50:17 CST 2019
Sun Jul 28 18:50:18 CST 2019
Sun Jul 28 18:50:19 CST 2019
Sun Jul 28 18:50:20 CST 2019
Sun Jul 28 18:50:27 CST 2019
Sun Jul 28 18:50:28 CST 2019
Sun Jul 28 18:50:29 CST 2019
Sun Jul 28 18:50:30 CST 2019
Sun Jul 28 18:50:31 CST 2019
Sun Jul 28 18:50:37 CST 2019
Sun Jul 28 18:50:38 CST 2019
Sun Jul 28 18:50:39 CST 2019
Sun Jul 28 18:50:40 CST 2019
Sun Jul 28 18:50:41 CST 2019
Sun Jul 28 18:50:48 CST 2019
Sun Jul 28 18:50:49 CST 2019
Sun Jul 28 18:50:50 CST 2019
Sun Jul 28 18:50:51 CST 2019
Sun Jul 28 18:50:52 CST 2019
3112 次点击
所在节点    Linux
2 条回复
arrow8899
2019-07-28 19:18:16 +08:00
Ho
2019-07-28 19:36:03 +08:00
@arrow8899

还是会出现中断 6,7 秒的情况
```
[Timer]
OnCalendar=*:*:0/1
Unit=matlab_script.service
Persistent=yes
AccuracySec=1us
OnUnitActiveSec=1s
```

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/586927

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX