Author: fhanik Date: Fri Mar 23 08:28:39 2007 New Revision: 521765 URL: http://svn.apache.org/viewvc?view=rev&rev=521765 Log: 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
Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java?view=diff&rev=521765&r1=521764&r2=521765 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/http11/Http11NioProcessor.java Fri Mar 23 08:28:39 2007 @@ -936,8 +936,9 @@ 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; } Modified: tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java?view=diff&rev=521765&r1=521764&r2=521765 ============================================================================== --- tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java (original) +++ tomcat/tc6.0.x/trunk/java/org/apache/tomcat/util/net/NioEndpoint.java Fri Mar 23 08:28:39 2007 @@ -1406,7 +1406,7 @@ 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 @@ 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 @@ 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 @@ 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) { --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]