From 795b14a7b116111574d019bd38aaaa7e33f61120 Mon Sep 17 00:00:00 2001 From: Trustin Lee Date: Tue, 19 Aug 2008 13:50:42 +0000 Subject: [PATCH] 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 --- .../socket/nio/NioProviderMetadata.java | 53 +++++++++++++++++++ .../netty/channel/socket/nio/NioWorker.java | 23 ++------ 2 files changed, 57 insertions(+), 19 deletions(-) create mode 100644 src/main/java/org/jboss/netty/channel/socket/nio/NioProviderMetadata.java diff --git a/src/main/java/org/jboss/netty/channel/socket/nio/NioProviderMetadata.java b/src/main/java/org/jboss/netty/channel/socket/nio/NioProviderMetadata.java new file mode 100644 index 0000000000..0156864e1a --- /dev/null +++ b/src/main/java/org/jboss/netty/channel/socket/nio/NioProviderMetadata.java @@ -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."); + } + } +} diff --git a/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java b/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java index fef1288121..957d2bc761 100644 --- a/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java +++ b/src/main/java/org/jboss/netty/channel/socket/nio/NioWorker.java @@ -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);