[LON-CAPA-cvs] cvs: loncom /interface lonsearchcat.pm lonspreadsheet.pm lonstatistics.pm /lonnet/perl lonnet.pm

www lon-capa-cvs@mail.lon-capa.org
Mon, 16 Sep 2002 20:09:47 -0000


www		Mon Sep 16 16:09:47 2002 EDT

  Modified files:              
    /loncom/interface	lonsearchcat.pm lonspreadsheet.pm 
                     	lonstatistics.pm 
    /loncom/lonnet/perl	lonnet.pm 
  Log:
  Overload protection
  
  
Index: loncom/interface/lonsearchcat.pm
diff -u loncom/interface/lonsearchcat.pm:1.156 loncom/interface/lonsearchcat.pm:1.157
--- loncom/interface/lonsearchcat.pm:1.156	Mon Sep 16 08:52:33 2002
+++ loncom/interface/lonsearchcat.pm	Mon Sep 16 16:09:45 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # Search Catalog
 #
-# $Id: lonsearchcat.pm,v 1.156 2002/09/16 12:52:33 matthew Exp $
+# $Id: lonsearchcat.pm,v 1.157 2002/09/16 20:09:45 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -171,6 +171,10 @@
 sub handler {
     my $r = shift;
     #
+
+    my $loaderror=&Apache::lonnet::overloaderror($r);
+    if ($loaderror) { return $loaderror; }
+
     my $closebutton;  # button that closes the search window 
                       # This button is different for the RAT compared to
                       # normal invocation.
Index: loncom/interface/lonspreadsheet.pm
diff -u loncom/interface/lonspreadsheet.pm:1.109 loncom/interface/lonspreadsheet.pm:1.110
--- loncom/interface/lonspreadsheet.pm:1.109	Tue Sep 10 15:04:13 2002
+++ loncom/interface/lonspreadsheet.pm	Mon Sep 16 16:09:45 2002
@@ -1,5 +1,5 @@
 #
-# $Id: lonspreadsheet.pm,v 1.109 2002/09/10 19:04:13 matthew Exp $
+# $Id: lonspreadsheet.pm,v 1.110 2002/09/16 20:09:45 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -2416,6 +2416,14 @@
 
 sub handler {
     my $r=shift;
+
+     my $loaderror=&Apache::lonnet::overloaderror($r);
+     if ($loaderror) { return $loaderror; }
+     $loaderror=
+        &Apache::lonnet::overloaderror($r,
+          $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
+     if ($loaderror) { return $loaderror; } 
+
     if ($r->header_only) {
         $r->content_type('text/html');
         $r->send_http_header;
Index: loncom/interface/lonstatistics.pm
diff -u loncom/interface/lonstatistics.pm:1.50 loncom/interface/lonstatistics.pm:1.51
--- loncom/interface/lonstatistics.pm:1.50	Sun Sep  1 02:23:19 2002
+++ loncom/interface/lonstatistics.pm	Mon Sep 16 16:09:46 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network with CAPA
 # (Publication Handler
 #
-# $Id: lonstatistics.pm,v 1.50 2002/09/01 06:23:19 stredwic Exp $
+# $Id: lonstatistics.pm,v 1.51 2002/09/16 20:09:46 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -611,6 +611,13 @@
     my $r=shift;
 
 #    $jr = $r;
+
+    my $loaderror=&Apache::lonnet::overloaderror($r);
+    if ($loaderror) { return $loaderror; }
+    $loaderror=
+       &Apache::lonnet::overloaderror($r,
+         $ENV{'course.'.$ENV{'request.course.id'}.'.home'});
+    if ($loaderror) { return $loaderror; }
 
     unless(&Apache::lonnet::allowed('vgr',$ENV{'request.course.id'})) {
         $ENV{'user.error.msg'}=
Index: loncom/lonnet/perl/lonnet.pm
diff -u loncom/lonnet/perl/lonnet.pm:1.282 loncom/lonnet/perl/lonnet.pm:1.283
--- loncom/lonnet/perl/lonnet.pm:1.282	Mon Sep 16 15:42:10 2002
+++ loncom/lonnet/perl/lonnet.pm	Mon Sep 16 16:09:47 2002
@@ -1,7 +1,7 @@
 # The LearningOnline Network
 # TCP networking package
 #
-# $Id: lonnet.pm,v 1.282 2002/09/16 19:42:10 albertel Exp $
+# $Id: lonnet.pm,v 1.283 2002/09/16 20:09:47 www Exp $
 #
 # Copyright Michigan State University Board of Trustees
 #
@@ -346,6 +346,28 @@
      $fh->close();
     }
     return 'ok';
+}
+
+# ------------------------------------------ Fight off request when overloaded
+
+sub overloaderror {
+    my ($r,$checkserver)=@_;
+    unless ($checkserver) { $checkserver=$perlvar{'lonHostID'}; }
+    my $loadavg;
+    if ($checkserver eq $perlvar{'lonHostID'}) {
+       my $loadfile=Apache::File->new('/proc/loadavg');
+       $loadavg=<$loadfile>;
+       $loadavg =~ s/\s.*//g;
+    } else {
+       $loadavg=&reply('load',$checkserver);
+    }
+    my $overload=$loadavg-$perlvar{'lonLoadLim'};
+    if ($overload>0) {
+	$r->err_headers_out->{'Retry-After'}=$overload*30;
+        $r->log_error('Overload of '.$overload.' on '.$checkserver);
+        return 413;
+    }    
+    return '';
 }
 
 # ------------------------------ Find server with least workload from spare.tab