[LON-CAPA-cvs] cvs: loncom /auth lonacc.pm /lonnet/perl lonnet.pm

raeburn raeburn at source.lon-capa.org
Wed May 30 16:29:49 EDT 2012


raeburn		Wed May 30 20:29:49 2012 EDT

  Modified files:              
    /loncom/lonnet/perl	lonnet.pm 
    /loncom/auth	lonacc.pm 
  Log:
  - Dedicated loadbalancer.
    - If a session for a specific user is being hosted on a loadbalancer server
      call to lonnet::check_loadbalancing() only made for an authenticated 
      user, once 10 minutes have elapsed since last call. 
      (user.loadbalexempt and user.loadbalcheck.time stored in %env). 
  
  
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.1175 loncom/lonnet/perl/lonnet.pm:1.1176
--- loncom/lonnet/perl/lonnet.pm:1.1175	Wed May 30 16:29:25 2012
+++ loncom/lonnet/perl/lonnet.pm	Wed May 30 20:29:45 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.1175 2012/05/30 16:29:25 raeburn Exp $
+# $Id: lonnet.pm,v 1.1176 2012/05/30 20:29:45 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -1353,37 +1353,46 @@
             $offloadto = &this_host_spares($dom_in_use);
         }
     }
-    my $lowest_load = 30000;
-    if (ref($offloadto) eq 'HASH') {
-        if (ref($offloadto->{'primary'}) eq 'ARRAY') {
-            foreach my $try_server (@{$offloadto->{'primary'}}) {
-                ($otherserver,$lowest_load) =
-                    &compare_server_load($try_server,$otherserver,$lowest_load);
+    if ($is_balancer) {
+        my $lowest_load = 30000;
+        if (ref($offloadto) eq 'HASH') {
+            if (ref($offloadto->{'primary'}) eq 'ARRAY') {
+                foreach my $try_server (@{$offloadto->{'primary'}}) {
+                    ($otherserver,$lowest_load) =
+                        &compare_server_load($try_server,$otherserver,$lowest_load);
+                }
             }
-        }
-        my $found_server = ($otherserver ne '' && $lowest_load < 100);
+            my $found_server = ($otherserver ne '' && $lowest_load < 100);
 
-        if (!$found_server) {
-            if (ref($offloadto->{'default'}) eq 'ARRAY') {
-                foreach my $try_server (@{$offloadto->{'default'}}) {
+            if (!$found_server) {
+                if (ref($offloadto->{'default'}) eq 'ARRAY') {
+                    foreach my $try_server (@{$offloadto->{'default'}}) {
+                        ($otherserver,$lowest_load) =
+                            &compare_server_load($try_server,$otherserver,$lowest_load);
+                    }
+                }
+            }
+        } elsif (ref($offloadto) eq 'ARRAY') {
+            if (@{$offloadto} == 1) {
+                $otherserver = $offloadto->[0];
+            } elsif (@{$offloadto} > 1) {
+                foreach my $try_server (@{$offloadto}) {
                     ($otherserver,$lowest_load) =
                         &compare_server_load($try_server,$otherserver,$lowest_load);
                 }
             }
         }
-    } elsif (ref($offloadto) eq 'ARRAY') {
-        if (@{$offloadto} == 1) {
-            $otherserver = $offloadto->[0];
-        } elsif (@{$offloadto} > 1) {
-            foreach my $try_server (@{$offloadto}) {
-                ($otherserver,$lowest_load) =
-                    &compare_server_load($try_server,$otherserver,$lowest_load);
+        if (($otherserver ne '') && (grep(/^\Q$otherserver\E$/, at hosts))) {
+            $is_balancer = 0;
+            if ($uname ne '' && $udom ne '') {
+                if (($env{'user.name'} eq $uname) && ($env{'user.domain'} eq $udom)) {
+                    
+                    &appenv({'user.loadbalexempt'     => $lonhost,  
+                             'user.loadbalcheck.time' => time});
+                }
             }
         }
     }
-    if (($otherserver ne '') && (grep(/^\Q$otherserver\E$/, at hosts))) {
-        $is_balancer = 0;
-    }
     return ($is_balancer,$otherserver);
 }
 
Index: loncom/auth/lonacc.pm
diff -u loncom/auth/lonacc.pm:1.137 loncom/auth/lonacc.pm:1.138
--- loncom/auth/lonacc.pm:1.137	Tue Aug  9 01:35:31 2011
+++ loncom/auth/lonacc.pm	Wed May 30 20:29:49 2012
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # Cookie Based Access Handler
 #
-# $Id: lonacc.pm,v 1.137 2011/08/09 01:35:31 raeburn Exp $
+# $Id: lonacc.pm,v 1.138 2012/05/30 20:29:49 raeburn Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -438,9 +438,17 @@
 
 # ------------------------------------------------------ Check if load balancer 
 
-        ($is_balancer,$otherserver) =
-            &Apache::lonnet::check_loadbalancing($env{'user.name'},
-                                                 $env{'user.domain'});
+        my $checkexempt;
+        if ($env{'user.loadbalexempt'} eq $r->dir_config('lonHostID')) {
+            if ($env{'user.loadbalcheck.time'} + 600 > time) {
+                $checkexempt = 1;    
+            }
+        }
+        unless ($checkexempt) {
+            ($is_balancer,$otherserver) =
+                &Apache::lonnet::check_loadbalancing($env{'user.name'},
+                                                     $env{'user.domain'});
+        }
         if ($is_balancer) {
             $r->set_handlers('PerlResponseHandler'=>
                              [\&Apache::switchserver::handler]);




More information about the LON-CAPA-cvs mailing list