--- loncom/auth/lonauth.pm 2010/08/18 19:39:42 1.101.8.3 +++ loncom/auth/lonauth.pm 2010/08/26 08:15:59 1.101.8.4 @@ -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 @@ sub handler { &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; }