You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Grobe, Gary" <Ga...@bmc.com> on 2001/08/01 23:24:29 UTC

do callbacks to engine exist?

After reading the Tomcat architecure docs, I have a question.

Is there anyway to call the invoke method of a container from the webserver
whenever needed. i.e. If I wanted to get the time it takes for the web
server to process a request, could the server engine be invoke()'d to
startTime and when the webserver finished handling the request, is there
some way it could be invoked again to stopTime so that I'd know how long it
took?

I know that in order for the servlet to do this it must handle the request
and I could get the times from the response and then the request, but I'm
looking to see if I can *monitor* (if that's the right word) the web servers
performance or it's requests in some way. Maybe someway to make callbacks to
the webserver?

My reason for wanting apache to handle the requests is because of sites that
have very large connection loads that our clients/or Tomcat will not accept
performace wise. If this part doesn't make sense, please ignore as their are
other reasons also.


Re: do callbacks to engine exist?

Posted by "Craig R. McClanahan" <cr...@apache.org>.
I presume from the questions that you're talking about Tomcat 4, so I will
answer on that basis.

On Wed, 1 Aug 2001, Grobe, Gary wrote:

> 
> After reading the Tomcat architecure docs, I have a question.
> 
> Is there anyway to call the invoke method of a container from the webserver
> whenever needed. i.e. If I wanted to get the time it takes for the web
> server to process a request, could the server engine be invoke()'d to
> startTime and when the webserver finished handling the request, is there
> some way it could be invoked again to stopTime so that I'd know how long it
> took?

Depending on *exactly* what you want to measure, this can be easy or
hard.  Let's assume Tomcat stand-alone first.

The easiest thing to do would be to write a simple Valve that did these
timings, and stick it first in the Valves nested inside the Engine.  This
would track all of the execution time within the core part of Catalina,
but would not include the time used to read and parse the HTTP request, or
the time used to actually send the response back out the socket.

    Aside:  you can do this kind of thing in a portable
    manner by writing a Filter instead.  This would measure
    the time within your application only, but it would run
    on any servlet 2.3 container.  There is just such a filter
    in the "examples" web app included with Tomcat.

If you really want to time Apache+Tomcat, then you need to start the timer
when Apache starts working on the request, and stop the timer after Apache
has completed the response.  That means you'll need to modify Apache code,
not just Tomcat.

> 
> I know that in order for the servlet to do this it must handle the request
> and I could get the times from the response and then the request, but I'm
> looking to see if I can *monitor* (if that's the right word) the web servers
> performance or it's requests in some way. Maybe someway to make callbacks to
> the webserver?
> 

I'm not sure how callbacks would help you ... don't you really want Apache
to report the total time required to its log files?  You might want to
investigate whether there are any Apache plug-in modules that do this kind
of thing.

> My reason for wanting apache to handle the requests is because of sites that
> have very large connection loads that our clients/or Tomcat will not accept
> performace wise. If this part doesn't make sense, please ignore as their are
> other reasons also.
> 
> 

If I were you, I'd consider primarily focusing on the time spent *within*
your app rather than the total time.  However, as I'm sure you know, the
time required to do a particular request will be very much affected by
what else is going on at that particular moment -- one of the eternal
challenges of benchmarking :-).

Craig



RE: do callbacks to engine exist?

Posted by Thom Park <tp...@borland.com>.
You could try adding a <defaultContext> entry at the engine level
which contains an <InstanceListener>.

In the InstanceListener, you could then trap the "before" service event
followed by the "after" service event.

The delta between those two times should be how long the container
spent 'executing' the service.

e.g:

<Engine.....>
	<DefaultContext>
  		<InstanceListener>
    			org.myco.listener
  		</InstanceListener>
	</DefaultContext>
</Engine>

If you just wanted to monitor one specific webapp, just add the
<InstanceListener> at the
<Context> level.

In the instance listener you'd do something like this:

in the instanceEvent method, you could determine which event you were
interested in,

e.g:
  public void instanceEvent(InstanceEvent event) {
    String eventType = event.getType();
	if ( eventType.compareIgnoreCase("beforeService") == 0 ) {
		// start counter
	}
	if ( eventType.compareIgnoreCase("afterService") == 0 ) {
		// stop counter
      }
	// then process the result
	...
  }

note you'd have to track the servlet name, and app being used - all
available from the servlet wrapper and
context. I use the current (convenient) fact that the same thread that the
before event occurs on is hte same
thread as the after event. That way I can use thread local storage to keep
track of the relevent information
pertaining to the servlet.

-Thom

-----Original Message-----
From: Grobe, Gary [mailto:Gary_Grobe@bmc.com]
Sent: Wednesday, August 01, 2001 2:24 PM
To: 'tomcat-user@jakarta.apache.org'
Subject: do callbacks to engine exist?



After reading the Tomcat architecure docs, I have a question.

Is there anyway to call the invoke method of a container from the webserver
whenever needed. i.e. If I wanted to get the time it takes for the web
server to process a request, could the server engine be invoke()'d to
startTime and when the webserver finished handling the request, is there
some way it could be invoked again to stopTime so that I'd know how long it
took?

I know that in order for the servlet to do this it must handle the request
and I could get the times from the response and then the request, but I'm
looking to see if I can *monitor* (if that's the right word) the web servers
performance or it's requests in some way. Maybe someway to make callbacks to
the webserver?

My reason for wanting apache to handle the requests is because of sites that
have very large connection loads that our clients/or Tomcat will not accept
performace wise. If this part doesn't make sense, please ignore as their are
other reasons also.