[#3378] Automatically increase number of possible handled events
Motivation: At the moment the max number of events that can be handled per epoll wakup was set during construction. Modifications: - Automatically increase the max number of events to handle Result: Better performance when a lot of events need to be handled without adjusting the code.
This commit is contained in:
parent
c66da29644
commit
6b8ec6b781
@ -51,7 +51,8 @@ final class EpollEventLoop extends SingleThreadEventLoop {
|
||||
private final int epollFd;
|
||||
private final int eventFd;
|
||||
private final IntObjectMap<AbstractEpollChannel> ids = new IntObjectHashMap<AbstractEpollChannel>();
|
||||
private final long[] events;
|
||||
private final boolean allowGrowing;
|
||||
private long[] events;
|
||||
|
||||
private int id;
|
||||
|
||||
@ -61,7 +62,13 @@ final class EpollEventLoop extends SingleThreadEventLoop {
|
||||
|
||||
EpollEventLoop(EventLoopGroup parent, Executor executor, int maxEvents) {
|
||||
super(parent, executor, false);
|
||||
events = new long[maxEvents];
|
||||
if (maxEvents == 0) {
|
||||
allowGrowing = true;
|
||||
events = new long[128];
|
||||
} else {
|
||||
allowGrowing = false;
|
||||
events = new long[maxEvents];
|
||||
}
|
||||
boolean success = false;
|
||||
int epollFd = -1;
|
||||
int eventFd = -1;
|
||||
@ -268,7 +275,10 @@ final class EpollEventLoop extends SingleThreadEventLoop {
|
||||
final long ioTime = System.nanoTime() - ioStartTime;
|
||||
runAllTasks(ioTime * (100 - ioRatio) / ioRatio);
|
||||
}
|
||||
|
||||
if (allowGrowing && ready == events.length) {
|
||||
// double the size of the array as we needed the whole space for the events
|
||||
events = new long[events.length << 1];
|
||||
}
|
||||
if (isShuttingDown()) {
|
||||
closeAll();
|
||||
if (confirmShutdown()) {
|
||||
|
@ -46,14 +46,19 @@ public final class EpollEventLoopGroup extends MultithreadEventLoopGroup {
|
||||
/**
|
||||
* Create a new instance using the specified number of threads and the given {@link ThreadFactory}.
|
||||
*/
|
||||
@SuppressWarnings("deprecation")
|
||||
public EpollEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
|
||||
this(nThreads, threadFactory, 128);
|
||||
this(nThreads, threadFactory, 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new instance using the specified number of threads, the given {@link ThreadFactory} and the given
|
||||
* maximal amount of epoll events to handle per epollWait(...).
|
||||
*
|
||||
* @deprecated Use {@link #EpollEventLoopGroup(int)}, {@link #EpollEventLoopGroup(int)} or
|
||||
* {@link #EpollEventLoopGroup(int, ThreadFactory)}
|
||||
*/
|
||||
@Deprecated
|
||||
public EpollEventLoopGroup(int nThreads, ThreadFactory threadFactory, int maxEventsAtOnce) {
|
||||
super(nThreads, threadFactory, maxEventsAtOnce);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user