You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by mt...@apache.org on 2006/11/26 10:29:16 UTC

svn commit: r479317 - in /tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp: AjpAprProcessor.java AjpProcessor.java Constants.java

Author: mturk
Date: Sun Nov 26 01:29:15 2006
New Revision: 479317

URL: http://svn.apache.org/viewvc?view=rev&rev=479317
Log:
Compress outgoing response headers according to the
AJP13 protocol specification.

Modified:
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
    tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java?view=diff&rev=479317&r1=479316&r2=479317
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpAprProcessor.java Sun Nov 26 01:29:15 2006
@@ -960,9 +960,15 @@
         // Other headers
         int numHeaders = headers.size();
         responseHeaderMessage.appendInt(numHeaders);
-        for (int i = 0; i < numHeaders; i++) {
+        for (int i = 0; i < numHeaders; i++) {            
             MessageBytes hN = headers.getName(i);
-            responseHeaderMessage.appendBytes(hN);
+            int hC = Constants.getResponseAjpIndex(hN.toString());
+            if (hC > 0) {
+                responseHeaderMessage.appendInt(hC);
+            }
+            else {
+                responseHeaderMessage.appendBytes(hN);
+            }
             MessageBytes hV=headers.getValue(i);
             responseHeaderMessage.appendBytes(hV);
         }

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java?view=diff&rev=479317&r1=479316&r2=479317
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/AjpProcessor.java Sun Nov 26 01:29:15 2006
@@ -929,7 +929,13 @@
         responseHeaderMessage.appendInt(numHeaders);
         for (int i = 0; i < numHeaders; i++) {
             MessageBytes hN = headers.getName(i);
-            responseHeaderMessage.appendBytes(hN);
+            int hC = Constants.getResponseAjpIndex(hN.toString());
+            if (hC > 0) {
+                responseHeaderMessage.appendInt(hC);
+            }
+            else {
+                responseHeaderMessage.appendBytes(hN);
+            }
             MessageBytes hV=headers.getValue(i);
             responseHeaderMessage.appendBytes(hV);
         }

Modified: tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java
URL: http://svn.apache.org/viewvc/tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java?view=diff&rev=479317&r1=479316&r2=479317
==============================================================================
--- tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java (original)
+++ tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp/Constants.java Sun Nov 26 01:29:15 2006
@@ -17,6 +17,9 @@
 
 package org.apache.coyote.ajp;
 
+import java.lang.IndexOutOfBoundsException;
+import java.util.Hashtable;
+import java.util.Locale;
 import org.apache.tomcat.util.buf.ByteChunk;
 
 
@@ -67,6 +70,7 @@
     public static final int SC_RESP_SERVLET_ENGINE      = 0xA009;
     public static final int SC_RESP_STATUS              = 0xA00A;
     public static final int SC_RESP_WWW_AUTHENTICATE    = 0xA00B;
+    public static final int SC_RESP_AJP13_MAX           = 11;
 
     // Integer codes for common (optional) request attribute names
     public static final byte SC_A_CONTEXT       = 1;  // XXX Unused
@@ -179,7 +183,47 @@
             "user-agent"
     };
 
+    // Translates integer codes to response header names
+    public static final String []responseTransArray = {
+            "content-type",
+            "content-language",
+            "content-length",
+            "date",
+            "last-modified",
+            "location",
+            "set-cookie",
+            "set-cookie2",
+            "servlet-engine",
+            "status",
+            "www-authenticate"
+    };
+
+    private static final Hashtable<String,Integer>  responseTransHash =
+        new Hashtable<String,Integer>(20);
+
+    static {
+        try {
+            int i;
+            for (i = 0; i < SC_RESP_AJP13_MAX; i++) {
+                responseTransHash.put(responseTransArray[i],
+                                      new Integer(0xA001 + i));
+            }
+        }
+        catch (Exception e) {
+            // Do nothing
+        }
+    }    
+
+    public static final int getResponseAjpIndex(String header)
+    {
+        Integer i = responseTransHash.get(header.toLowerCase(Locale.US));
+        if (i == null)
+            return 0;
+        else
+            return i.intValue();
+    }
 
+    
     /**
      * CRLF.
      */



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r479317 - in /tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp: AjpAprProcessor.java AjpProcessor.java Constants.java

Posted by Remy Maucherat <re...@apache.org>.
Mladen Turk wrote:
> Remy Maucherat wrote:
>> mturk@apache.org wrote:
>>> +        Integer i = 
>>> responseTransHash.get(header.toLowerCase(Locale.US));
>>
>> -0. The String operations take away any benefit this could have.
>>
> 
> Perhaps for CPU usage on the Tomcat, that is annihilated by the
> lower processing on the mod_jk side.

It seems the CPU is more important on the application server side. 
Obviously, one garbage string is not very important, but I did bother 
optimizing the rest, so I appreciate when others try to do the same 
thing too.

> Also the network traffic is much 
> lower.

I don't see how there can be a bandwidth issue between the front end 
server and the appserver.

> The standard header having Content-Type, Content-Length and Date
> is 30 bytes smaller.

Silly me who thought the actually relevant bandwidth was between the 
front end and the client ;)

> If we can guarantee header names will always be in the proper
> case, the toLowerCase can be omitted, or by using something
> other to compare with array of string.

It's up to you if you want to add this feature. At the moment, I think I 
have to be against this change because the implementation is simply ugly.

Rémy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r479317 - in /tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp: AjpAprProcessor.java AjpProcessor.java Constants.java

Posted by Mladen Turk <mt...@apache.org>.
Remy Maucherat wrote:
> mturk@apache.org wrote:
>> +        Integer i = 
>> responseTransHash.get(header.toLowerCase(Locale.US));
> 
> -0. The String operations take away any benefit this could have.
> 

Perhaps for CPU usage on the Tomcat, that is annihilated by the
lower processing on the mod_jk side. Also the network traffic is much lower.
The standard header having Content-Type, Content-Length and Date
is 30 bytes smaller.

If we can guarantee header names will always be in the proper
case, the toLowerCase can be omitted, or by using something
other to compare with array of string.

Regards,
Mladen.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org


Re: svn commit: r479317 - in /tomcat/tc6.0.x/trunk/java/org/apache/coyote/ajp: AjpAprProcessor.java AjpProcessor.java Constants.java

Posted by Remy Maucherat <re...@apache.org>.
mturk@apache.org wrote:
> +        Integer i = responseTransHash.get(header.toLowerCase(Locale.US));

-0. The String operations take away any benefit this could have.

Rémy

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org