Changeset 11971 for lang/perl/Moobal/trunk/lib
- Timestamp:
- 05/19/08 12:18:25 (5 years ago)
- Location:
- lang/perl/Moobal/trunk/lib
- Files:
-
- 5 modified
-
Moobal.pm (modified) (1 diff)
-
Moobal/BackendPool.pm (modified) (1 diff)
-
Moobal/Component/BackendHTTP.pm (modified) (7 diffs)
-
Moobal/Pool.pm (modified) (3 diffs)
-
Moobal/Role/SocketHandler.pm (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
lang/perl/Moobal/trunk/lib/Moobal.pm
r11968 r11971 96 96 return $self; 97 97 }; 98 99 sub register_backend 100 { 101 $_[0]->backend_pool->register_bored( $_[1] ); 102 } 98 103 99 104 sub pool { $_[0]->pools->{ $_[1] } } -
lang/perl/Moobal/trunk/lib/Moobal/BackendPool.pm
r11968 r11971 8 8 ); 9 9 10 sub register_bored 11 { 12 my $self = shift; 13 push @{ $self->bored }, $_[0]; 14 } 15 10 16 1; -
lang/perl/Moobal/trunk/lib/Moobal/Component/BackendHTTP.pm
r11968 r11971 32 32 has 'ip' => ( 33 33 is => 'rw', 34 isa => 'Str' 34 isa => 'Str', 35 required => 1, 35 36 ); 36 37 … … 38 39 has 'port' => ( 39 40 is => 'rw', 40 isa => 'Str' 41 isa => 'Str', 42 required => 1, 41 43 ); 42 44 … … 44 46 has 'ipport' => ( 45 47 is => 'rw', 46 isa => 'Str' 48 isa => 'Str', 49 required => 1, 47 50 ); 48 51 … … 160 163 161 164 my $self = $next->($class, %args, 165 ipport => join(':', $args{ip}, $args{port}), 162 166 socket => _create_socket( $args{context}, $args{ip}, $args{port} ) 163 167 ); … … 176 180 177 181 # 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 ); 181 193 182 194 return $self; 195 }; 196 197 around '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, @_ ); 183 204 }; 184 205 … … 417 438 418 439 my $service = $self->service; 419 if (defined $service && $service-> verify_backend&&440 if (defined $service && $service->param('verify_backend') && 420 441 !$self->{has_attention} && !defined $NoVerify{$ipport}) { 421 442 422 443 # 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"); 424 445 $self->watch_read(1); 425 446 $self->{waiting_options} = 1; … … 687 708 688 709 # and now see if we should closed based on the pool we're from 710 711 my $pool = $self->pool; 689 712 return $self->close('pool_requested_closure') 690 if $ self->{pool} && ! $self->{pool}->backend_should_live($self);713 if $pool && ! $pool->backend_should_live($self); 691 714 692 715 # we've been used -
lang/perl/Moobal/trunk/lib/Moobal/Pool.pm
r11966 r11971 41 41 ); 42 42 43 has 'use_count' => ( 44 is => 'rw', 45 isa => 'Int', 46 default => 0, 47 ); 48 43 49 use constant NODEFILE_RELOAD_FREQ => 3; 44 50 … … 79 85 return @{ $nodes[int(rand($self->node_count))] }; 80 86 } 87 88 sub 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 81 98 82 99 1; … … 284 301 } 285 302 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 whole291 # function might do more and actually take into account the individual292 # backend, but for now, this suits us.293 return 1 if $self->{use_count};294 return 0;295 }296 297 303 sub node_count { 298 304 my Moobal::Pool $self = $_[0]; -
lang/perl/Moobal/trunk/lib/Moobal/Role/SocketHandler.pm
r11945 r11971 74 74 has 'read_ahead' => ( 75 75 is => 'rw', 76 isa => 'Str' 76 isa => 'Int', 77 default => 0, 77 78 ); 78 79
![(please configure the [header_logo] section in trac.ini)](/share/chrome/site/your_project_logo.png)