我有这个独特的问题,我的代码中使用的linux的轮询系统调用得到它在轮询时等待的fds,我的意思是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
..
..
..
}
===============================================================
答案 0 :(得分:1)
听起来你想积累足够的数据或者特定的超时会降低CPU的使用率,对吧?如果是这种情况,您可以使用recvmmsg():http://man7.org/linux/man-pages/man2/recvmmsg.2.html
recvmmsg()系统调用是recvmsg(2)的扩展,允许 调用者使用单个来自套接字的多个消息 系统调用。 (这对某些应用程序具有性能优势。) 对recvmsg(2)的进一步扩展是对超时的支持 接受手术。