[#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:
Norman Maurer 2015-01-29 20:53:52 +01:00
parent 94c6c83318
commit e8b1f033fb
2 changed files with 25 additions and 5 deletions

View File

@ -52,7 +52,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;
@ -62,7 +63,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()) {

View File

@ -62,8 +62,9 @@ public final class EpollEventLoopGroup extends MultithreadEventLoopGroup {
* {@code executor} to lie very close together.
* @param executor the {@link Executor} to use, or {@code null} if the default should be used.
*/
@SuppressWarnings("deprecation")
public EpollEventLoopGroup(int nEventLoops, Executor executor) {
this(nEventLoops, executor, 128);
this(nEventLoops, executor, 0);
}
/**
@ -75,8 +76,9 @@ public final class EpollEventLoopGroup extends MultithreadEventLoopGroup {
* @param executorServiceFactory the {@link ExecutorServiceFactory} to use, or {@code null} if the
* default should be used.
*/
@SuppressWarnings("deprecation")
public EpollEventLoopGroup(int nEventLoops, ExecutorServiceFactory executorServiceFactory) {
this(nEventLoops, executorServiceFactory, 128);
this(nEventLoops, executorServiceFactory, 0);
}
/**
@ -87,7 +89,11 @@ public final class EpollEventLoopGroup extends MultithreadEventLoopGroup {
* {@code executor} to lie very close together.
* @param executor the {@link Executor} to use, or {@code null} if the default should be used.
* @param maxEventsAtOnce the maximum number of epoll events to handle per epollWait(...).
*
* @deprecated Use {@link #EpollEventLoopGroup(int)}, {@link #EpollEventLoopGroup(int)} or
* {@link #EpollEventLoopGroup(int, Executor)}
*/
@Deprecated
public EpollEventLoopGroup(int nEventLoops, Executor executor, int maxEventsAtOnce) {
super(nEventLoops, executor, maxEventsAtOnce);
}
@ -101,7 +107,11 @@ public final class EpollEventLoopGroup extends MultithreadEventLoopGroup {
* @param executorServiceFactory the {@link ExecutorServiceFactory} to use, or {@code null} if the default
* should be used.
* @param maxEventsAtOnce the maximum number of epoll events to handle per epollWait(...).
*
* @deprecated Use {@link #EpollEventLoopGroup(int)}, {@link #EpollEventLoopGroup(int)} or
* {@link #EpollEventLoopGroup(int, ExecutorServiceFactory)}
*/
@Deprecated
public EpollEventLoopGroup(int nEventLoops, ExecutorServiceFactory executorServiceFactory, int maxEventsAtOnce) {
super(nEventLoops, executorServiceFactory, maxEventsAtOnce);
}