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

New epoll event engine implemention that may be more effecient #295

Merged
merged 5 commits into from
Dec 14, 2023

Conversation

Coldwings
Copy link
Collaborator

@Coldwings Coldwings commented Dec 8, 2023

A new epoll event engine implementation (EPOLL_NG) which use epoll groups to manage read/write events.
This is much simpler and use no on-heap memory allocation, with better performance, as mentioned in #268

Edge-trigger related feature will be implemented in future.

New engine shows 3%~5% throughput/QPS improvement by net-perf test.

Signed-off-by: Coldwings <coldwings@me.com>
struct Poller {
int epfd = -1;
epoll_event events[16];
int remains = 0;
Copy link
Collaborator

Choose a reason for hiding this comment

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

put it right after epfd, to improve alignment.

#define EPOLLRDHUP 0
#endif

class EventEngineEPollNG : public MasterEventEngine,
Copy link
Collaborator

Choose a reason for hiding this comment

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

inherit ResetHandle

io/epoll-ng.cpp Outdated
engine.collect(timeout);
engine.notify_all(
[&](epoll_data_t data) __INLINE__ {
if (data.fd == evfd) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

better to do it like this:

switch(data) {
case 0:
	eventfd_read(evfd, &value);
	break;
case 1:
	rpoller.collect(0);
	break;
case 2:
	wpoller.collect(0);
	break;
case 3:
	epoller.collect(0);
	break;
}

so as to improve branch prediction

io/epoll-ng.cpp Outdated
return fired;
}

void collect(uint64_t timeout) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

better name it "reap"

io/epoll-ng.cpp Outdated
0, [&](epoll_data_t data) __INLINE__ { *ptr++ = data.ptr; },
[&]()
__INLINE__ { // make sure each fd receives all possible events
return (end - ptr) >= 3;
Copy link
Collaborator

Choose a reason for hiding this comment

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

this seems not necessary any more?

io/epoll-ng.cpp Outdated
return ctl(fd, EPOLL_CTL_DEL, events, data);
}

int wait(epoll_event* evs, size_t len, uint64_t timeout) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

wait() is only invoked by one-liner collect(). consider merging them.

io/epoll-ng.cpp Outdated

Poller pl[4];
Poller& engine = pl[(int)PULLERTYPE::ENGINE];
Poller& rpoller = pl[(int)PULLERTYPE::READER];
Copy link
Collaborator

Choose a reason for hiding this comment

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

xpoller can be defined as macros instead. (x = r, w, e)

return;
case (uint64_t)PULLERTYPE::EVENT:
eventfd_read(evfd, &value);
return;
Copy link
Collaborator

Choose a reason for hiding this comment

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

default:
    LOG_ERROR(...);

@lihuiba lihuiba merged commit fc26e18 into alibaba:main Dec 14, 2023
7 checks passed
This pull request was closed.
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.

2 participants