remm        2005/05/15 08:49:31

  Modified:    http11/src/java/org/apache/coyote/http11
                        InternalAprInputBuffer.java
  Log:
  - Use a direct ByteBuffer for input as well, as the performance impact turned 
out to be bigger than on output (probably
    due to the fact that the byte array used is actually bigger).
  - /usr/sbin/ab.exe -c 20 -k -n 20000 http://127.0.0.1:8080/tomcat.gif, Sun 
Java 5 server, Windows XP with no firewall:
    - APR HTTP: 1.00
    - regular HTTP: 1.03
    - when removing -k, APR is actually slightly faster now (about the same 
very hard to measure difference, though)
  - This means the difference is negligible, and I expect it to be impossible 
to measure when testing over a network. If
    confirmed, these results will make APR recommendable for everyone running a 
Tomcat production server.
  
  Revision  Changes    Path
  1.6       +28 -6     
jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalAprInputBuffer.java
  
  Index: InternalAprInputBuffer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-tomcat-connectors/http11/src/java/org/apache/coyote/http11/InternalAprInputBuffer.java,v
  retrieving revision 1.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- InternalAprInputBuffer.java       15 Apr 2005 17:19:52 -0000      1.5
  +++ InternalAprInputBuffer.java       15 May 2005 15:49:31 -0000      1.6
  @@ -19,6 +19,7 @@
   
   import java.io.IOException;
   import java.io.EOFException;
  +import java.nio.ByteBuffer;
   
   import org.apache.tomcat.jni.Socket;
   import org.apache.tomcat.jni.Status;
  @@ -58,6 +59,7 @@
           headerBuffer2 = new byte[headerBufferSize];
           bodyBuffer = new byte[headerBufferSize];
           buf = headerBuffer1;
  +        bbuf = ByteBuffer.allocateDirect(headerBufferSize);
   
           headerBuffer = new char[headerBufferSize];
           ascbuf = headerBuffer;
  @@ -162,6 +164,12 @@
   
   
       /**
  +     * Direct byte buffer used to perform actual reading.
  +     */
  +    protected ByteBuffer bbuf;
  +
  +
  +    /**
        * Underlying socket.
        */
       protected long socket;
  @@ -393,9 +401,12 @@
               // Read new bytes if needed
               if (pos >= lastValid) {
                   // Do a simple read with a short timeout
  -                int nRead = Socket.recvt
  -                    (socket, buf, pos, buf.length - lastValid, readTimeout);
  +                bbuf.clear();
  +                int nRead = Socket.recvbt
  +                    (socket, bbuf, 0, buf.length - lastValid, readTimeout);
                   if (nRead > 0) {
  +                    bbuf.limit(nRead);
  +                    bbuf.get(buf, pos, nRead);
                       lastValid = pos + nRead;
                   } else {
                       if (Status.APR_STATUS_IS_ETIMEDOUT(-nRead)) {
  @@ -417,9 +428,12 @@
   
           if (pos >= lastValid) {
               // Do a simple read with a short timeout
  -            int nRead = Socket.recvt
  -                (socket, buf, pos, buf.length - lastValid, readTimeout);
  +            bbuf.clear();
  +            int nRead = Socket.recvbt
  +                (socket, bbuf, 0, buf.length - lastValid, readTimeout);
               if (nRead > 0) {
  +                bbuf.limit(nRead);
  +                bbuf.get(buf, pos, nRead);
                   lastValid = pos + nRead;
               } else {
                   if (Status.APR_STATUS_IS_ETIMEDOUT(-nRead)) {
  @@ -758,8 +772,12 @@
                       (sm.getString("iib.requestheadertoolarge.error"));
               }
   
  -            nRead = Socket.recv(socket, buf, pos, buf.length - lastValid);
  +            bbuf.clear();
  +            nRead = Socket.recvb
  +                (socket, bbuf, 0, buf.length - lastValid);
               if (nRead > 0) {
  +                bbuf.limit(nRead);
  +                bbuf.get(buf, pos, nRead);
                   lastValid = pos + nRead;
               } else {
                   if (Status.APR_STATUS_IS_EAGAIN(-nRead)) {
  @@ -774,8 +792,12 @@
               buf = bodyBuffer;
               pos = 0;
               lastValid = 0;
  -            nRead = Socket.recv(socket, buf, 0, buf.length);
  +            bbuf.clear();
  +            nRead = Socket.recvb
  +                (socket, bbuf, 0, buf.length);
               if (nRead > 0) {
  +                bbuf.limit(nRead);
  +                bbuf.get(buf, 0, nRead);
                   lastValid = nRead;
               } else {
                   throw new IOException(sm.getString("iib.failedread"));
  
  
  

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

Reply via email to