You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tapestry.apache.org by "Cormier, Ross" <Ro...@Williams.com> on 2005/12/01 22:09:56 UTC

Performance Metrics

I would like to time page loading/rendering throughout my app.  I have
overridded doService in ApplicationServlet which allows me to time
everything, too much actually.  Is it possible to use Tapestry and
determine what 'type' of request is being processed?  I could always
look at the RequestParameters and filter out assets, etc. but it would
be nice to use the framework.
 
 
    protected void doService(HttpServletRequest request,
HttpServletResponse response) 
    throws IOException, ServletException 
    {
        ToStringBuilder builder = new ToStringBuilder("",
MyEngine.STRING_STYLE);
                
        MultiTimer.startTimer(request, 'd', "doService");
        super.doService(request, response);
        String pageInfo = ""; //I would like to figure out if the
request is for a page, asset, get the page's name, etc.
        MultiTimer.stopTimerPrint(request, 'd', "doService", pageInfo);
    }        

 
Thanks,
Ross

Re: Performance Metrics

Posted by Konstantin Ignatyev <kg...@yahoo.com>.
Simple rendering meter does not tell the whole story
therefore I have created a simplistic PageMeter that
calculates the whole time to render a page including
all the artifacts.

For example for my test index page it prints:
1296 ms - /pagemeter/
1 ms - /pagemeter/images/TrafficOff.gif
0 ms - /pagemeter/images/TrafficRed.gif
1 ms - /pagemeter/images/TrafficYellow.gif
0 ms - /pagemeter/images/TrafficGreen.gif
1454 ms - Length of the sequence


As you may notice the total time is not equal to the
sum of render times because it takes into account time
for browser to think and time for stuff to go over the
network.

I hope you may want it useful during development. 
Note: current assumptions are 
- the filter works for single client environment only;
- requests for the page parts are not delayyed more
than 500 ms (increase quietPeriodMS if your network is
too slow ) 

In the web.xml
<web-app>
  <filter>
    <filter-name>meter</filter-name>
   
<filter-class>com.kgionline.web.filter.PageMeter</filter-class>
  </filter>
  <filter-mapping>
    <filter-name>meter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>


package com.kgionline.web.filter;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.io.PrintStream;
import java.util.Timer;
import java.util.TimerTask;

/**
 * Created by IntelliJ IDEA.
 * User: konstantinignatyev
 * Date: Nov 22, 2005
 * Time: 1:46:31 PM
 */
public class PageMeter implements Filter {
  Timer t ;
  long quietPeriodMS = 500;
  long firstInTheChain = -1;
  long lastRequest = -1;

  PrintStream  out = System.out;

  private boolean inRequest = false;

  public synchronized boolean isInRequest(){
    return inRequest;
  }

  public synchronized void setInRequest( boolean
inRequest ){
    this.inRequest = inRequest;
  }


  public void init( FilterConfig filterConfig ) throws
ServletException{
    reset();
    t = new Timer( true );
    TimerTask task = new TimerTask(){

      public void run(){
        if( ! isInRequest() ){
         checkQuietness();
        }
        //System.out.println( "." );
      }
    };
    t.scheduleAtFixedRate( task, 0, 300);

  }

  public void doFilter( ServletRequest servletRequest,
ServletResponse servletResponse, FilterChain
filterChain ) throws IOException, ServletException{
    long start = System.currentTimeMillis() ;
    requestStarted();
    filterChain.doFilter( servletRequest,
servletResponse );
    requestFinished( start,
System.currentTimeMillis(), servletRequest );

  }

  private void requestStarted(){
    setInRequest( true );
    if( firstInTheChain == -1 ){
      firstInTheChain = System.currentTimeMillis();
    }
  }

  private void requestFinished( long start, long end,
ServletRequest servletRequest ){
    setInRequest( false );
    lastRequest = System.currentTimeMillis();
    if( servletRequest instanceof HttpServletRequest){
      HttpServletRequest r = ( HttpServletRequest )
servletRequest;
      printLength( end - start, r.getRequestURI() );
    }
  }

  private void printLength( long l, String requestInfo
){
    out.println( l + " ms - " + requestInfo);
  }

  public void destroy(){

  }

  private void checkQuietness(){
    if( firstInTheChain == -1 ) return;
    if( System.currentTimeMillis() - lastRequest>
quietPeriodMS ){
      reset();
    }
  }

  private void reset(){
    printLength( lastRequest - firstInTheChain,
"Length of the sequence\n\n\n\n\n");
    firstInTheChain = -1;
    lastRequest = -1;

  }

}





