[#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
94c6c83318
commit
e8b1f033fb
@ -52,7 +52,8 @@ final class EpollEventLoop extends SingleThreadEventLoop {
|
|||||||
private final int epollFd;
|
private final int epollFd;
|
||||||
private final int eventFd;
|
private final int eventFd;
|
||||||
private final IntObjectMap<AbstractEpollChannel> ids = new IntObjectHashMap<AbstractEpollChannel>();
|
private final IntObjectMap<AbstractEpollChannel> ids = new IntObjectHashMap<AbstractEpollChannel>();
|
||||||
private final long[] events;
|
private final boolean allowGrowing;
|
||||||
|
private long[] events;
|
||||||
|
|
||||||
private int id;
|
private int id;
|
||||||
|
|
||||||
@ -62,7 +63,13 @@ final class EpollEventLoop extends SingleThreadEventLoop {
|
|||||||
|
|
||||||
EpollEventLoop(EventLoopGroup parent, Executor executor, int maxEvents) {
|
EpollEventLoop(EventLoopGroup parent, Executor executor, int maxEvents) {
|
||||||
super(parent, executor, false);
|
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;
|
boolean success = false;
|
||||||
int epollFd = -1;
|
int epollFd = -1;
|
||||||
int eventFd = -1;
|
int eventFd = -1;
|
||||||
@ -268,7 +275,10 @@ final class EpollEventLoop extends SingleThreadEventLoop {
|
|||||||
final long ioTime = System.nanoTime() - ioStartTime;
|
final long ioTime = System.nanoTime() - ioStartTime;
|
||||||
runAllTasks(ioTime * (100 - ioRatio) / ioRatio);
|
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()) {
|
if (isShuttingDown()) {
|
||||||
closeAll();
|
closeAll();
|
||||||
if (confirmShutdown()) {
|
if (confirmShutdown()) {
|
||||||
|
@ -62,8 +62,9 @@ public final class EpollEventLoopGroup extends MultithreadEventLoopGroup {
|
|||||||
* {@code executor} to lie very close together.
|
* {@code executor} to lie very close together.
|
||||||
* @param executor the {@link Executor} to use, or {@code null} if the default should be used.
|
* @param executor the {@link Executor} to use, or {@code null} if the default should be used.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public EpollEventLoopGroup(int nEventLoops, Executor executor) {
|
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
|
* @param executorServiceFactory the {@link ExecutorServiceFactory} to use, or {@code null} if the
|
||||||
* default should be used.
|
* default should be used.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public EpollEventLoopGroup(int nEventLoops, ExecutorServiceFactory executorServiceFactory) {
|
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.
|
* {@code executor} to lie very close together.
|
||||||
* @param executor the {@link Executor} to use, or {@code null} if the default should be used.
|
* @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(...).
|
* @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) {
|
public EpollEventLoopGroup(int nEventLoops, Executor executor, int maxEventsAtOnce) {
|
||||||
super(nEventLoops, executor, 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
|
* @param executorServiceFactory the {@link ExecutorServiceFactory} to use, or {@code null} if the default
|
||||||
* should be used.
|
* should be used.
|
||||||
* @param maxEventsAtOnce the maximum number of epoll events to handle per epollWait(...).
|
* @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) {
|
public EpollEventLoopGroup(int nEventLoops, ExecutorServiceFactory executorServiceFactory, int maxEventsAtOnce) {
|
||||||
super(nEventLoops, executorServiceFactory, maxEventsAtOnce);
|
super(nEventLoops, executorServiceFactory, maxEventsAtOnce);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user