throttling

Mark Smith junior at danga.com
Fri Aug 26 15:31:44 PDT 2005


Perlbal has no support for this at the moment, but you could add it in as a
plugin using a combination of the start_proxy_request/start_http_request
hooks (either/or depending on what you want to delay) and then the timer
callback functionality.

I imagine it could be something like:

Perlbal::register_hook('start_proxy_request', sub {
    my Perlbal::ClientProxy $self = shift;
    my $hd = $self->{req_headers};
    return undef unless $self && $hd;

    # rate limit by ip
    my $ip = $self->peer_ip_string;
    if (my $delay_for = ip_too_fast($ip)) {
        Perlbal::Socket->register_callback($delay_for, sub {
            $self->handle_request;
        });
        return 1;
    }

    return 0;
});

The idea being that you usurp handling of the request, and if you want to
throttle the request, you register a callback (your mythical ip_too_fast
sub would check that the IP is okay or not), and then after that amount of
time, the request is restarted.

One problem with this overly simple example is that requests can be waited
multiple times, which might be undesired behavior.  A better system is to
keep track of what requests you've throttled and handle that case.

Of course, it might be useful to put this functionality into the core...
then we can just have a throttle hook, and call it to see if we should
throttle and if so for how long, and then have Perlbal handle everything
else.

-jr

On Fri, Aug 26, 2005, Max Michaels wrote:
> Hellos,
> 
> We are considering a switch to perlbal for a front-end 
> proxy/load-balancer but i have a question first. Is there a throttling 
> mechanism built-in to Perlbal or a plug-in. I would like to be able to 
> say that a single IP can only request n documents per second or minute 
> or whatever. I've got perlbal running in a test environment and so far, 
> everything looks great.
> 
> -max
> 


--
Junior (aka Mark Smith)
junior at danga.com

Software Engineer
Six Apart / Danga Interactive


More information about the perlbal mailing list