[LON-CAPA-cvs] cvs: loncom / loncnew

foxr lon-capa-cvs@mail.lon-capa.org
Tue, 21 Sep 2004 10:54:43 -0000


foxr		Tue Sep 21 06:54:43 2004 EDT

  Modified files:              
    /loncom	loncnew 
  Log:
  Only allow new connections if there are no connection requests in progress. 
  This should prevent connection explosions due to short term load spikes.
  I believe that connection explosion may also be responsible for transaction
  failures due to resource issues.
  
  
Index: loncom/loncnew
diff -u loncom/loncnew:1.55 loncom/loncnew:1.56
--- loncom/loncnew:1.55	Mon Sep 20 14:40:06 2004
+++ loncom/loncnew	Tue Sep 21 06:54:43 2004
@@ -2,7 +2,7 @@
 # The LearningOnline Network with CAPA
 # lonc maintains the connections to remote computers
 #
-# $Id: loncnew,v 1.55 2004/09/20 18:40:06 albertel Exp $
+# $Id: loncnew,v 1.56 2004/09/21 10:54:43 foxr Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -276,6 +276,7 @@
     $ConnectionRetriesLeft--;
     if($ConnectionRetriesLeft <= 0) {
 	Log("CRITICAL", "Host marked DEAD: ".GetServerHost());
+	$LondConnecting = 0;
     }
 
 }
@@ -332,21 +333,18 @@
     #
     
     my $Requests = $WorkQueue->Count();
-    if (($ConnectionCount == 0)  && ($Requests > 0)) { 
+    if (($ConnectionCount == 0)  && ($Requests > 0) && (!$LondConnecting)) { 
 	if ($ConnectionRetriesLeft > 0) {
-	    my $Connections = ($Requests <= $MaxConnectionCount) ?
-		$Requests : $MaxConnectionCount;
-	    Debug(5,"Work but no connections, start ".$Connections." of them");
-	    my $successCount = 0;
-	    for (my $i =0; $i < $Connections; $i++) {
-		$successCount += MakeLondConnection();
-	    }
-	    if($successCount == 0) { # All connections failed:
+	    Debug(5,"Work but no connections, Make a new one");
+	    my $success;
+	    $success    = &MakeLondConnection;
+	    if($success == 0) { # All connections failed:
 		Debug(5,"Work in queue failed to make any connectiouns\n");
 		EmptyQueue();	# Fail pending transactions with con_lost.
 		CloseAllLondConnections(); # Should all be closed but....
 	    }
 	} else {
+	    $LondConnecting = 0;
 	    ShowStatus(GetServerHost()." >>> DEAD!!! <<<");
 	    Debug(5,"Work in queue, but gave up on connections..flushing\n");
 	    EmptyQueue();	# Connections can't be established.
@@ -799,6 +797,11 @@
 	    "Lond connection lost.");
 	if(exists($ActiveTransactions{$Socket})) {
 	    FailTransaction($ActiveTransactions{$Socket});
+	} else {
+	    #  Socket is connecting and failed... need to mark
+	    #  no longer connecting.
+	   
+	    $LondConnecting = 0;
 	}
 	$Watcher->cancel();
 	KillSocket($Socket);
@@ -990,6 +993,10 @@
 	    " has been disconnected");
 	if(exists($ActiveTransactions{$Socket})) {
 	    FailTransaction($ActiveTransactions{$Socket});
+	} else {
+	    #  In the process of conneting, so need to turn that off.
+	    
+	    $LondConnecting = 0;
 	}
 	$Watcher->cancel();
 	KillSocket($Socket);
@@ -1244,15 +1251,18 @@
     if(!defined $LondSocket) {	# Need to queue request.
 	Debug(5,"Must queue...");
 	$WorkQueue->enqueue($requestData);
-	if(($ConnectionCount < $MaxConnectionCount) && !$LondConnecting) {
+	Debug(5, "Queue Transaction startnew $ConnectionCount $LondConnecting");
+	if(($ConnectionCount < $MaxConnectionCount)   && (! $LondConnecting)) {
+
 	    if($ConnectionRetriesLeft > 0) {
 		Debug(5,"Starting additional lond connection");
-		if(MakeLondConnection() == 0) {
+		if(&MakeLondConnection() == 0) {
 		    EmptyQueue();	# Fail transactions, can't make connection.
 		    CloseAllLondConnections; # Should all be closed but...
 		}
 	    } else {
 		ShowStatus(GetServerHost()." >>> DEAD !!!! <<<");
+		$LondConnecting = 0;
 		EmptyQueue();	# It's worse than that ... he's dead Jim.
 		CloseAllLondConnections; # Should all be closed but..
 	    }