---------------------------------------------------------------------
To unsubscribe, e-mail: tapestry-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: tapestry-user-help@jakarta.apache.org


Re: Performance Metrics

Posted by Geoff Hopson <ge...@gmail.com>.
Or use JMX in Hivemind...

in hivemodule.xml

        <!-- JMX -->
        <contribution configuration-id="hivemind.EagerLoad">
                <load service-id="hivemind.management.MBeanRegistry"/>
        </contribution>


        <service-point id="statisticsService" interface="com.anite.MyService
">
                <invoke-factory>
                <construct      class="com.anite.MyServiceImpl"
                                        initialize-method="init">
                        </construct>
        </invoke-factory>
                <interceptor service-id="
hivemind.management.PerformanceMonitorFactory"></interceptor>
        </service-point>

Use the exclude directive to cut out the stuff you don't want, connect up to
port 8090 and away you go...

Geoff


On 01/12/05, Jesse Kuhnert <jk...@gmail.com> wrote:
>
> I think for your uses you may find the use/getting familiar with hivemind
> the best approach. Almost every piece of the tapestry core is broken up
> into
> hivemind services, which allows you to do a lot of very cool things, the
> least of which would be taking something like this:
>
> http://jakarta.apache.org/hivemind/hivemind/LoggingInterceptor.html
>
> And turning it into a performance logging interceptor :) To apply the
> interceptor to an existing hivemind/tapestry service this is sort of what
> it
> would look like:
>
> <implementation service-id="hivemind.ThreadEventNotifier" >
>     <interceptor service-id="hivemind.LoggingInterceptor" />
>     </implementation>
>
> Hope that helps.
>
> jesse
>
> On 12/1/05, Cormier, Ross <Ro...@williams.com> wrote:
> >
> > I would like to time page loading/rendering throughout my app.  I have
> > overridded doService in ApplicationServlet which allows me to time
> > everything, too much actually.  Is it possible to use Tapestry and
> > determine what 'type' of request is being processed?  I could always
> > look at the RequestParameters and filter out assets, etc. but it would
> > be nice to use the framework.
> >
> >
> >     protected void doService(HttpServletRequest request,
> > HttpServletResponse response)
> >     throws IOException, ServletException
> >     {
> >         ToStringBuilder builder = new ToStringBuilder("",
> > MyEngine.STRING_STYLE);
> >
> >         MultiTimer.startTimer(request, 'd', "doService");
> >         super.doService(request, response);
> >         String pageInfo = ""; //I would like to figure out if the
> > request is for a page, asset, get the page's name, etc.
> >         MultiTimer.stopTimerPrint(request, 'd', "doService", pageInfo);
> >     }
> >
> >
> > Thanks,
> > Ross
> >
> >
>
>

Re: Performance Metrics

Posted by Jesse Kuhnert <jk...@gmail.com>.
I think for your uses you may find the use/getting familiar with hivemind
the best approach. Almost every piece of the tapestry core is broken up into
hivemind services, which allows you to do a lot of very cool things, the
least of which would be taking something like this:

http://jakarta.apache.org/hivemind/hivemind/LoggingInterceptor.html

And turning it into a performance logging interceptor :) To apply the
interceptor to an existing hivemind/tapestry service this is sort of what it
would look like:

<implementation service-id="hivemind.ThreadEventNotifier" >
    <interceptor service-id="hivemind.LoggingInterceptor" />
    </implementation>

Hope that helps.

jesse

On 12/1/05, Cormier, Ross <Ro...@williams.com> wrote:
>
> I would like to time page loading/rendering throughout my app.  I have
> overridded doService in ApplicationServlet which allows me to time
> everything, too much actually.  Is it possible to use Tapestry and
> determine what 'type' of request is being processed?  I could always
> look at the RequestParameters and filter out assets, etc. but it would
> be nice to use the framework.
>
>
>     protected void doService(HttpServletRequest request,
> HttpServletResponse response)
>     throws IOException, ServletException
>     {
>         ToStringBuilder builder = new ToStringBuilder("",
> MyEngine.STRING_STYLE);
>
>         MultiTimer.startTimer(request, 'd', "doService");
>         super.doService(request, response);
>         String pageInfo = ""; //I would like to figure out if the
> request is for a page, asset, get the page's name, etc.
>         MultiTimer.stopTimerPrint(request, 'd', "doService", pageInfo);
>     }
>
>
> Thanks,
> Ross
>
>