httpd-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jim Albert <...@netrition.com>
Subject Re: [users@httpd] Make apache sleep
Date Tue, 23 Oct 2007 17:18:53 GMT
Jim Albert wrote:
> For the purposes of testing a heavy load situation, I'd like to 
> configure one of my apache web servers to intentionally respond slow to 
> a request.
> 
> Is anyone aware of some type of apache sleep or delay configuration that 
> will easily allow me to configure this? For example, tell apache to wait 
> 10 seconds before responding to any request.

Thanks to all who responded. I was hoping apache already had a 
configuration built in to do this. Instead of turning a variety of pages 
into dynamic pages in order to insert a sleep, I ended up writing an 
apache module and configured it with PerlInitHandler. This worked out 
well as I could configure it to just slow for my ip address without 
affecting anyone else. I could also easily apply it to all requests or a 
particular request via the <Location> tag.

In conf.d/perl.conf add this line:
PerlInitHandler MyDelay

Contents of MyDelay.pm are as follows:

package MyDelay;

# This package can be used in conjunction with a
# PerlInitHandler directive to slow down a connection
# based on an ip address

# Example: set in perl.conf
# To slow down a particular request
#<Location /delay_test.html>
#   PerlInitHandler MyDelay
#</Location>
#
# or outside of any Location, File, etc to slow down all requests
#  PerlInitHandler MyDelay

use strict;
use Apache2::RequestRec;
use Apache2::Const;             # for OK
use Apache2::Connection;		# for remote_ip

sub handler
{
    my $r = shift;
    my($c);
    my($ip_addr);

    $c = $r->connection;
    $ip_addr = $c->remote_ip;
    if ($ip_addr eq "my ip address")
    {
       print STDERR ("in MyDelay:handler\n");
       print STDERR ("ip_addr = $ip_addr\n");
       sleep (30);
    }

    return OK;
}

1;

---
Jim Albert



---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Mime
View raw message