Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

xiaosuo
Copy link

@xiaosuo xiaosuo commented Jun 3, 2017

For #4

@winlinvip winlinvip changed the base branch from master to srs June 4, 2017 03:12
@winlinvip winlinvip changed the base branch from srs to master June 4, 2017 03:13
@lihuiba
Copy link

lihuiba commented Nov 22, 2017

Please merge it

@winlinvip
Copy link
Member

winlinvip commented Jan 2, 2018

  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 winlinvip changed the title epoll: Don't iterate all the fds when using epoll epoll: Don't iterate all the fds when using epoll for #4 Jan 2, 2018
@winlinvip winlinvip changed the title epoll: Don't iterate all the fds when using epoll for #4 epoll: Don't iterate all the fds when using epoll Jan 2, 2018
winlinvip added a commit that referenced this pull request Jan 2, 2018
@winlinvip
Copy link
Member

winlinvip commented Jan 2, 2018

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

@winlinvip
Copy link
Member

重新看了ST的调度和IO事件处理的代码,看懂了你说的问题在哪里,以及主要优化的场景,我记录在了这里:#13 (comment)

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

如果FD很多时,有大量等待IO的fd时,就会触发这个性能瓶颈,可以看到_st_epoll_dispatch占用较多的CPU,这就是 #4 (comment) 中描述的性能问题。

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

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

_st_pollq_t *pq;
_st_pollq_t **pqs;
};
int pq_cnt;
Copy link
Member

@winlinvip winlinvip Apr 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_st_epolldata. evtlist.epoll_data.ptr是可以放自定义指针的。
可能更适合放_st_pollq_t的信息,可以存放协程的链表_st_clist_t。

typedef union epoll_data {
    void    *ptr;
    int      fd;
    uint32_t u32;
    uint64_t u64;
} epoll_data_t;

struct epoll_event {
    uint32_t     events;    /* Epoll events */
    epoll_data_t data;      /* User data variable */
};

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#[[[[[**_```

> ~~~~~~~~``~~committed ~~``~~~~~~~~

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants