You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by kh...@hyperreal.org on 1998/06/12 20:51:23 UTC

cvs commit: modperl/lib/Apache Resource.pm

khera       98/06/12 11:51:23

  Modified:    lib/Apache Resource.pm
  Log:
  Cleaned up documentation to match reality: CPU limit is in seconds,
  not milliseconds.
  
  Set the status report to show megabyte values as megabytes in addition
  to bytes.
  
  Defined MEMLOCK and CORE limits as being megabyte values.
  
  Revision  Changes    Path
  1.7       +39 -27    modperl/lib/Apache/Resource.pm
  
  Index: Resource.pm
  ===================================================================
  RCS file: /home/cvs/modperl/lib/Apache/Resource.pm,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Resource.pm	1998/03/19 23:08:46	1.6
  +++ Resource.pm	1998/06/12 18:51:22	1.7
  @@ -1,3 +1,4 @@
  +#! /usr/local/bin/perl
   package Apache::Resource;
   
   use strict;
  @@ -5,24 +6,26 @@
   use BSD::Resource qw(setrlimit getrlimit get_rlimits);
   
   $Debug ||= 0;
  -$Apache::Resource::VERSION = (qw$Revision: 1.6 $)[1];
  +$Apache::Resource::VERSION = (qw$Revision: 1.7 $)[1];
   
   sub MB ($) { 
       my $num = shift;
  -    if($num < (1024 * 1024)) {
  -	return $num*1024*1024;
  -    }
  -    $num;
  +    return ($num < (1024 * 1024)) ?  $num*1024*1024 : $num;
  +}
  +
  +sub BM ($) { 
  +    my $num = shift;
  +    return ($num > (1024 * 1024)) ?  '(' . ($num>>20) . 'Mb)' : '';
   }
   
  -sub DEFAULT_RLIMIT_DATA  () { 64 } #data (memory) size
  -sub DEFAULT_RLIMIT_CPU   () { 60*6 } #cpu time in milliseconds
  -sub DEFAULT_RLIMIT_CORE  () { 0  } #core file size
  -sub DEFAULT_RLIMIT_RSS   () { 16 } #resident set size
  -sub DEFAULT_RLIMIT_FSIZE () { 10 } #file size 
  -sub DEFAULT_RLIMIT_STACK () { 20 } #stack size
  +sub DEFAULT_RLIMIT_DATA  () { 64 } #data (memory) size in MB
  +sub DEFAULT_RLIMIT_CPU   () { 60*6 } #cpu time in seconds
  +sub DEFAULT_RLIMIT_CORE  () { 0  } #core file size (MB)
  +sub DEFAULT_RLIMIT_RSS   () { 16 } #resident set size (MB)
  +sub DEFAULT_RLIMIT_FSIZE () { 10 } #file size  (MB)
  +sub DEFAULT_RLIMIT_STACK () { 20 } #stack size (MB)
   
  -my %is_mb = map {$_,1} qw{DATA RSS STACK FSIZE};
  +my %is_mb = map {$_,1} qw{DATA RSS STACK FSIZE CORE MEMLOCK};
   
   sub debug { print STDERR @_ if $Debug }
   
  @@ -47,7 +50,7 @@
   
       $hard ||= $soft;
   
  -    debug "Apache::Resource: attempting to set `$name'=$soft:$hard ...";
  +    debug "Apache::Resource: PID $$ attempting to set `$name'=$soft:$hard ...";
   
       ($soft, $hard) = (MB $soft, MB $hard) if $is_mb{$name};
   
  @@ -82,18 +85,23 @@
   sub status_rlimit {
       my $lim = get_rlimits();
       my @retval = ("<table border=1><tr>", 
  -		  (map "<td><b>$_</b></td>", qw(Resource Soft Hard)),
  +		  (map "<th>$_</th>", qw(Resource Soft Hard)),
   		  "</tr>");
   
       for my $res (keys %$lim) {
   	my $val = eval "&BSD::Resource::${res}()";
  +	my ($soft,$hard) = getrlimit $val;
  +	(my $limit = $res) =~ s/^RLIMIT_//;
  +	($soft, $hard) = ("$soft " . BM($soft),"$hard ". BM($hard))
  +	  if $is_mb{$limit};
   	push @retval, 
   	"<tr>",
  -	(map { "<td>$_</td>" } $res, getrlimit $val),
  +	(map { "<td>$_</td>" } $res, $soft, $hard),
   	"</tr>";
       }
   
  -    push @retval, "</table>";
  +    push @retval, "</table><P>";
  +    push @retval, "<SMALL>Apache::Resource $Apache::Resource::VERSION</SMALL>";
   
       return \@retval;
   }
  @@ -121,12 +129,13 @@
   
   =head1 SYNOPSIS
   
  - #set memory limit in megabytes
  + PerlModule Apache::Resource
  + #set child memory limit in megabytes
    #default is 64 Meg
  - PerlSetEnv PERL_DATA_LIMIT 35
  + PerlSetEnv PERL_RLIMIT_DATA 32:48
   
  - #set cpu limit in milliseconds
  - #default is 60 milliseconds
  + #set child cpu limit in seconds
  + #default is 360 seconds
    PerlSetEnv PERL_RLIMIT_CPU 120
   
    PerlChildInitHandler Apache::Resource
  @@ -138,13 +147,16 @@
   system resources such as memory and cpu usage.
   
   Any B<RLIMIT> operation available to limit on your system can be set
  -by defining that operation as an envrionment variable with a B<PERL_>
  -prefix.  If no value is set a reasonable default is used if defined.
  -See your system C<setrlimit> manpage for available resources which 
  -can be limited.
  - 
  -By default, C<PERL_RLIMIT_DATA> is set to 64 megabytes if it does
  -not exist in the current environment. 
  +by defining that operation as an environment variable with a C<PERL_>
  +prefix.  See your system C<setrlimit> manpage for available resources
  +which can be limited.
  +
  +The following limit values are in megabytes: C<DATA>, C<RSS>, C<STACK>,
  +C<FSIZE>, C<CORE>, C<MEMLOCK>; all others are treated as their natural unit.
  +
  +If the value of the variable is of the form C<S:H>, C<S> is treated as
  +the soft limit, and C<H> is the hard limit.  If it is just a single
  +number, it is used for both soft and hard limits.
   
   =head1 DEFAULTS