linux - epoll_wait 阻塞时间超过超时

标签 linux linux-kernel timeout epoll

我的应用程序在 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 如此不准确?

最佳答案

documentation说:

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/

相关文章:

linux - 从 Linux 机器中存在的 Web 应用程序访问 MS SQL Server?

linux - 如何在 linux RHEL7 中阻止 udp 端口​​范围

linux - 无法通过 linux 命令向 office 365 发送电子邮件

linux - 切换到用户模式时,非抢占式和抢占式内核有什么区别?

c - 如何使用 fcntl 和 F_GETOWN 知道我们是否收到错误或组 ID?

c - 通用 scsi ioctl 后 fread 期间出现段错误

c - 内核如何使用task_struct?

android - Android 中的发送超时重试模式

java - 如果我不使用自定义连接管理器,是否仍应在 Apache HttpClient 上设置 ConnectionRequestTimeout?

wcf - 处理 WCF 服务中的超时