Python 调度执行延迟的原因
我们使用 Python 2.6 中的 sched 模块每 60 秒运行一个函数。每次调用在执行后都会发出 sched.enter() 函数,延迟时间为 60,优先级为 1。这一直运行良好。
然而,我们发现了一种情况,sched 函数的下一次执行在几分钟内都没有发生,甚至长达 5-6 分钟后。这是在虚拟机上观察到的。
可能是什么原因造成的?是否有任何解决方法可以确保任务定期执行?
We are using the sched module in Python 2.6 to run a function every 60 seconds. Each call issues the sched.enter() function after executing with a delay of 60 and priority of 1. This has been working fine.
However, we have found a situation when the next execution of the sched function doesn't happen for several minutes, even up to 5-6 minutes later. This has been observed on a virtual machine.
What could be causing this? Is there any workaround to ensure the task gets executed regularly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
调用
sched.enter
之前发生的处理需要多长时间?我建议对此进行监控,并可能在sched.enter
的delay
参数中考虑处理时间。VM和VM主机的负载也可能是重要因素。我发现某些应用程序的性能下降是由于 VM 主机负载和交换过高而导致的。
How long takes the processing that happens before
sched.enter
is called? I would suggest monitoring this, and maybe taking that processing time into account in thedelay
parameter ofsched.enter
.The load of the VM and of the VM host may also be important factors. I've seen performance degradations in some apps caused by the VM host being under a too high load and swapping.