Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: ModPerl: ModPerl

Measuring response time Apache request

 

 

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded


marcodisano at gmail

May 24, 2011, 8:30 AM

Post #1 of 12 (1580 views)
Permalink
Measuring response time Apache request

Hi all,
I want to get the response time that Apache spends to serve a request
(from post-read-request phase to the response phase).
Any idea?

Thanks


adam.prime at utoronto

May 24, 2011, 8:35 AM

Post #2 of 12 (1554 views)
Permalink
Re: Measuring response time Apache request [In reply to]

On 11-05-24 11:30 AM, marco wrote:
> Hi all,
> I want to get the response time that Apache spends to serve a request
> (from post-read-request phase to the response phase).
> Any idea?
>
> Thanks

I'm pretty sure there are messages buried in the archives (from torsten)
showing how to do this with $r->push_handlers and Time::HiRes (or
something along those lines). It's not really that complicated though,
you basically just have a PostReadRequestHandler that uses push_handlers
to push a handler into every phase that just logs the current time, or
whatever it is you want to log.

Adam


marcodisano at gmail

May 24, 2011, 8:42 AM

Post #3 of 12 (1553 views)
Permalink
Re: Measuring response time Apache request [In reply to]

Il 24/05/2011 17.35, Adam Prime ha scritto:
> On 11-05-24 11:30 AM, marco wrote:
>> Hi all,
>> I want to get the response time that Apache spends to serve a request
>> (from post-read-request phase to the response phase).
>> Any idea?
>>
>> Thanks
>
> I'm pretty sure there are messages buried in the archives (from
> torsten) showing how to do this with $r->push_handlers and Time::HiRes
> (or something along those lines). It's not really that complicated
> though, you basically just have a PostReadRequestHandler that uses
> push_handlers to push a handler into every phase that just logs the
> current time, or whatever it is you want to log.
>
> Adam
>
>
Hi Adam,
I'm in this list only since 2 weeks. Can you tell me where can I find
this mails?
Thanks a lot.

Best Regards


torsten.foertsch at gmx

May 24, 2011, 9:19 AM

Post #4 of 12 (1553 views)
Permalink
Re: Measuring response time Apache request [In reply to]

On Tuesday, May 24, 2011 17:30:33 marco wrote:
> I want to get the response time that Apache spends to serve a request
> (from post-read-request phase to the response phase).

PerlPostReadRequestHandler "sub { \
use Time::HiRes(); \
use Apache2::RequestUtil(); \
$_[0]->pnotes->{starttime}=Time::HiRes::time; \
0; \
}"

Then in the PerlResponseHandler you can do:

$elapsed=Time::HiRes::time-$r->pnotes->{starttime};

Torsten Förtsch

--
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net


aw at ice-sa

May 24, 2011, 9:20 AM

Post #5 of 12 (1560 views)
Permalink
Re: Measuring response time Apache request [In reply to]

marco wrote:
> Il 24/05/2011 17.35, Adam Prime ha scritto:
>> On 11-05-24 11:30 AM, marco wrote:
>>> Hi all,
>>> I want to get the response time that Apache spends to serve a request
>>> (from post-read-request phase to the response phase).
>>> Any idea?
>>>
>>> Thanks
>>
>> I'm pretty sure there are messages buried in the archives (from
>> torsten) showing how to do this with $r->push_handlers and Time::HiRes
>> (or something along those lines). It's not really that complicated
>> though, you basically just have a PostReadRequestHandler that uses
>> push_handlers to push a handler into every phase that just logs the
>> current time, or whatever it is you want to log.
>>
>> Adam
>>
>>
> Hi Adam,
> I'm in this list only since 2 weeks. Can you tell me where can I find
> this mails?
> Thanks a lot.
>

To answer you last question :

Go to : http://perl.apache.org/
On the left side, there is an item : Mailing lists
This leads you to the : mod_perl Users mailing list
This leads you to the : Searchable archives
where you have a choice of searchable archives.
and have a look for example at "marc.theaimsgroup.com"

Apart from that, and for the main issue :

Is it not easier to just read the Apache access log a posteriori, and filter the lines
which you need ?
With the appropriate LogFormat, you can have the microseconds needed for each request.

See : http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#formats
(parameter %D)

e.g.
LogFormat "%a - %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %D" combined_ip
CustomLog /var/log/apache2/somehost/access.log combined_ip

Sample log line with the above format (server name changed for privacy) :

192.168.193.11 - U367532 [24/May/2011:17:49:05 +0200] "POST /starweb/OPAC/servlet.starweb
HTTP/1.0" 200 28029
"http://somehost.mycompany.com/starweb/OPAC/servlet.starweb?path=OPAC/STARLibs_OPAC_xxx.web"
"Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.2; .NET CLR 1.1.4322; .NET CLR 2.0.50727;
.NET CLR 3.0.04506.648; .NET CLR 3.5.21022; .NET CLR 3.0.4506.2152; .NET CLR 3.5.30729;
.NET4.0C; .NET4.0E)" 147626


(the last number is the number of microseconds needed to process that request)


torsten.foertsch at gmx

May 24, 2011, 9:50 AM

Post #6 of 12 (1549 views)
Permalink
Re: Measuring response time Apache request [In reply to]

On Tuesday, May 24, 2011 18:20:23 André Warnier wrote:
> Is it not easier to just read the Apache access log a posteriori, and
> filter the lines which you need ?
> With the appropriate LogFormat, you can have the microseconds needed
> for each request.

With Apache2::ModLogConfig you can even install a Perl handler to be
called by CustomLog:

<Perl>
sub My::LogReceiver {
my ($r, $usec)=@_;
...
}
</Perl>

CustomLog "@perl: My::LogReceiver" "%D"

But Marco wanted PostReadRequest => Response not PostReadRequest => Log.

Torsten Förtsch

--
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net


marcodisano at gmail

May 24, 2011, 10:02 AM

Post #7 of 12 (1576 views)
Permalink
Re: Measuring response time Apache request [In reply to]

Il 24/05/2011 18.19, Torsten Förtsch ha scritto:
> On Tuesday, May 24, 2011 17:30:33 marco wrote:
>> I want to get the response time that Apache spends to serve a request
>> (from post-read-request phase to the response phase).
> PerlPostReadRequestHandler "sub { \
> use Time::HiRes(); \
> use Apache2::RequestUtil(); \
> $_[0]->pnotes->{starttime}=Time::HiRes::time; \
> 0; \
> }"
>
> Then in the PerlResponseHandler you can do:
>
> $elapsed=Time::HiRes::time-$r->pnotes->{starttime};
>
> Torsten Förtsch
>
Hi,
I follow your suggest using Time::HiRes but I have an error when I try
to start apache. Here's my code(it is only an example):
This is the script that will be executed as response handler, but it
doesn't work because doesn't print the time.
*use strict;
use warnings;

use Time::HiRes qw(gettimeofday tv_interval);

use Apache2::RequestRec ();
use Apache2::RequestIO ();

use Apache2::Const -compile => 'OK';

sub handler{
my $r = shift;
my $start_time = [ gettimeofday ];
my $end_time = [ gettimeofday ];
my $elapsed = tv_interval($start_time,$end_time);
$r->send_http_header('text/html');
$r->print ($elapsed);
return Apache2::Const::OK;
}
1;
*
In httpd.conf file I have:

PerlPostReadRequestHandler Dir::touch #this script is well executed
PerlResponseHandler Dir::timediff #this handler (below)
is not executed!!!!!!!!!!!!!!!!!!!

why it doesn't work?
Can you help me,please?
Thanks for your answers!


torsten.foertsch at gmx

May 24, 2011, 11:11 AM

Post #8 of 12 (1545 views)
Permalink
Re: Measuring response time Apache request [In reply to]

On Tuesday, May 24, 2011 19:02:50 marco wrote:
> In httpd.conf file I have:
>
> PerlPostReadRequestHandler Dir::touch #this script is well
> executed PerlResponseHandler Dir::timediff #this
> handler (below) is not executed!!!!!!!!!!!!!!!!!!!

perhaps you forgot

SetHandler modperl

The response phase is a bit different from the other phases. The
"SetHandler" is needed to make apache call the perl interpreter in the
response phase.

Torsten Förtsch

