Relates issue: NETTY-18 (Performance degradation when Channel.write() is called from outside an I/O thread (NIO transport)

* Extracted NioWorker.WAKEUP_REQUIREMENT_LEVEL to NioProviderMetadata
This commit is contained in:
Trustin Lee 2008-08-19 13:50:42 +00:00
parent 3828b3754a
commit 795b14a7b1
2 changed files with 57 additions and 19 deletions

View File

@ -0,0 +1,53 @@
/*
* JBoss, Home of Professional Open Source
*
* Copyright 2008, Red Hat Middleware LLC, and individual contributors
* by the @author tags. See the COPYRIGHT.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.netty.channel.socket.nio;
/**
* Provides information which is specific to a NIO service provider
* implementation.
*
* @author The Netty Project (netty-dev@lists.jboss.org)
* @author Trustin Lee (tlee@redhat.com)
*
* @version $Rev$, $Date$
*
*/
class NioProviderMetadata {
/**
* FIXME Auto-detect the level
*
* 0 - no need to wake up to get / set interestOps
* 1 - no need to wake up to get interestOps, but need to wake up to set.
* 2 - need to wake up to get / set interestOps
*/
static final int CONSTRAINT_LEVEL = 0;
static {
if (CONSTRAINT_LEVEL < 0 || CONSTRAINT_LEVEL > 2) {
throw new Error(
"Unexpected wakeup requirement level: " +
CONSTRAINT_LEVEL + ", please report this error.");
}
}
}

View File

@ -49,22 +49,7 @@ class NioWorker implements Runnable {
private static final InternalLogger logger =
InternalLoggerFactory.getInstance(NioWorker.class);
/**
* FIXME Auto-detect the level
*
* 0 - no need to wake up to get / set interestOps
* 1 - no need to wake up to get interestOps, but need to wake up to set.
* 2 - need to wake up to get / set interestOps
*/
private static final int WAKEUP_REQUIREMENT_LEVEL = 0;
static {
if (WAKEUP_REQUIREMENT_LEVEL < 0 || WAKEUP_REQUIREMENT_LEVEL > 2) {
throw new Error(
"Unexpected wakeup requirement level: " +
WAKEUP_REQUIREMENT_LEVEL + ", please report this error.");
}
}
private static final int CONSTRAINT_LEVEL = NioProviderMetadata.CONSTRAINT_LEVEL;
private final int bossId;
private final int id;
@ -379,7 +364,7 @@ class NioWorker implements Runnable {
int interestOps;
boolean changed = false;
if (opWrite) {
switch (WAKEUP_REQUIREMENT_LEVEL) {
switch (CONSTRAINT_LEVEL) {
case 0:
interestOps = key.interestOps();
if ((interestOps & SelectionKey.OP_WRITE) == 0) {
@ -429,7 +414,7 @@ class NioWorker implements Runnable {
throw new Error();
}
} else {
switch (WAKEUP_REQUIREMENT_LEVEL) {
switch (CONSTRAINT_LEVEL) {
case 0:
interestOps = key.interestOps();
if ((interestOps & SelectionKey.OP_WRITE) != 0) {
@ -542,7 +527,7 @@ class NioWorker implements Runnable {
boolean changed = false;
try {
switch (WAKEUP_REQUIREMENT_LEVEL) {
switch (CONSTRAINT_LEVEL) {
case 0:
if (key.interestOps() != interestOps) {
key.interestOps(interestOps);