[prev in list] [next in list] [prev in thread] [next in thread]
List: apache-modperl-dev
Subject: Fw: Apache::SizeLimit patches
From: "Perrin Harkins" <perrin () elem ! com>
Date: 2001-07-03 6:40:08
[Download RAW message or body]
Here's a patch I submitted for Apache::SizeLimit, presented for your general
amusement and critique.
- Perrin
----- Original Message -----
From: "Perrin Harkins" <perrin@elem.com>
To: "Doug MacEachern" <dougm@covalent.net>
Sent: Saturday, June 23, 2001 9:45 PM
Subject: Re: Apache::SizeLimit patches
> Hi Doug,
>
> Sorry this took so long. This is a diff against today's CVS. Here's a
> brief description of the changes:
>
> - Added support for minimum shared memory and maximum unshared memory
> settings.
> - Added extra diagnostics to tell how many requests a process served, how
> long it lived, and how much shared memory it was using when SizeLimit
killed
> it.
>
> I upped ther version to 0.04. Let me know if you need anything else.
> - Perrin
>
["SizeLimit.pm.patch" (application/octet-stream)]
15c15,18
< $Apache::SizeLimit::MAX_PROCESS_SIZE = 10000; # in KB, so this is 10MB
---
> # sizes are in KB
> $Apache::SizeLimit::MAX_PROCESS_SIZE = 10000; # 10MB
> $Apache::SizeLimit::MIN_SHARE_SIZE = 1000; # 1MB
> $Apache::SizeLimit::MAX_UNSHARED_SIZE = 12000; # 12MB
28c31,33
< &Apache::SizeLimit::setmax(10000); # Max Process Size in KB
---
> &Apache::SizeLimit::setmax(10000); # Max size in KB
> &Apache::SizeLimit::setmin(1000); # Min share in KB
> &Apache::SizeLimit::setmax_unshared(12000); # Max unshared size in KB
68a74,89
> =head1 SHARED MEMORY OPTIONS
>
> In addition to simply checking the total size of a process, this
> module can factor in how much of the memory used by the process is
> actually being shared by copy-on-write. If you don't understand how
> memory is shared in this way, take a look at the mod_perl Guide at
> http://perl.apache.org/guide/.
>
> You can take advantage of the shared memory information by setting a
> minimum shared size and/or a maximum unshared size. Experience on one
> heavily trafficked mod_perl site showed that setting maximum unshared
> size and leaving the others unset is the most effective policy. This
> is because it only kills off processes that are truly using too much
> physical RAM, allowing most processes to live longer and reducing the
> process churn rate.
>
72c93,96
< is pretty different from OS to OS, and some platforms may not be supported.
---
> is pretty different from OS to OS, and some platforms may not be
> supported. In particular, the limits on minimum shared memory and
> maximum shared memory are currently only supported on Linux and BSD.
> If you can contribute support for another OS, please do.
89a114
> Shared memory calculations are not supported.
102c127,128
< Uses BSD::Resource::getrusage() to determine process size.
---
> Uses BSD::Resource::getrusage() to determine process size. Not sure if the
> shared memory calculations will work or not. AIX users?
124c150,151
< $REQUEST_COUNT $CHECK_EVERY_N_REQUESTS);
---
> $REQUEST_COUNT $CHECK_EVERY_N_REQUESTS
> $MIN_SHARE_SIZE $MAX_UNSHARED_SIZE $START_TIME);
128a156,159
> $MAX_PROCESS_SIZE = 0;
> $MIN_SHARE_SIZE = 0;
> $MAX_UNSHARED_SIZE = 0;
>
151c182
< my $size = 0;
---
> my ($size, $resident, $share) = (0,0,0);
153,154c184,185
< if (open(FH, "</proc/self/status")) {
< while (<FH>) { last if (($size) = (/^VmRSS:\s+(\d+)/)) }
---
> if (open(FH, "</proc/self/statm")) {
> ($size, $resident, $share) = split(/\s/, scalar <FH>);
159c190,191
< return($size);
---
> # linux on intel x86 has 4KB page size...
> return($size*4, $share*4);
166c198
< return($size);
---
> return($size, 0); # return 0 for share, to avoid undef warnings
170c202
< return( (&BSD::Resource::getrusage())[2] );
---
> return (&BSD::Resource::getrusage())[2,3];
175,182c207,226
< return DECLINED if ($REQUEST_COUNT++ < $CHECK_EVERY_N_REQUESTS);
< $REQUEST_COUNT = 1;
< if ($MAX_PROCESS_SIZE) {
< my $size = &$HOW_BIG_IS_IT();
< if ($size > $MAX_PROCESS_SIZE) {
< # I have no idea if this will work on anything but UNIX
< if (getppid > 1) { # this is a child httpd
< error_log("httpd process too big, exiting at SIZE=$size KB");
---
> return DECLINED if ($CHECK_EVERY_N_REQUESTS &&
> ($REQUEST_COUNT++ % $CHECK_EVERY_N_REQUESTS));
>
> $START_TIME ||= time;
>
> my($size, $share) = &$HOW_BIG_IS_IT();
>
> if (($MAX_PROCESS_SIZE && $size > $MAX_PROCESS_SIZE)
> ||
> ($MIN_SHARE_SIZE && $share < $MIN_SHARE_SIZE)
> ||
> ($MAX_UNSHARED_SIZE && ($size - $share) > $MAX_UNSHARED_SIZE)) {
>
> # wake up! time to die.
> if (getppid > 1) { # this is a child httpd
> my $e = time - $START_TIME;
> my $msg = "httpd process too big, exiting at SIZE=$size KB ";
> $msg .= " SHARE=$share KB " if ($share);
> $msg .= " REQUESTS=$REQUEST_COUNT LIFETIME=$e seconds";
> error_log($msg);
184,185c228,232
< } else { # this is the main httpd
< error_log("main process too big, SIZE=$size KB");
---
>
> } else { # this is the main httpd, whose parent is init?
> my $msg = "main process too big, exiting at SIZE=$size KB ";
> $msg .= " SHARE=$share KB" if ($share);
> error_log($msg);
187,189d233
< }
< } else {
< error_log("you didn't set \$Apache::SizeLimit::MAX_PROCESS_SIZE");
200a245,254
> sub setmin {
> $MIN_SHARE_SIZE = shift;
> Apache->request->post_connection(\&exit_if_too_big);
> }
>
> sub setmax_unshared {
> $MAX_UNSHARED_SIZE = shift;
> Apache->request->post_connection(\&exit_if_too_big);
> }
>
218a273,275
>
> Doug Steinwand and Perrin Harkins <perrin@elem.com>: added support
> for shared memory and additional diagnostic info
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@perl.apache.org
For additional commands, e-mail: dev-help@perl.apache.org
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic