version 1.28, 2003/10/14 15:36:21
|
version 1.30, 2003/10/27 10:09:21
|
Line 45
|
Line 45
|
|
|
# Change log: |
# Change log: |
# $Log$ |
# $Log$ |
|
# Revision 1.30 2003/10/27 10:09:21 foxr |
|
# Tighten up a few compares to eq and flip a few debug levels around... nothing |
|
# critical |
|
# |
|
# Revision 1.29 2003/10/21 14:24:42 foxr |
|
# Fix little typo that may explain growth of connections |
|
# |
# Revision 1.28 2003/10/14 15:36:21 albertel |
# Revision 1.28 2003/10/14 15:36:21 albertel |
# - making it easier to run loncnew, |
# - making it easier to run loncnew, |
# /etc/init.d/loncontrol startnew |
# /etc/init.d/loncontrol startnew |
Line 181 my $MaxConnectionCount = 10; # Will get
|
Line 188 my $MaxConnectionCount = 10; # Will get
|
my $ClientConnection = 0; # Uniquifier for client events. |
my $ClientConnection = 0; # Uniquifier for client events. |
|
|
my $DebugLevel = 0; |
my $DebugLevel = 0; |
my $NextDebugLevel= 10; # So Sigint can toggle this. |
my $NextDebugLevel= 2; # So Sigint can toggle this. |
my $IdleTimeout= 3600; # Wait an hour before pruning connections. |
my $IdleTimeout= 3600; # Wait an hour before pruning connections. |
|
|
# |
# |
Line 198 my $ConnectionCount = 0;
|
Line 205 my $ConnectionCount = 0;
|
my $IdleSeconds = 0; # Number of seconds idle. |
my $IdleSeconds = 0; # Number of seconds idle. |
my $Status = ""; # Current status string. |
my $Status = ""; # Current status string. |
my $RecentLogEntry = ""; |
my $RecentLogEntry = ""; |
my $ConnectionRetries=5; # Number of connection retries allowed. |
my $ConnectionRetries=2; # Number of connection retries allowed. |
my $ConnectionRetriesLeft=5; # Number of connection retries remaining. |
my $ConnectionRetriesLeft=2; # Number of connection retries remaining. |
|
|
# |
# |
# The hash below gives the HTML format for log messages |
# The hash below gives the HTML format for log messages |
Line 409 sub Tick {
|
Line 416 sub Tick {
|
if ($ConnectionRetriesLeft > 0) { |
if ($ConnectionRetriesLeft > 0) { |
my $Connections = ($Requests <= $MaxConnectionCount) ? |
my $Connections = ($Requests <= $MaxConnectionCount) ? |
$Requests : $MaxConnectionCount; |
$Requests : $MaxConnectionCount; |
Debug(1,"Work but no connections, start ".$Connections." of them"); |
Debug(5,"Work but no connections, start ".$Connections." of them"); |
my $successCount = 0; |
my $successCount = 0; |
for (my $i =0; $i < $Connections; $i++) { |
for (my $i =0; $i < $Connections; $i++) { |
$successCount += MakeLondConnection(); |
$successCount += MakeLondConnection(); |
} |
} |
if($successCount == 0) { # All connections failed: |
if($successCount == 0) { # All connections failed: |
Debug(1,"Work in queue failed to make any connectiouns\n"); |
Debug(5,"Work in queue failed to make any connectiouns\n"); |
EmptyQueue(); # Fail pending transactions with con_lost. |
EmptyQueue(); # Fail pending transactions with con_lost. |
} |
} |
} else { |
} else { |
ShowStatus(GetServerHost()." >>> DEAD!!! <<<"); |
ShowStatus(GetServerHost()." >>> DEAD!!! <<<"); |
Debug(1,"Work in queue, but gave up on connections..flushing\n"); |
Debug(5,"Work in queue, but gave up on connections..flushing\n"); |
EmptyQueue(); # Connections can't be established. |
EmptyQueue(); # Connections can't be established. |
} |
} |
|
|
Line 467 sub ServerToIdle {
|
Line 474 sub ServerToIdle {
|
my $Socket = shift; # Get the socket. |
my $Socket = shift; # Get the socket. |
delete($ActiveTransactions{$Socket}); # Server has no transaction |
delete($ActiveTransactions{$Socket}); # Server has no transaction |
|
|
&Debug(6, "Server to idle"); |
&Debug(5, "Server to idle"); |
|
|
# If there's work to do, start the transaction: |
# If there's work to do, start the transaction: |
|
|
my $reqdata = $WorkQueue->dequeue(); # This is a LondTransaction |
my $reqdata = $WorkQueue->dequeue(); # This is a LondTransaction |
unless($reqdata eq undef) { |
if ($reqdata ne undef) { |
Debug(9, "Queue gave request data: ".$reqdata->getRequest()); |
Debug(5, "Queue gave request data: ".$reqdata->getRequest()); |
&StartRequest($Socket, $reqdata); |
&StartRequest($Socket, $reqdata); |
|
|
} else { |
} else { |
|
|
# There's no work waiting, so push the server to idle list. |
# There's no work waiting, so push the server to idle list. |
&Debug(8, "No new work requests, server connection going idle"); |
&Debug(5, "No new work requests, server connection going idle"); |
$IdleConnections->push($Socket); |
$IdleConnections->push($Socket); |
} |
} |
} |
} |
Line 525 sub ClientWritable {
|
Line 532 sub ClientWritable {
|
# request. |
# request. |
|
|
&Debug(9,"Send result is ".$result." Defined: ".defined($result)); |
&Debug(9,"Send result is ".$result." Defined: ".defined($result)); |
if(defined($result)) { |
if($result ne undef) { |
&Debug(9, "send result was defined"); |
&Debug(9, "send result was defined"); |
if($result == length($Data)) { # Entire string sent. |
if($result == length($Data)) { # Entire string sent. |
&Debug(9, "ClientWritable data all written"); |
&Debug(9, "ClientWritable data all written"); |
Line 596 The transaction that is being completed.
|
Line 603 The transaction that is being completed.
|
=cut |
=cut |
|
|
sub CompleteTransaction { |
sub CompleteTransaction { |
&Debug(6,"Complete transaction"); |
&Debug(5,"Complete transaction"); |
my $Socket = shift; |
my $Socket = shift; |
my $Transaction = shift; |
my $Transaction = shift; |
|
|
Line 635 sub StartClientReply {
|
Line 642 sub StartClientReply {
|
&Debug(8," Reply was: ".$data); |
&Debug(8," Reply was: ".$data); |
my $Serial = $ActiveClients{$Client}; |
my $Serial = $ActiveClients{$Client}; |
my $desc = sprintf("Connection to lonc client %d", |
my $desc = sprintf("Connection to lonc client %d", |
|
|
$Serial); |
$Serial); |
Event->io(fd => $Client, |
Event->io(fd => $Client, |
poll => "w", |
poll => "w", |
Line 884 sub LondReadable {
|
Line 890 sub LondReadable {
|
$ConnectionRetriesLeft = $ConnectionRetries; # success resets the count |
$ConnectionRetriesLeft = $ConnectionRetries; # success resets the count |
$Watcher->cancel(); |
$Watcher->cancel(); |
if(exists($ActiveTransactions{$Socket})) { |
if(exists($ActiveTransactions{$Socket})) { |
Debug(8,"Completing transaction!!"); |
Debug(5,"Completing transaction!!"); |
CompleteTransaction($Socket, |
CompleteTransaction($Socket, |
$ActiveTransactions{$Socket}); |
$ActiveTransactions{$Socket}); |
} else { |
} else { |
Line 1131 sub MakeLondConnection {
|
Line 1137 sub MakeLondConnection {
|
my $Connection = LondConnection->new(&GetServerHost(), |
my $Connection = LondConnection->new(&GetServerHost(), |
&GetServerPort()); |
&GetServerPort()); |
|
|
if($Connection == undef) { # Needs to be more robust later. |
if($Connection eq undef) { # Needs to be more robust later. |
Log("CRITICAL","Failed to make a connection with lond."); |
Log("CRITICAL","Failed to make a connection with lond."); |
$ConnectionRetriesLeft--; |
$ConnectionRetriesLeft--; |
return 0; # Failure. |
return 0; # Failure. |
Line 1143 sub MakeLondConnection {
|
Line 1149 sub MakeLondConnection {
|
# exchange underway. |
# exchange underway. |
# |
# |
my $Socket = $Connection->GetSocket(); |
my $Socket = $Connection->GetSocket(); |
if($Socket == undef) { |
if($Socket eq undef) { |
die "did not get a socket from the connection"; |
die "did not get a socket from the connection"; |
} else { |
} else { |
&Debug(9,"MakeLondConnection got socket: ".$Socket); |
&Debug(9,"MakeLondConnection got socket: ".$Socket); |
Line 1246 sub QueueTransaction {
|
Line 1252 sub QueueTransaction {
|
|
|
my $LondSocket = $IdleConnections->pop(); |
my $LondSocket = $IdleConnections->pop(); |
if(!defined $LondSocket) { # Need to queue request. |
if(!defined $LondSocket) { # Need to queue request. |
Debug(8,"Must queue..."); |
Debug(5,"Must queue..."); |
$WorkQueue->enqueue($requestData); |
$WorkQueue->enqueue($requestData); |
if($ConnectionCount < $MaxConnectionCount) { |
if($ConnectionCount < $MaxConnectionCount) { |
if($ConnectionRetriesLeft > 0) { |
if($ConnectionRetriesLeft > 0) { |
Debug(4,"Starting additional lond connection"); |
Debug(5,"Starting additional lond connection"); |
if(MakeLondConnection() == 0) { |
if(MakeLondConnection() == 0) { |
EmptyQueue(); # Fail transactions, can't make connection. |
EmptyQueue(); # Fail transactions, can't make connection. |
} |
} |
Line 1288 sub ClientRequest {
|
Line 1294 sub ClientRequest {
|
my $rv = $socket->recv($thisread, POSIX::BUFSIZ, 0); |
my $rv = $socket->recv($thisread, POSIX::BUFSIZ, 0); |
Debug(8, "rcv: data length = ".length($thisread) |
Debug(8, "rcv: data length = ".length($thisread) |
." read =".$thisread); |
." read =".$thisread); |
unless (defined $rv && length($thisread)) { |
unless (defined $rv && length($thisread)) { |
# Likely eof on socket. |
# Likely eof on socket. |
Debug(5,"Client Socket closed on lonc for ".$RemoteHost); |
Debug(5,"Client Socket closed on lonc for ".$RemoteHost); |
close($socket); |
close($socket); |