billbarker    2005/06/29 19:49:38

  Modified:    jk/java/org/apache/jk/common ChannelNioSocket.java
                        ChannelSocket.java HandlerRequest.java
                        JkInputStream.java
               jk/java/org/apache/jk/server JkMain.java
  Log:
  Optionally enable buffering on the output stream.
  
  With a 16K bufferSize, the APR connector is no longer the clear winner in 
performance.  For BC, it's currently disabled by default, but it's easy enough 
to change that after some more testing.
  
  Revision  Changes    Path
  1.5       +28 -19    
jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelNioSocket.java
  
  Index: ChannelNioSocket.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelNioSocket.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- ChannelNioSocket.java     15 May 2005 19:14:38 -0000      1.4
  +++ ChannelNioSocket.java     30 Jun 2005 02:49:38 -0000      1.5
  @@ -91,18 +91,19 @@
       private static org.apache.commons.logging.Log log=
           org.apache.commons.logging.LogFactory.getLog( ChannelNioSocket.class 
);
   
  -    int startPort=8009;
  -    int maxPort=8019; // 0 for backward compat.
  -    int port=startPort;
  -    InetAddress inet;
  -    int serverTimeout = 0;
  -    boolean tcpNoDelay=true; // nodelay to true by default
  -    int linger=100;
  -    int socketTimeout = 0;
  -    boolean nioIsBroken = false;
  +    private int startPort=8009;
  +    private int maxPort=8019; // 0 for backward compat.
  +    private int port=startPort;
  +    private InetAddress inet;
  +    private int serverTimeout = 0;
  +    private boolean tcpNoDelay=true; // nodelay to true by default
  +    private int linger=100;
  +    private int socketTimeout = 0;
  +    private boolean nioIsBroken = false;
       private Selector selector = null;
  +    private int bufferSize = 8*1024;
   
  -    long requestCount=0;
  +    private long requestCount=0;
       
       /* Turning this to true will reduce the latency with about 20%.
          But it requires changes in tomcat to make sure client-requested
  @@ -152,6 +153,17 @@
           this.inet=inet;
       }
   
  +    public void setBufferSize(int bs) {
  +        if(bs > 8*1024) {
  +            bufferSize = bs;
  +        }
  +    }
  +
  +    public int getBufferSize() {
  +        return bufferSize;
  +    }
  +
  +
       /**
        * @jmx:managed-attribute description="Bind on a specified address" 
access="READ_WRITE"
        */
  @@ -500,8 +512,7 @@
       }
   
       public int send( Msg msg, MsgContext ep)
  -        throws IOException
  -    {
  +        throws IOException    {
           msg.end(); // Write the packet header
           byte buf[]=msg.getBuffer();
           int len=msg.getLen();
  @@ -511,19 +522,18 @@
   
           OutputStream os=(OutputStream)ep.getNote( osNote );
           os.write( buf, 0, len );
  -        os.flush();
           return len;
       }
   
       public int flush( Msg msg, MsgContext ep)
  -        throws IOException
  -    {
  +        throws IOException    {
  +        OutputStream os=(OutputStream)ep.getNote( osNote );
  +        os.flush();
           return 0;
       }
   
       public int receive( Msg msg, MsgContext ep )
  -        throws IOException
  -    {
  +        throws IOException    {
           if (log.isTraceEnabled()) {
               log.trace("receive() ");
           }
  @@ -1109,8 +1119,7 @@
       }
   
       protected class SocketOutputStream extends OutputStream {
  -        final int BUFFER_SIZE = 8200;
  -        ByteBuffer buffer = ByteBuffer.allocateDirect(BUFFER_SIZE);
  +        ByteBuffer buffer = ByteBuffer.allocateDirect(bufferSize);
           SocketChannel channel;
   
           SocketOutputStream(SocketChannel channel) {
  
  
  
  1.56      +67 -67    
jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelSocket.java
  
  Index: ChannelSocket.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/ChannelSocket.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- ChannelSocket.java        15 May 2005 19:14:38 -0000      1.55
  +++ ChannelSocket.java        30 Jun 2005 02:49:38 -0000      1.56
  @@ -82,23 +82,17 @@
       private static org.apache.commons.logging.Log log=
           org.apache.commons.logging.LogFactory.getLog( ChannelSocket.class );
   
  -    int startPort=8009;
  -    int maxPort=8019; // 0 for backward compat.
  -    int port=startPort;
  -    InetAddress inet;
  -    int serverTimeout;
  -    boolean tcpNoDelay=true; // nodelay to true by default
  -    int linger=100;
  -    int socketTimeout;
  -
  -    long requestCount=0;
  -    
  -    /* Turning this to true will reduce the latency with about 20%.
  -       But it requires changes in tomcat to make sure client-requested
  -       flush() is honored ( on my test, I got 367->433 RPS and
  -       52->35ms average time with a simple servlet )
  -    */
  -    static final boolean BUFFER_WRITE=false;
  +    private int startPort=8009;
  +    private int maxPort=8019; // 0 for backward compat.
  +    private int port=startPort;
  +    private InetAddress inet;
  +    private int serverTimeout;
  +    private boolean tcpNoDelay=true; // nodelay to true by default
  +    private int linger=100;
  +    private int socketTimeout;
  +    private int bufferSize = -1;
  +
  +    private long requestCount=0;
       
       ThreadPool tp=ThreadPool.createThreadPool(true);
   
  @@ -206,6 +200,14 @@
           return maxPort;
       }
   
  +    public void setBufferSize(int bs) {
  +        bufferSize = bs;
  +    }
  +
  +    public int getBufferSize() {
  +        return bufferSize;
  +    }
  +
       /** At startup we'll look for the first free port in the range.
           The difference between this port and the beggining of the range
           is the 'id'.
  @@ -232,27 +234,27 @@
           tp.setMaxThreads(i);
       }
       
  -     public void setMinSpareThreads( int i ) {
  +    public void setMinSpareThreads( int i ) {
           if( log.isDebugEnabled()) log.debug("Setting minSpareThreads " + i);
  -            tp.setMinSpareThreads(i);
  -     }
  -
  -     public void setMaxSpareThreads( int i ) {
  +        tp.setMinSpareThreads(i);
  +    }
  +    
  +    public void setMaxSpareThreads( int i ) {
           if( log.isDebugEnabled()) log.debug("Setting maxSpareThreads " + i);
  -            tp.setMaxSpareThreads(i);
  -     }
  +        tp.setMaxSpareThreads(i);
  +    }
   
       public int getMaxThreads() {
           return tp.getMaxThreads();   
       }
       
  -     public int getMinSpareThreads() {
  +    public int getMinSpareThreads() {
           return tp.getMinSpareThreads();   
  -     }
  +    }
   
  -     public int getMaxSpareThreads() {
  +    public int getMaxSpareThreads() {
           return tp.getMaxSpareThreads();   
  -     }
  +    }
   
       public void setBacklog(int i) {
       }
  @@ -307,8 +309,8 @@
   
           InputStream is=new BufferedInputStream(s.getInputStream());
           OutputStream os;
  -        if( BUFFER_WRITE )
  -            os = new BufferedOutputStream( s.getOutputStream());
  +        if( bufferSize > 0 )
  +            os = new BufferedOutputStream( s.getOutputStream(), bufferSize);
           else
               os = s.getOutputStream();
           ep.setNote( isNote, is );
  @@ -498,8 +500,7 @@
       }
   
       public int send( Msg msg, MsgContext ep)
  -        throws IOException
  -    {
  +        throws IOException    {
           msg.end(); // Write the packet header
           byte buf[]=msg.getBuffer();
           int len=msg.getLen();
  @@ -513,9 +514,8 @@
       }
   
       public int flush( Msg msg, MsgContext ep)
  -        throws IOException
  -    {
  -        if( BUFFER_WRITE ) {
  +        throws IOException    {
  +        if( bufferSize > 0 ) {
               OutputStream os=(OutputStream)ep.getNote( osNote );
               os.flush();
           }
  @@ -523,8 +523,7 @@
       }
   
       public int receive( Msg msg, MsgContext ep )
  -        throws IOException
  -    {
  +        throws IOException    {
           if (log.isDebugEnabled()) {
               log.debug("receive() ");
           }
  @@ -592,8 +591,7 @@
        *
        **/
       public int read( MsgContext ep, byte[] b, int offset, int len)
  -        throws IOException
  -    {
  +        throws IOException    {
           InputStream is=(InputStream)ep.getNote( isNote );
           int pos = 0;
           int got;
  @@ -837,40 +835,42 @@
       public MBeanNotificationInfo[] getNotificationInfo() {
           return notifInfo;
       }
  -}
   
  -class SocketAcceptor implements ThreadPoolRunnable {
  -    ChannelSocket wajp;
  +    static class SocketAcceptor implements ThreadPoolRunnable {
  +     ChannelSocket wajp;
       
  -    SocketAcceptor(ChannelSocket wajp ) {
  -        this.wajp=wajp;
  -    }
  -
  -    public Object[] getInitData() {
  -        return null;
  +     SocketAcceptor(ChannelSocket wajp ) {
  +         this.wajp=wajp;
  +     }
  +     
  +     public Object[] getInitData() {
  +         return null;
  +     }
  +     
  +     public void runIt(Object thD[]) {
  +         wajp.acceptConnections();
  +     }
       }
   
  -    public void runIt(Object thD[]) {
  -        wajp.acceptConnections();
  -    }
  -}
  +    static class SocketConnection implements ThreadPoolRunnable {
  +     ChannelSocket wajp;
  +     MsgContext ep;
  +
  +     SocketConnection(ChannelSocket wajp, MsgContext ep) {
  +         this.wajp=wajp;
  +         this.ep=ep;
  +     }
   
  -class SocketConnection implements ThreadPoolRunnable {
  -    ChannelSocket wajp;
  -    MsgContext ep;
   
  -    SocketConnection(ChannelSocket wajp, MsgContext ep) {
  -        this.wajp=wajp;
  -        this.ep=ep;
  +     public Object[] getInitData() {
  +         return null;
  +     }
  +     
  +     public void runIt(Object perTh[]) {
  +         wajp.processConnection(ep);
  +         ep = null;
  +     }
       }
   
  -
  -    public Object[] getInitData() {
  -        return null;
  -    }
  -    
  -    public void runIt(Object perTh[]) {
  -        wajp.processConnection(ep);
  -        ep = null;
  -    }
   }
  +
  
  
  
  1.47      +1 -0      
jakarta-tomcat-connectors/jk/java/org/apache/jk/common/HandlerRequest.java
  
  Index: HandlerRequest.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/HandlerRequest.java,v
  retrieving revision 1.46
  retrieving revision 1.47
  diff -u -r1.46 -r1.47
  --- HandlerRequest.java       20 May 2005 05:52:02 -0000      1.46
  +++ HandlerRequest.java       30 Jun 2005 02:49:38 -0000      1.47
  @@ -313,6 +313,7 @@
               msg.reset();
               msg.appendByte(AjpConstants.JK_AJP13_CPONG_REPLY);
               ep.getSource().send( msg, ep );
  +            ep.getSource().flush( msg, ep ); // Server needs to get it
               return OK;
   
           case HANDLE_THREAD_END:
  
  
  
  1.19      +1 -0      
jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JkInputStream.java
  
  Index: JkInputStream.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/common/JkInputStream.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- JkInputStream.java        20 May 2005 05:52:02 -0000      1.18
  +++ JkInputStream.java        30 Jun 2005 02:49:38 -0000      1.19
  @@ -214,6 +214,7 @@
               log.debug("refillReadBuffer " + Thread.currentThread());
   
           mc.getSource().send(bodyMsg, mc);
  +        mc.getSource().flush(bodyMsg, mc); // Server needs to get it
   
           // In JNI mode, response will be in bodyMsg. In TCP mode, response 
need to be
           // read
  
  
  
  1.50      +1 -0      
jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkMain.java
  
  Index: JkMain.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/jk/java/org/apache/jk/server/JkMain.java,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -r1.49 -r1.50
  --- JkMain.java       17 Apr 2005 03:41:08 -0000      1.49
  +++ JkMain.java       30 Jun 2005 02:49:38 -0000      1.50
  @@ -486,6 +486,7 @@
           replacements.put("soTimeout", "channelSocket.soTimeout");
           replacements.put("timeout", "channelSocket.timeout");
           replacements.put("address", "channelSocket.address");            
  +        replacements.put("bufferSize", "channelSocket.bufferSize");
           replacements.put("tomcatAuthentication", 
"request.tomcatAuthentication");            
       }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to