Use nanos to detect the jdk epoll bug. Also use 80% of the select timeout to detect it to be more save. Thanks to @kimchy for spot this
This commit is contained in:
parent
798390fc4d
commit
f8a99a0108
@ -242,6 +242,10 @@ abstract class AbstractNioWorker implements Worker {
|
||||
boolean shutdown = false;
|
||||
int selectReturnsImmediately = 0;
|
||||
Selector selector = this.selector;
|
||||
|
||||
// use 80% of the timeout for measure
|
||||
long minSelectTimeout = SelectorUtil.SELECT_TIMEOUT_NANOS / 100 * 80;
|
||||
|
||||
for (;;) {
|
||||
wakenUp.set(false);
|
||||
|
||||
@ -257,8 +261,8 @@ abstract class AbstractNioWorker implements Worker {
|
||||
int selected = SelectorUtil.select(selector);
|
||||
if (selected == 0) {
|
||||
long timeBlocked = System.nanoTime() - beforeSelect;
|
||||
if (timeBlocked < SelectorUtil.SELECT_WAIT_TIME) {
|
||||
// returned before the SELECT_WAIT_TIME elapsed with nothing select.
|
||||
if (timeBlocked < minSelectTimeout) {
|
||||
// returned before the minSelectTimeout elapsed with nothing select.
|
||||
// this may be the cause of the jdk epoll(..) bug, so increment the counter
|
||||
// which we use later to see if its really the jdk bug.
|
||||
selectReturnsImmediately++;
|
||||
|
@ -28,7 +28,8 @@ final class SelectorUtil {
|
||||
|
||||
static final int DEFAULT_IO_THREADS = Runtime.getRuntime().availableProcessors() * 2;
|
||||
|
||||
static final int SELECT_WAIT_TIME = 10;
|
||||
static final int SELECT_TIMEOUT = 10;
|
||||
static final int SELECT_TIMEOUT_NANOS = SELECT_TIMEOUT * 1000;
|
||||
|
||||
// Workaround for JDK NIO bug.
|
||||
//
|
||||
@ -51,7 +52,7 @@ final class SelectorUtil {
|
||||
|
||||
static int select(Selector selector) throws IOException {
|
||||
try {
|
||||
return selector.select(SELECT_WAIT_TIME);
|
||||
return selector.select(SELECT_TIMEOUT);
|
||||
} catch (CancelledKeyException e) {
|
||||
if (logger.isDebugEnabled()) {
|
||||
logger.debug(
|
||||
|
Loading…
Reference in New Issue
Block a user