epoll: Don't iterate all the fds when using epoll
For #4
Please merge it
- We should test it for active connections and other features such as cond and sync.
- 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.
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.
重新看了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时可能不会出现这个问题。