Changeset 11971 for lang/perl/Moobal

Show
Ignore:
Timestamp:
05/19/08 12:18:25 (7 years ago)
Author:
daisuke
Message:

proxy accepts connections, but blocks

Location:
lang/perl/Moobal/trunk/lib
Files:
5 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/Moobal/trunk/lib/Moobal.pm

    r11968 r11971  
    9696    return $self; 
    9797}; 
     98 
     99sub register_backend 
     100{ 
     101    $_[0]->backend_pool->register_bored( $_[1] ); 
     102} 
    98103 
    99104sub pool { $_[0]->pools->{ $_[1] } } 
  • lang/perl/Moobal/trunk/lib/Moobal/BackendPool.pm

    r11968 r11971  
    88); 
    99 
     10sub register_bored 
     11{ 
     12    my $self = shift; 
     13    push @{ $self->bored }, $_[0]; 
     14} 
     15 
    10161; 
  • lang/perl/Moobal/trunk/lib/Moobal/Component/BackendHTTP.pm

    r11968 r11971  
    3232has 'ip' => ( 
    3333    is => 'rw', 
    34     isa => 'Str' 
     34    isa => 'Str', 
     35    required => 1, 
    3536); 
    3637 
     
    3839has 'port' => ( 
    3940    is => 'rw', 
    40     isa => 'Str' 
     41    isa => 'Str', 
     42    required => 1, 
    4143); 
    4244 
     
    4446has 'ipport' => ( 
    4547    is => 'rw', 
    46     isa => 'Str' 
     48    isa => 'Str', 
     49    required => 1, 
    4750); 
    4851 
     
    160163 
    161164    my $self = $next->($class, %args, 
     165        ipport => join(':', $args{ip}, $args{port}), 
    162166        socket => _create_socket( $args{context}, $args{ip}, $args{port} ) 
    163167    ); 
     
    176180 
    177181    # mark another connection to this ip:port 
    178     $NodeStats{$self->ipport}->{attempts}++; 
    179     $NodeStats{$self->ipport}->{lastattempt} = $self->{create_time}; 
    180  
     182    my $data = $NodeStats{$self->ipport}; 
     183    if (! $data) { 
     184        $data = { attempts => 0, lastattempt => 0 }; 
     185        $NodeStats{$self->ipport} = $data; 
     186    } 
     187    $data->{attempts}++; 
     188    $data->{lastattempt} = $self->{create_time}; 
     189 
     190    # All backend http components are registered into the global 
     191    # backend pool 
     192    $self->context->register_backend( $self ); 
    181193 
    182194    return $self; 
     195}; 
     196 
     197around 'DESTROY' => sub { 
     198    my $next = shift; 
     199    my $self = shift; 
     200    if (my $context = $self->context) { 
     201        $context->unregister_backend( $self ); 
     202    } 
     203    $next->($self, @_ ); 
    183204}; 
    184205 
     
    417438 
    418439        my $service = $self->service; 
    419         if (defined $service && $service->verify_backend && 
     440        if (defined $service && $service->param('verify_backend') && 
    420441            !$self->{has_attention} && !defined $NoVerify{$ipport}) { 
    421442 
    422443            # the backend should be able to answer this incredibly quickly. 
    423             $self->write("OPTIONS " . $self->{service}->{verify_backend_path} . " HTTP/1.0\r\nConnection: keep-alive\r\n\r\n"); 
     444            $self->write("OPTIONS " . ($service->param('verify_backend_path') || '/') . " HTTP/1.0\r\nConnection: keep-alive\r\n\r\n"); 
    424445            $self->watch_read(1); 
    425446            $self->{waiting_options} = 1; 
     
    687708 
    688709    # and now see if we should closed based on the pool we're from 
     710 
     711    my $pool = $self->pool; 
    689712    return $self->close('pool_requested_closure') 
    690         if $self->{pool} && ! $self->{pool}->backend_should_live($self); 
     713        if $pool && ! $pool->backend_should_live($self); 
    691714 
    692715    # we've been used 
  • lang/perl/Moobal/trunk/lib/Moobal/Pool.pm

    r11966 r11971  
    4141); 
    4242 
     43has 'use_count' => ( 
     44    is => 'rw', 
     45    isa => 'Int', 
     46    default => 0, 
     47); 
     48 
    4349use constant NODEFILE_RELOAD_FREQ => 3; 
    4450 
     
    7985    return @{ $nodes[int(rand($self->node_count))] }; 
    8086} 
     87 
     88sub backend_should_live { 
     89    my ($self, $be) = @_; 
     90 
     91    # a backend stays alive if we still have users.  eventually this whole 
     92    # function might do more and actually take into account the individual 
     93    # backend, but for now, this suits us. 
     94    return $self->use_count > 0; 
     95} 
     96 
     97 
    8198 
    82991; 
     
    284301} 
    285302 
    286 sub backend_should_live { 
    287     my Moobal::Pool $self = $_[0]; 
    288     my Moobal::BackendHTTP $be = $_[1]; 
    289  
    290     # a backend stays alive if we still have users.  eventually this whole 
    291     # function might do more and actually take into account the individual 
    292     # backend, but for now, this suits us. 
    293     return 1 if $self->{use_count}; 
    294     return 0; 
    295 } 
    296  
    297303sub node_count { 
    298304    my Moobal::Pool $self = $_[0]; 
  • lang/perl/Moobal/trunk/lib/Moobal/Role/SocketHandler.pm

    r11945 r11971  
    7474has 'read_ahead' => ( 
    7575    is => 'rw', 
    76     isa => 'Str' 
     76    isa => 'Int', 
     77    default => 0, 
    7778); 
    7879