[Catalyst-commits] r7056 -
trunk/Catalyst-Engine-HTTP-Sprocket/lib/Catalyst/Engine/HTTP/Sprocket
andyg at dev.catalyst.perl.org
andyg at dev.catalyst.perl.org
Thu Oct 25 01:10:22 GMT 2007
Author: andyg
Date: 2007-10-25 01:10:22 +0100 (Thu, 25 Oct 2007)
New Revision: 7056
Modified:
trunk/Catalyst-Engine-HTTP-Sprocket/lib/Catalyst/Engine/HTTP/Sprocket/Server.pm
trunk/Catalyst-Engine-HTTP-Sprocket/lib/Catalyst/Engine/HTTP/Sprocket/Worker.pm
Log:
If no free children for a request, retry it later
Modified: trunk/Catalyst-Engine-HTTP-Sprocket/lib/Catalyst/Engine/HTTP/Sprocket/Server.pm
===================================================================
--- trunk/Catalyst-Engine-HTTP-Sprocket/lib/Catalyst/Engine/HTTP/Sprocket/Server.pm 2007-10-24 21:29:55 UTC (rev 7055)
+++ trunk/Catalyst-Engine-HTTP-Sprocket/lib/Catalyst/Engine/HTTP/Sprocket/Server.pm 2007-10-25 00:10:22 UTC (rev 7056)
@@ -156,6 +156,7 @@
$con->call( 'child_reset' );
+ # XXX: Sprocket bug doesn't close connections properly?
$con->close();
}
}
@@ -179,37 +180,66 @@
DEBUG && warn "[$con] local_receive: " . dump($input) . "\n";
# Find a free child to send the request to
- for my $id ( keys %{ $self->{children} } ) {
- next if $self->{child_busy}->{ $id };
+ for my $wheel_id ( keys %{ $self->{children} } ) {
+ next if $self->{child_busy}->{ $wheel_id };
- # Mark the child as busy handling this connection
- $self->{child_busy}->{ $id } = $con;
+ DEBUG && warn "[$con] Dispatching request to $wheel_id\n";
- # Link this child to the connection
- $con->x->{handler_id} = $id;
+ $con->call( dispatch => $wheel_id, \$input );
- # XXX: Static requests should be handled directly with AIO
+ return 1;
+ }
+
+ # No child ready for this request, queue it and try later
+ $con->x->{pending} = \$input;
+
+ DEBUG && warn "[$con] No worker available to process request, retrying...\n";
+
+ $con->delay_set( 'dispatch_pending', 0.1 );
+}
+
+sub dispatch_pending {
+ my ( $self, $server, $con ) = @_;
+
+ for my $wheel_id ( keys %{ $self->{children} } ) {
+ next if $self->{child_busy}->{ $wheel_id };
- # Pass connection info before the request
- my $conn = join( "|", (
- $con->peer_ip,
- $con->peer_hostname,
- $con->local_ip,
- $con->local_port,
- ) ) . "\x0D\x0A";
+ DEBUG && warn "[$con] Dispatching request to $wheel_id\n";
- # Send the data along to the child for handling
- $self->{children}->{ $id }->put( $conn . $input );
+ $con->call( dispatch => $wheel_id, delete $con->x->{pending} );
- return 1;
+ return;
}
- # XXX: no child available to handle the request
- warn "[$con] No child available for request\n";
- warn dump($self) . "\n";
- die;
+ # All children still busy, try again later
+ DEBUG && warn "[$con] No worker available to process request, retrying...\n";
+
+ $con->delay_set( 'dispatch_pending', 0.1 );
}
+sub dispatch {
+ my ( $self, $server, $con, $wheel_id, $input ) = @_;
+
+ # Mark the child as busy handling this connection
+ $self->{child_busy}->{ $wheel_id } = $con;
+
+ # Link this child to the connection
+ $con->x->{handler_id} = $wheel_id;
+
+ # XXX: Static requests should be handled directly with AIO
+
+ # Pass connection info before the request
+ my $conn = join( "|", (
+ $con->peer_ip,
+ $con->peer_hostname,
+ $con->local_ip,
+ $con->local_port,
+ ) ) . "\x0D\x0A";
+
+ # Send the data along to the child for handling
+ $self->{children}->{ $wheel_id }->put( $conn . $$input );
+}
+
### Child handlers
sub child_error {
@@ -264,6 +294,7 @@
$con->call( 'child_reset' );
# XXX: keep-alive support, just close connection for now
+ # XXX: Sprocket bug doesn't close connections properly?
$con->close();
return;
Modified: trunk/Catalyst-Engine-HTTP-Sprocket/lib/Catalyst/Engine/HTTP/Sprocket/Worker.pm
===================================================================
--- trunk/Catalyst-Engine-HTTP-Sprocket/lib/Catalyst/Engine/HTTP/Sprocket/Worker.pm 2007-10-24 21:29:55 UTC (rev 7055)
+++ trunk/Catalyst-Engine-HTTP-Sprocket/lib/Catalyst/Engine/HTTP/Sprocket/Worker.pm 2007-10-25 00:10:22 UTC (rev 7056)
@@ -33,7 +33,7 @@
# Autoflush to avoid weirdness
select(STDOUT); $|++;
- select(STDERR); $|++;
+ select(STDERR); $|++;
$SIG{__WARN__} = 'DEFAULT';
$SIG{__DIE__} = 'DEFAULT';
@@ -212,4 +212,4 @@
syswrite STDOUT, $self->{config}->{child_done};
}
-1;
\ No newline at end of file
+1;
More information about the Catalyst-commits
mailing list