我的应用程序在 epoll_wait
中等待的时间比我在超时中指定的时间长得多:
22578 09:33:46.959791 epoll_wait(5, <unfinished ...>
22578 09:33:50.010794 <... epoll_wait resumed> [], 128, 1498) = 0
...
22034 09:35:07.686896 epoll_wait(5, <unfinished ...>
22034 09:35:09.482526 <... epoll_wait resumed> [{EPOLLIN, {u32=151458248, u64=151458248}}], 128, 362) = 1
...
22036 09:35:41.433241 epoll_wait(5, <unfinished ...>
22036 09:35:43.176881 <... epoll_wait resumed> [], 128, 97) = 0
我已要求为一个值超时,但计时显示它等待了更长的时间间隔。
来自日志的时间是可靠的 - 我从 strace
输出中得到它。
我该怎么做才能使 epoll
中的超时更细化?
为什么 epoll_wait
如此不准确?
最佳答案
Note that the timeout interval will be rounded up to the system clock granularity, and kernel scheduling delays mean that the blocking interval may overrun by a small amount.
换句话说,超时是一个最小值。
但是当机器空闲时不会发生这么大的延迟。 如果你有实时约束,确保你的代码可以实际运行,即设置适当的调度策略,防止它被换出等。
关于linux - epoll_wait 阻塞时间超过超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40930546/