--
Need professional modperl support? Hire me! (http://foertsch.name)

Like fantasy? http://kabatinte.net


marcodisano at gmail

May 24, 2011, 11:21 AM

Post #9 of 12 (1545 views)
Permalink
Re: Measuring response time Apache request [In reply to]

Il 24/05/2011 20.11, Torsten Förtsch ha scritto:
> On Tuesday, May 24, 2011 19:02:50 marco wrote:
>> In httpd.conf file I have:
>>
>> PerlPostReadRequestHandler Dir::touch #this script is well
>> executed PerlResponseHandler Dir::timediff #this
>> handler (below) is not executed!!!!!!!!!!!!!!!!!!!
> perhaps you forgot
>
> SetHandler modperl
>
> The response phase is a bit different from the other phases. The
> "SetHandler" is needed to make apache call the perl interpreter in the
> response phase.
>
> Torsten Förtsch
>
Ok i solved it, thanks a lot Torsten!!!!!!!!!!!


aw at ice-sa

May 24, 2011, 11:24 AM

Post #10 of 12 (1544 views)
Permalink
Re: Measuring response time Apache request [In reply to]

Torsten Förtsch wrote:
> On Tuesday, May 24, 2011 18:20:23 André Warnier wrote:
>> Is it not easier to just read the Apache access log a posteriori, and
>> filter the lines which you need ?
>> With the appropriate LogFormat, you can have the microseconds needed
>> for each request.
>
> With Apache2::ModLogConfig you can even install a Perl handler to be
> called by CustomLog:
>
> <Perl>
> sub My::LogReceiver {
> my ($r, $usec)=@_;
> ...
> }
> </Perl>
>
> CustomLog "@perl: My::LogReceiver" "%D"
>
> But Marco wanted PostReadRequest => Response not PostReadRequest => Log.
>
I know, but the difference is likely to be only a Muckeseckele, as they say around here.
:-)


cosimo at streppone

May 24, 2011, 5:29 PM

Post #11 of 12 (1537 views)
Permalink
Re: Measuring response time Apache request [In reply to]

On Wed, 25 May 2011 02:20:23 +1000, André Warnier <aw [at] ice-sa> wrote:

> marco wrote:
>> Il 24/05/2011 17.35, Adam Prime ha scritto:
>>> On 11-05-24 11:30 AM, marco wrote:

>>>> Hi all,
>>>> I want to get the response time that Apache spends to serve a request
>>>> (from post-read-request phase to the response phase).
>>>> Any idea?

> See : http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#formats
> (parameter %D)

Hi Marco,

I also use "%D" as André suggested.

Add "%D" to your LogFormat string,
unless you need to do something in your application
with the request time, like for example
include it in a html comment.

If you're using Debian/Ubuntu, just change your LogFormat
or create a file like "/etc/apache2/conf.d/log-request-time" with:

LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\"
time:%D" combined

that should be it.

--
Cosimo


marcodisano at gmail

May 25, 2011, 7:41 AM

Post #12 of 12 (1533 views)
Permalink
Re: Measuring response time Apache request [In reply to]

Il 25/05/2011 2.29, Cosimo Streppone ha scritto:
> On Wed, 25 May 2011 02:20:23 +1000, André Warnier <aw [at] ice-sa> wrote:
>
>> marco wrote:
>>> Il 24/05/2011 17.35, Adam Prime ha scritto:
>>>> On 11-05-24 11:30 AM, marco wrote:
>
>>>>> Hi all,
>>>>> I want to get the response time that Apache spends to serve a request
>>>>> (from post-read-request phase to the response phase).
>>>>> Any idea?
>
>> See : http://httpd.apache.org/docs/2.2/mod/mod_log_config.html#formats
>> (parameter %D)
>
> Hi Marco,
>
> I also use "%D" as André suggested.
>
> Add "%D" to your LogFormat string,
> unless you need to do something in your application
> with the request time, like for example
> include it in a html comment.
>
> If you're using Debian/Ubuntu, just change your LogFormat
> or create a file like "/etc/apache2/conf.d/log-request-time" with:
>
> LogFormat "%a %l %u %t \"%r\" %>s %b \"%{Referer}i\"
> \"%{User-Agent}i\" time:%D" combined
>
> that should be it.
>
Hi,
thanks for your answer. I tried it and it works!!!!

ModPerl modperl RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.