state-threads icon indicating copy to clipboard operation
state-threads copied to clipboard

epoll: Don't iterate all the fds when using epoll

Open xiaosuo opened this issue 8 years ago • 4 comments

For #4

xiaosuo avatar Jun 03 '17 16:06 xiaosuo

Please merge it

lihuiba avatar Nov 22 '17 05:11 lihuiba

  1. We should test it for active connections and other features such as cond and sync.
  2. I will merge it to a feature branch, and test it in SRS server.

If it works well, I will merge from feature to srs branch. I will keep the master branch as ST1.9 without any changes.

winlinvip avatar Jan 02 '18 03:01 winlinvip

I have merge this PR to https://github.com/ossrs/state-threads/tree/features/xiaosuo/epoll The merged code is here: https://github.com/ossrs/state-threads/compare/srs...features/xiaosuo/epoll Please test it and file PR to it for updates.

winlinvip avatar Jan 02 '18 03:01 winlinvip

重新看了ST的调度和IO事件处理的代码,看懂了你说的问题在哪里,以及主要优化的场景,我记录在了这里:https://github.com/ossrs/state-threads/issues/13#issuecomment-616096568

ST在收到事件后,会遍历io_q,因为st对于fd的记录只记录了events,而没有记录哪些协程(_st_pollq_t)在侦听这个fd,因为一个协程可能会用st_poll侦听多个fd,所以维护这个关系比较复杂,估计ST就省略了。

如果FD很多时,有大量等待IO的fd时,就会触发这个性能瓶颈,可以看到_st_epoll_dispatch占用较多的CPU,这就是 https://github.com/ossrs/state-threads/issues/4#issuecomment-308707403 中描述的性能问题。

由于这个修改涉及较多,我觉得还是应该先完善ST的UTest,然后再修改这个问题。

PS: 在少量FD时可能不会出现这个问题。

winlinvip avatar Apr 19 '20 10:04 winlinvip