You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by Arvind Srinivasan <ar...@sun.com> on 2002/06/10 08:36:47 UTC

Qn about a performance bottleneck in InvokerServlet

The following code snippet is from the serveRequest() method of
org.apache.catalina.servlets.InvokerServlet.java

-----
        String name = "org.apache.catalina.INVOKER." + servletClass;
        String pattern = inServletPath + "/" + servletClass + "/*";
        Wrapper wrapper = null;

        // Synchronize to avoid race conditions when multiple requests
        // try to initialize the same servlet at the same time
        synchronized (this) {

            // Are we referencing an existing servlet class or name?
            wrapper = (Wrapper) context.findChild(servletClass);
            if (wrapper == null)
                wrapper = (Wrapper) context.findChild(name);
            if (wrapper != null) {
                if (debug >= 1)
                    log("Using wrapper for servlet '" +
                        wrapper.getName() + "' with mapping '" +
                        pattern + "'");                
                context.addServletMapping(pattern, wrapper.getName());
             }

            // No, create a new wrapper for the specified servlet class
            else {
-----

What is the purpose of adding a servlet mapping of /servlet/$SERVLET/*
for servlets serviced by the invoker ?

context.addServletMapping is called on every request to the
InvokerServlet and shows up on performance profiles. Removing it did not
affect the behaviour of InvokerServlet but it eliminated this
performance hotspot.

Thanks,
 Arvind

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Qn about a performance bottleneck in InvokerServlet

Posted by Arvind Srinivasan <ar...@sun.com>.
"Craig R. McClanahan" wrote:
 
> The purpose is a performance optimization -- on subsequent requests to
> "/servlet/foo", the container should find an existing mapping for the
> servlet, so it will get called directly instead of going through the
> invoker.
> 
> > context.addServletMapping is called on every request to the
> > InvokerServlet and shows up on performance profiles. Removing it did not
> > affect the behaviour of InvokerServlet but it eliminated this
> > performance hotspot.
> >
> 
> The intent is that the invoker only gets called once for any given
> "/servlet/xxx" pattern.  If it's actually executing the invoker again,
> that's a bug (probably in the way the dynamically registered servlet
> mapping's URL pattern is constructed).
> 

My apologies...the bug was in a change I had made in my tree. The
performance optimization is working as implemented.

 Arvind

--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>


Re: Qn about a performance bottleneck in InvokerServlet

Posted by "Craig R. McClanahan" <cr...@apache.org>.

On Sun, 9 Jun 2002, Arvind Srinivasan wrote:

> Date: Sun, 09 Jun 2002 23:36:47 -0700
> From: Arvind Srinivasan <ar...@sun.com>
> Reply-To: Tomcat Developers List <to...@jakarta.apache.org>,
>      arvind.srinivasan@sun.com
> To: Tomcat Developers List <to...@jakarta.apache.org>
> Subject: Qn about a performance bottleneck in InvokerServlet
>
> The following code snippet is from the serveRequest() method of
> org.apache.catalina.servlets.InvokerServlet.java
>
> -----
>         String name = "org.apache.catalina.INVOKER." + servletClass;
>         String pattern = inServletPath + "/" + servletClass + "/*";
>         Wrapper wrapper = null;
>
>         // Synchronize to avoid race conditions when multiple requests
>         // try to initialize the same servlet at the same time
>         synchronized (this) {
>
>             // Are we referencing an existing servlet class or name?
>             wrapper = (Wrapper) context.findChild(servletClass);
>             if (wrapper == null)
>                 wrapper = (Wrapper) context.findChild(name);
>             if (wrapper != null) {
>                 if (debug >= 1)
>                     log("Using wrapper for servlet '" +
>                         wrapper.getName() + "' with mapping '" +
>                         pattern + "'");
>                 context.addServletMapping(pattern, wrapper.getName());
>              }
>
>             // No, create a new wrapper for the specified servlet class
>             else {
> -----
>
> What is the purpose of adding a servlet mapping of /servlet/$SERVLET/*
> for servlets serviced by the invoker ?
>

The purpose is a performance optimization -- on subsequent requests to
"/servlet/foo", the container should find an existing mapping for the
servlet, so it will get called directly instead of going through the
invoker.

> context.addServletMapping is called on every request to the
> InvokerServlet and shows up on performance profiles. Removing it did not
> affect the behaviour of InvokerServlet but it eliminated this
> performance hotspot.
>

The intent is that the invoker only gets called once for any given
"/servlet/xxx" pattern.  If it's actually executing the invoker again,
that's a bug (probably in the way the dynamically registered servlet
mapping's URL pattern is constructed).

> Thanks,
>  Arvind
>

Craig


--
To unsubscribe, e-mail:   <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>