From: fhanik Date: Fri, 23 Mar 2007 15:28:39 +0000 (+0000) Subject: Optimized sendfile a tiny bit. Instead of handing off to the poller, since we are... X-Git-Url: https://git.internetallee.de/?a=commitdiff_plain;h=a0ba12a14b5a054cace25a0347344dbf2752bcbf;p=tomcat7.0 Optimized sendfile a tiny bit. Instead of handing off to the poller, since we are already on a thread then try it first on, and if we are not done, then simply register with the poller git-svn-id: https://svn.apache.org/repos/asf/tomcat/tc6.0.x/trunk@521765 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/java/org/apache/coyote/http11/Http11NioProcessor.java b/java/org/apache/coyote/http11/Http11NioProcessor.java index 4b58aa784..8300d6747 100644 --- a/java/org/apache/coyote/http11/Http11NioProcessor.java +++ b/java/org/apache/coyote/http11/Http11NioProcessor.java @@ -936,8 +936,9 @@ public class Http11NioProcessor implements ActionHook { KeyAttachment ka = (KeyAttachment)socket.getAttachment(false); ka.setSendfileData(sendfileData); sendfileData.keepAlive = keepAlive; - endpoint.getPoller0().add(socket,SelectionKey.OP_WRITE); - openSocket = true; + SelectionKey key = socket.getIOChannel().keyFor(socket.getPoller().getSelector()); + //do the first write on this thread, might as well + openSocket = socket.getPoller().processSendfile(key,ka,true); break; } diff --git a/java/org/apache/tomcat/util/net/NioEndpoint.java b/java/org/apache/tomcat/util/net/NioEndpoint.java index 474d550ef..33d5bcacb 100644 --- a/java/org/apache/tomcat/util/net/NioEndpoint.java +++ b/java/org/apache/tomcat/util/net/NioEndpoint.java @@ -1406,7 +1406,7 @@ public class NioEndpoint { NioChannel channel = attachment.getChannel(); if (sk.isReadable() || sk.isWritable() ) { if ( attachment.getSendfileData() != null ) { - processSendfile(sk,attachment); + processSendfile(sk,attachment,true); } else if ( attachment.getComet() ) { //check if thread is available if ( isWorkerAvailable() ) { @@ -1451,7 +1451,7 @@ public class NioEndpoint { return result; } - protected void processSendfile(SelectionKey sk, KeyAttachment attachment) { + public boolean processSendfile(SelectionKey sk, KeyAttachment attachment, boolean reg) { try { //unreg(sk,attachment);//only do this if we do process send file on a separate thread SendfileData sd = attachment.getSendfileData(); @@ -1459,7 +1459,7 @@ public class NioEndpoint { File f = new File(sd.fileName); if ( !f.exists() ) { cancelledKey(sk,SocketStatus.ERROR,false); - return; + return false; } sd.fchannel = new FileInputStream(f).getChannel(); } @@ -1472,17 +1472,23 @@ public class NioEndpoint { if ( sd.length <= 0 ) { attachment.setSendfileData(null); if ( sd.keepAlive ) - reg(sk,attachment,SelectionKey.OP_READ); + if (reg) reg(sk,attachment,SelectionKey.OP_READ); else cancelledKey(sk,SocketStatus.STOP,false); + } else if ( attachment.interestOps() == 0 && reg ) { + reg(sk,attachment,SelectionKey.OP_WRITE); } }catch ( IOException x ) { - if ( log.isDebugEnabled() ) log.warn("Unable to complete send file", x); + if ( log.isDebugEnabled() ) log.warn("Unable to complete sendfile request:", x); + else log.warn("Unable to complete sendfile request:"+x.getMessage()); cancelledKey(sk,SocketStatus.ERROR,false); + return false; }catch ( Throwable t ) { log.error("",t); cancelledKey(sk, SocketStatus.ERROR, false); + return false; } + return true; } protected void unreg(SelectionKey sk, KeyAttachment attachment) {