Hi Remy,

I think the performance related change that you made to StandardPipeline can
be improved upon in that it can avoid using a HashMap to store/retrieve the
pipeline stage and instead simply store/retrieve it from an integer variable
in the RequestBase class. Since this codepath (StandardPipeline.invokeNext)
is executed many times per request, replacing the request.getNote() call
with something like request.getPipelineStage() will benefit performance.
I've attached a patch that implements this suggestion.

Thanks,
 Arvind

> remm        02/03/31 20:19:55
>
>   Modified:    catalina/src/share/org/apache/catalina/core
>                         StandardPipeline.java
>   Log:
>   - Use a note in the request instead of a ThreadLocal to keep
> track of the
>     pipeline stage.
>     Note: This could cause problems with a valve that would wrap
> the request,
>     and not delegate the getNote method to the wrapped request.
>
Index: catalina/src/share/org/apache/catalina/Request.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/Request.java,v
retrieving revision 1.5
diff -u -r1.5 Request.java
--- catalina/src/share/org/apache/catalina/Request.java 1 Aug 2001 03:04:04 -0000      
 1.5
+++ catalina/src/share/org/apache/catalina/Request.java 3 Apr 2002 08:40:02 -0000
@@ -210,6 +210,22 @@
     public void setWrapper(Wrapper wrapper);
 
 
+    /**
+     * Set the index of the (next) valve (in the pipeline) that will process
+     * this request.
+     *
+     * @param stage The position of the next valve (in the pipeline)
+     */
+    public void setPipelineStage(int stage);
+
+
+    /**
+     * Return the index (in the pipeline) of the valve that is to process
+     * this request.
+     */
+    public int getPipelineStage();
+
+
     // --------------------------------------------------------- Public Methods
 
 
Index: catalina/src/share/org/apache/catalina/connector/RequestBase.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/connector/RequestBase.java,v
retrieving revision 1.18
diff -u -r1.18 RequestBase.java
--- catalina/src/share/org/apache/catalina/connector/RequestBase.java   18 Mar 2002 
07:15:39 -0000      1.18
+++ catalina/src/share/org/apache/catalina/connector/RequestBase.java   3 Apr 2002 
+08:40:02 -0000
@@ -270,6 +270,13 @@
     protected Wrapper wrapper = null;
 
 
+    /**
+     * The index (in the pipeline) of the valve that is processing/will
+     * process this request.
+     */
+    protected int _stage = 0;
+
+
     // ------------------------------------------------------------- Properties
 
 
@@ -455,6 +462,26 @@
 
         this.wrapper = wrapper;
 
+    }
+
+
+    /**
+     * Set the index of the (next) valve (in the pipeline) that will process
+     * this request.
+     *
+     * @param stage The position of the next valve (in the pipeline)
+     */
+    public void setPipelineStage(int stage) {
+        _stage = stage;
+    }
+
+
+    /**
+     * Return the index (in the pipeline) of the valve that is to process
+     * this request.
+     */
+    public int getPipelineStage() {
+        return _stage;
     }
 
 
Index: catalina/src/share/org/apache/catalina/core/StandardPipeline.java
===================================================================
RCS file: 
/home/cvspublic/jakarta-tomcat-4.0/catalina/src/share/org/apache/catalina/core/StandardPipeline.java,v
retrieving revision 1.5
diff -u -r1.5 StandardPipeline.java
--- catalina/src/share/org/apache/catalina/core/StandardPipeline.java   1 Apr 2002 
04:19:54 -0000       1.5
+++ catalina/src/share/org/apache/catalina/core/StandardPipeline.java   3 Apr 2002 
+08:40:02 -0000
@@ -100,12 +100,6 @@
     implements Pipeline, Contained, Lifecycle, ValveContext {
 
 
-    // -------------------------------------------------------------- Constants
-
-
-    protected static final String STATE = "pipelineState";
-
-
     // ----------------------------------------------------------- Constructors
 
 
@@ -472,8 +466,9 @@
     public void invoke(Request request, Response response)
         throws IOException, ServletException {
 
-        // Initialize the per-thread state for this thread
-        request.setNote(STATE, new PipelineState());
+        // Indicate that the first valve in the pipeline should process
+        // this request
+        request.setPipelineStage(0);
 
         // Invoke the first Valve in this pipeline for this request
         invokeNext(request, response);
@@ -561,10 +556,10 @@
     public void invokeNext(Request request, Response response)
         throws IOException, ServletException {
 
-        // Identify the current subscript for the current request thread
-        PipelineState pipelineState = (PipelineState) request.getNote(STATE);
-        int subscript = pipelineState.stage;
-        pipelineState.stage = pipelineState.stage + 1;
+        // Increment the stage so that the next valve in the pipeline
+        // can process the request
+        int subscript = request.getPipelineStage();
+        request.setPipelineStage(subscript + 1);
 
         // Invoke the requested Valve for the current request thread
         if (subscript < valves.length) {

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

Reply via email to