使用轮询系统调用等待 fds 时 CPU 使用率高
High CPU usage while using poll system call to wait on fds
我有一个独特的问题,我的代码中使用的 linux 的轮询系统调用会得到它等待轮询的 fd,我的意思是每毫秒 POLLIN。这会导致 高 CPU 使用率 .我提供了 100 毫秒的超时,它似乎没有用。任何人都可以提出替代方案。
for (;;) {
ACE_Time_Value doWork(0, 20000);
ACE_OS::sleep(doWork); ----------------------------> Causing low throughput, put to decrease CPU usage / On removing this we see high CPU , but throughput is achieved.
..
.
..
if ((exitCode = fxDoWork()) < 0) {
break;}
}
fxDoWork()
{
ACE_Time_Value selectTime;
selectTime.set(0, 100000);
..
..
..
ACE_INT32 waitResult = ACE_OS::poll(myPollfds, eventCount, &selectTime);-----------------------------> Pollin happens for every milli second/Timeout is not at all useful
..
..
..
}
===============================================================
听起来您想积累足够的数据或发生特定的超时以减少 CPU 使用率,对吗? 如果是这种情况,您可以使用 recvmmsg(): http://man7.org/linux/man-pages/man2/recvmmsg.2.html
recvmmsg() 系统调用是 recvmsg(2) 的扩展,它允许 使用单个套接字从套接字接收多条消息的调用方 系统调用。 (这对某些应用程序具有性能优势。 对 recvmsg(2) 的进一步扩展是支持在 接收操作。
相关文章:
- 编写一个函数以使用 n 百分比的 CPU 使用率
- 对于等待以 std::future wait() 返回的函数的 CPU 使用率或检查标志在循环中休眠一段时间哪个更好?
- 如何降低应用程序的 CPU 使用率?
- 如何以编程方式获取任务管理器进程CPU使用率(不是PerfMon API)
- 一段时间后 CPU 使用率高
- 高CPU使用率,在API桌面复制中获取帧之间具有不同的超时间隔
- GetDC ReleaseDC 在特定上下文中的高 CPU 使用率
- 从 C++11 代码中获取系统内存和 CPU 使用率
- 在 Visual Studio 中记录 CPU 使用率
- C++如何允许等待而不会过多的 CPU 使用率
- Qtcreator 冻结,CPU 使用率为 100%
- 使用 fgets() c++ 读取大型 txt 文件时的 CPU 使用率为 99%
- OpenCL 的 CPU 使用率意外
- Loop Wregex始终返回false和高CPU使用率约50%
- 简单的C++SFML程序高CPU使用率
- 使用 PID 获取内存和 CPU 使用率
- 如何在TCP端口上实时传输数据期间减少CPU使用率
- WinAPI:在WM_PAINT省略 BeginPaint 和 EndPaint 会导致 100% 的 CPU 使用率
- 当CPU使用率高时,OpenCV会堆积内存吗
- 如何在运行SDL程序时降低CPU使用率