[LON-CAPA-cvs] cvs: loncom(version_2_10_X) /auth lonauth.pm

raeburn raeburn@source.lon-capa.org
Thu, 26 Aug 2010 08:15:59 -0000


raeburn		Thu Aug 26 08:15:59 2010 EDT

  Modified files:              (Branch: version_2_10_X)
    /loncom/auth	lonauth.pm 
  Log:
  - Backport 1.109.
  
  
Index: loncom/auth/lonauth.pm
diff -u loncom/auth/lonauth.pm:1.101.8.3 loncom/auth/lonauth.pm:1.101.8.4
--- loncom/auth/lonauth.pm:1.101.8.3	Wed Aug 18 19:39:42 2010
+++ loncom/auth/lonauth.pm	Thu Aug 26 08:15:59 2010
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # User Authentication Module
 #
-# $Id: lonauth.pm,v 1.101.8.3 2010/08/18 19:39:42 raeburn Exp $
+# $Id: lonauth.pm,v 1.101.8.4 2010/08/26 08:15:59 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -421,10 +421,32 @@
 	&success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',undef,
 		 \%form);
         my ($otherserver) = &Apache::lonnet::choose_server($form{'udom'});
-	$r->internal_redirect('/adm/switchserver?otherserver='.$otherserver);
+	$r->internal_redirect('/adm/switchserver?otherserver='.$otherserver.'&origurl='.$firsturl);
     } else {
-	&success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef,
-		 \%form);
+# ------------------------------------------------------- Do the load balancing
+
+# ---------------------------------------------------------- Determine own load
+        my $loadlim = $r->dir_config('lonLoadLim');
+        my $loadavg;
+        {
+            my $loadfile=Apache::File->new('/proc/loadavg');
+            $loadavg=<$loadfile>;
+        }
+        $loadavg =~ s/\s.*//g;
+        my $loadpercent=sprintf("%.1f",100*$loadavg/$loadlim);
+        my $userloadpercent=&Apache::lonnet::userload();
+
+# ---------------------------------------------------------- Are we overloaded?
+        if ((($userloadpercent>100.0)||($loadpercent>100.0))) {
+            my $unloaded=Apache::lonnet::spareserver($loadpercent,$userloadpercent,1,$form{'udom'});
+            if ($unloaded) {
+                &success($r,$form{'uname'},$form{'udom'},$authhost,'noredirect',
+                         undef,\%form);
+                $r->internal_redirect('/adm/switchserver?otherserver='.$unloaded.'&origurl='.$firsturl);
+            }
+        }
+        &success($r,$form{'uname'},$form{'udom'},$authhost,$firsturl,undef,
+                 \%form);
     }
     return OK;
 }