[#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
5b30dbef38
commit
bed3502772
@ -51,7 +51,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;
|
||||||
|
|
||||||
@ -61,7 +62,13 @@ final class EpollEventLoop extends SingleThreadEventLoop {
|
|||||||
|
|
||||||
EpollEventLoop(EventLoopGroup parent, ThreadFactory threadFactory, int maxEvents) {
|
EpollEventLoop(EventLoopGroup parent, ThreadFactory threadFactory, int maxEvents) {
|
||||||
super(parent, threadFactory, false);
|
super(parent, threadFactory, 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()) {
|
||||||
|
@ -44,14 +44,19 @@ public final class EpollEventLoopGroup extends MultithreadEventLoopGroup {
|
|||||||
/**
|
/**
|
||||||
* Create a new instance using the specified number of threads and the given {@link ThreadFactory}.
|
* Create a new instance using the specified number of threads and the given {@link ThreadFactory}.
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
public EpollEventLoopGroup(int nThreads, ThreadFactory threadFactory) {
|
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
|
* 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(...).
|
* 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) {
|
public EpollEventLoopGroup(int nThreads, ThreadFactory threadFactory, int maxEventsAtOnce) {
|
||||||
super(nThreads, threadFactory, maxEventsAtOnce);
|
super(nThreads, threadFactory, maxEventsAtOnce);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user