-
Notifications
You must be signed in to change notification settings - Fork 115
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
Conversation
Signed-off-by: Coldwings <coldwings@me.com>
struct Poller { | ||
int epfd = -1; | ||
epoll_event events[16]; | ||
int remains = 0; |
There was a problem hiding this comment.
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, |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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.
Signed-off-by: Coldwings <coldwings@me.com>
io/epoll-ng.cpp
Outdated
|
||
Poller pl[4]; | ||
Poller& engine = pl[(int)PULLERTYPE::ENGINE]; | ||
Poller& rpoller = pl[(int)PULLERTYPE::READER]; |
There was a problem hiding this comment.
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; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
default:
LOG_ERROR(...);
Signed-off-by: Coldwings <coldwings@me.com>
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.