Implement spinning in SelectorUtil.select()
- this seems to improve performance when the number of connections is very small
This commit is contained in:
parent
cab983244d
commit
83f1b5fa35
@ -26,11 +26,6 @@ final class SelectorUtil {
|
|||||||
private static final InternalLogger logger =
|
private static final InternalLogger logger =
|
||||||
InternalLoggerFactory.getInstance(SelectorUtil.class);
|
InternalLoggerFactory.getInstance(SelectorUtil.class);
|
||||||
|
|
||||||
public static final int DEFAULT_IO_THREADS = Runtime.getRuntime().availableProcessors() * 2;
|
|
||||||
|
|
||||||
public static final int DEFAULT_IO_ACCEPTING_THREADS = 1;
|
|
||||||
|
|
||||||
|
|
||||||
// Workaround for JDK NIO bug.
|
// Workaround for JDK NIO bug.
|
||||||
//
|
//
|
||||||
// See:
|
// See:
|
||||||
@ -52,6 +47,11 @@ final class SelectorUtil {
|
|||||||
|
|
||||||
static void select(Selector selector) throws IOException {
|
static void select(Selector selector) throws IOException {
|
||||||
try {
|
try {
|
||||||
|
for (int i = 0; i < 32; i ++) {
|
||||||
|
if (selector.selectNow() > 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
selector.select(10);
|
selector.select(10);
|
||||||
} catch (CancelledKeyException e) {
|
} catch (CancelledKeyException e) {
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
@ -60,7 +60,6 @@ final class SelectorUtil {
|
|||||||
" raised by a Selector - JDK bug?", e);
|
" raised by a Selector - JDK bug?", e);
|
||||||
}
|
}
|
||||||
// Harmless exception - log anyway
|
// Harmless exception - log anyway
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user