📄 apache2::sizelimit.3
字号:
.\" Automatically generated by Pod::Man 2.16 (Pod::Simple 3.05).\".\" Standard preamble:.\" ========================================================================.de Sh \" Subsection heading.br.if t .Sp.ne 5.PP\fB\\$1\fR.PP...de Sp \" Vertical space (when we can't use .PP).if t .sp .5v.if n .sp...de Vb \" Begin verbatim text.ft CW.nf.ne \\$1...de Ve \" End verbatim text.ft R.fi...\" Set up some character translations and predefined strings. \*(-- will.\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left.\" double quote, and \*(R" will give a right double quote. \*(C+ will.\" give a nicer C++. Capital omega is used to do unbreakable dashes and.\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff,.\" nothing in troff, for use with C<>..tr \(*W-.ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p'.ie n \{\. ds -- \(*W-. ds PI pi. if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch. if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch. ds L" "". ds R" "". ds C` "". ds C' ""'br\}.el\{\. ds -- \|\(em\|. ds PI \(*p. ds L" ``. ds R" '''br\}.\".\" Escape single quotes in literal strings from groff's Unicode transform..ie \n(.g .ds Aq \(aq.el .ds Aq '.\".\" If the F register is turned on, we'll generate index entries on stderr for.\" titles (.TH), headers (.SH), subsections (.Sh), items (.Ip), and index.\" entries marked with X<> in POD. Of course, you'll have to process the.\" output yourself in some meaningful fashion..ie \nF \{\. de IX. tm Index:\\$1\t\\n%\t"\\$2"... nr % 0. rr F.\}.el \{\. de IX...\}.\".\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2)..\" Fear. Run. Save yourself. No user-serviceable parts.. \" fudge factors for nroff and troff.if n \{\. ds #H 0. ds #V .8m. ds #F .3m. ds #[ \f1. ds #] \fP.\}.if t \{\. ds #H ((1u-(\\\\n(.fu%2u))*.13m). ds #V .6m. ds #F 0. ds #[ \&. ds #] \&.\}. \" simple accents for nroff and troff.if n \{\. ds ' \&. ds ` \&. ds ^ \&. ds , \&. ds ~ ~. ds /.\}.if t \{\. ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u". ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u'. ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u'. ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u'. ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u'. ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u'.\}. \" troff and (daisy-wheel) nroff accents.ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V'.ds 8 \h'\*(#H'\(*b\h'-\*(#H'.ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#].ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H'.ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u'.ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#].ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#].ds ae a\h'-(\w'a'u*4/10)'e.ds Ae A\h'-(\w'A'u*4/10)'E. \" corrections for vroff.if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u'.if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u'. \" for low resolution devices (crt and lpr).if \n(.H>23 .if \n(.V>19 \\{\. ds : e. ds 8 ss. ds o a. ds d- d\h'-1'\(ga. ds D- D\h'-1'\(hy. ds th \o'bp'. ds Th \o'LP'. ds ae ae. ds Ae AE.\}.rm #[ #] #H #V #F C.\" ========================================================================.\".IX Title "mod_perl-2.0.2::docs::api::Apache2::SizeLimit 3".TH mod_perl-2.0.2::docs::api::Apache2::SizeLimit 3 "2005-10-21" "perl v5.10.0" "User Contributed Perl Documentation".\" For nroff, turn off justification. Always turn off hyphenation; it makes.\" way too many mistakes in technical documents..if n .ad l.nh.SH "NAME"Apache2::SizeLimit \- Because size does matter..SH "Synopsis".IX Header "Synopsis"This module allows you to kill off Apache httpd processes if they growtoo large. You can choose to set up the process size limiter to checkthe process size on every request:.PP.Vb 6\& # in your startup.pl, or a <Perl> section:\& use Apache2::SizeLimit;\& # sizes are in KB\& $Apache2::SizeLimit::MAX_PROCESS_SIZE = 12000; # 12MB\& $Apache2::SizeLimit::MIN_SHARE_SIZE = 6000; # 6MB\& $Apache2::SizeLimit::MAX_UNSHARED_SIZE = 5000; # 5MB\&\& # in your httpd.conf:\& PerlCleanupHandler Apache2::SizeLimit.Ve.PPOr you can just check those requests that are likely to get big, suchas \s-1CGI\s0 requests. This way of checking is also easier for those whoare mostly just running \s-1CGI\s0 scripts under\&\f(CW\*(C`ModPerl::Registry\*(C'\fR:.PP.Vb 6\& # in your script:\& use Apache2::SizeLimit;\& # sizes are in KB\& Apache2::SizeLimit::setmax(12000);\& Apache2::SizeLimit::setmin(6000);\& Apache2::SizeLimit::setmax_unshared(5000);.Ve.PPThis will work in places where you are using \f(CW\*(C`SetHandlerperl\-script\*(C'\fR oranywhere you enable \f(CW\*(C`PerlOptions+GlobalRequest\*(C'\fR. Ifyou want to avoid turning on \f(CW\*(C`GlobalRequest\*(C'\fR, you can pass an\&\f(CW\*(C`Apache2::RequestRec\*(C'\fR object asthe second argument in these subs:.PP.Vb 4\& my $r = shift; # if you don\*(Aqt have $r already\& Apache2::SizeLimit::setmax(12000, $r);\& Apache2::SizeLimit::setmin(6000, $r);\& Apache2::SizeLimit::setmax_unshared(5000, $r);.Ve.PPSince checking the process size can take a few system calls on someplatforms (e.g. linux), you may want to only check the process sizeevery N times. To do so, put this in your startup.pl or \s-1CGI:\s0.PP.Vb 1\& $Apache2::SizeLimit::CHECK_EVERY_N_REQUESTS = 2;.Ve.PPThis will only check the process size every other time the processsize checker is called..SH "Description".IX Header "Description"This module is highly platform dependent, please read theCaveats section. It also does not work under threadedMPMs..PPThis module was written in response to questions on the mod_perlmailing list on how to tell the httpd process to exit if it gets toobig..PPActually there are two big reasons your httpd children will grow.First, it could have a bug that causes the process to increase in sizedramatically, until your system starts swapping. Second, it may justdo things that requires a lot of memory, and the more different kindsof requests your server handles, the larger the httpd processes growover time..PPThis module will not really help you with the first problem. For thatyou should probably look into\&\f(CW\*(C`Apache2::Resource\*(C'\fR or some othermeans of setting a limit on the data size of your program. BSD-ishsystems have \f(CW\*(C`setrlimit()\*(C'\fR which will croak your memory gobblingprocesses. However it is a little violent, terminating your processin mid-request..PPThis module attempts to solve the second situation where your processslowly grows over time. The idea is to check the memory usage afterevery request, and if it exceeds a threshold, exit gracefully..PPBy using this module, you should be able to discontinue using theApache configuration directive \f(CW\*(C`MaxRequestsPerChild\*(C'\fR, although youcan use both if you are feeling paranoid. Most users use thetechnique shown in this module and set their \f(CW\*(C`MaxRequestsPerChild\*(C'\fRvalue to \f(CW0\fR..SH "Shared Memory Options".IX Header "Shared Memory Options"In addition to simply checking the total size of a process, thismodule can factor in how much of the memory used by the process isactually being shared by copy-on-write. If you don't understand howmemory is shared in this way, take a look at the extensivedocumentation at http://perl.apache.org/docs/..PPYou can take advantage of the shared memory information by setting aminimum shared size and/or a maximum unshared size. Experience on oneheavily trafficked mod_perl site showed that setting maximum unsharedsize and leaving the others unset is the most effective policy. Thisis because it only kills off processes that are truly using too muchphysical \s-1RAM\s0, allowing most processes to live longer and reducing theprocess churn rate..SH "Caveats".IX Header "Caveats"This module is platform-dependent, since finding the size of a processis pretty different from \s-1OS\s0 to \s-1OS\s0, and some platforms may not besupported. In particular, the limits on minimum shared memory andmaximum shared memory are currently only supported on Linux and \s-1BSD\s0.If you can contribute support for another \s-1OS\s0, please do..Sh "Supported OSes".IX Subsection "Supported OSes".IP "linux" 4.IX Item "linux"For linux we read the process size out of \fI/proc/self/statm\fR. Thisseems to be fast enough on modern systems. If you are worried aboutperformance, try setting the \f(CW\*(C`CHECK_EVERY_N_REQUESTS\*(C'\fR option..SpSince linux 2.6 \fI/proc/self/statm\fR does not report the amount ofmemory shared by the copy-on-write mechanism as shared memory. Hencedecisions made on the basis of \f(CW\*(C`MAX_UNSHARED_SIZE\*(C'\fR or \f(CW\*(C`MIN_SHARE_SIZE\*(C'\fRare inherently wrong..SpTo correct the situation there is a patch to the linux kernel that adds a\&\fI/proc/self/smaps\fR entry for each process. At the time of this writingthe patch is included in the mm-tree (linux\-2.6.13\-rc4\-mm1) and is expectedto make it into the vanilla kernel in the near future..Sp\&\fI/proc/self/smaps\fR reports various sizes for each memory segment of aprocess and allows to count the amount of shared memory correctly..SpIf \f(CW\*(C`Apache2::SizeLimit\*(C'\fR detects a kernel that supports \fI/proc/self/smaps\fRand if the \f(CW\*(C`Linux::Smaps\*(C'\fR module is installed it will use them instead of\&\fI/proc/self/statm\fR. You can prevent \f(CW\*(C`Apache2::SizeLimit\*(C'\fR from using\&\fI/proc/self/smaps\fR and turn on the old behaviour by setting\&\f(CW$Apache2::SizeLimit::USE_SMAPS\fR to 0 before the first check..Sp\&\f(CW\*(C`Apache2::SizeLimit\*(C'\fR also resets \f(CW$Apache2::SizeLimit::USE_SMAPS\fR to 0if it somehow decides not to use \fI/proc/self/smaps\fR. Thus, you cancheck it to determine what is actually used..Sp\&\s-1NOTE:\s0 Reading \fI/proc/self/smaps\fR is expensive compared to\&\fI/proc/self/statm\fR. It must look at each page table entry of a process.Further, on multiprocessor systems the access is synchronized withspinlocks. Hence, you are encouraged to set the \f(CW\*(C`CHECK_EVERY_N_REQUESTS\*(C'\fRoption..SpThe following example shows the effect of copy-on-write:.Sp.Vb 7\& <Perl>\& require Apache2::SizeLimit;\& package X;\& use strict;\& use Apache2::RequestRec ();\& use Apache2::RequestIO ();\& use Apache2::Const \-compile=>qw(OK);\&\& my $x= "a" x (1024*1024);\&\& sub handler {\& my $r = shift;\& my ($size, $shared) = $Apache2::SizeLimit::HOW_BIG_IS_IT\->();\& $x =~ tr/a/b/;\& my ($size2, $shared2) = $Apache2::SizeLimit::HOW_BIG_IS_IT\->();\& $r\->content_type(\*(Aqtext/plain\*(Aq);\& $r\->print("1: size=$size shared=$shared\en");\& $r\->print("2: size=$size2 shared=$shared2\en");\& return Apache2::Const::OK;\& }\& </Perl>\&\& <Location /X>\& SetHandler modperl\& PerlResponseHandler X\& </Location>.Ve.SpThe parent apache allocates a megabyte for the string in \f(CW$x\fR. The\&\f(CW\*(C`tr\*(C'\fR\-command then overwrites all \*(L"a\*(R" with \*(L"b\*(R" if the handler iscalled with an argument. This write is done in place, thus, theprocess size doesn't change. Only \f(CW$x\fR is not shared anymore bymeans of copy-on-write between the parent and the child..SpIf \fI/proc/self/smaps\fR is available curl shows:.Sp.Vb 3\& r2@s93:~/work/mp2> curl http://localhost:8181/X\& 1: size=13452 shared=7456\& 2: size=13452 shared=6432.Ve.SpShared memory has lost 1024 kB. The process' overall size remains unchanged..SpWithout \fI/proc/self/smaps\fR it says:.Sp.Vb 3\& r2@s93:~/work/mp2> curl http://localhost:8181/X\& 1: size=13052 shared=3628\& 2: size=13052 shared=3636.Ve.SpOne can see the kernel lies about the shared memory. It simply doesn't count copy-on-write pages as shared..IP "Solaris 2.6 and above" 4.IX Item "Solaris 2.6 and above"For Solaris we simply retrieve the size of \fI/proc/self/as\fR, whichcontains the address-space image of the process, and convert to \s-1KB\s0.Shared memory calculations are not supported..Sp\&\s-1NOTE:\s0 This is only known to work for solaris 2.6 and above. Evidentlythe /proc filesystem has changed between 2.5.1 and 2.6. Can anyoneconfirm or deny?.IP "\s-1BSD\s0" 4.IX Item "BSD"Uses \f(CW\*(C`BSD::Resource::getrusage()\*(C'\fR to determine process size. This ispretty efficient (a lot more efficient than reading it from the\&\fI/proc\fR fs anyway)..IP "\s-1AIX\s0?" 4.IX Item "AIX?"Uses \f(CW\*(C`BSD::Resource::getrusage()\*(C'\fR to determine process size. Notsure if the shared memory calculations will work or not. \s-1AIX\s0 users?.IP "Win32" 4.IX Item "Win32"Under mod_perl 1, SizeLimit provided basic functionality by using \&\f(CW\*(C`Win32::API\*(C'\fR to access process memory information. This worked because there was only one mod_perl thread. With mod_perl 2, Win32 runs a true threaded \s-1MPM\s0, which unfortunately means that we can't tell the size of each interpreter. Win32 support is disabled until a solution for this can be found..PPIf your platform is not supported, and if you can tell us how to checkfor the size of a process under your \s-1OS\s0 (in \s-1KB\s0), then we will add it tothe list. The more portable/efficient the solution, the better, ofcourse..Sh "Supported MPMs".IX Subsection "Supported MPMs"At this time, \f(CW\*(C`Apache2::SizeLimit\*(C'\fR does not support use under threadedMPMs. This is because there is no efficient way to get the memoryusage of a thread, or make a thread exit cleanly. Suggestions andpatches are welcome on the mod_perl dev mailinglist..SH "Copyright".IX Header "Copyright"mod_perl 2.0 and its core modules are copyrighted underThe Apache Software License, Version 2.0..SH "Author".IX Header "Author"Doug Bagley <doug+modperl bagley.org>, channeling Procrustes..PPBrian Moseley <ix maz.org>: Solaris 2.6 support.PPDoug Steinwand and Perrin Harkins <perrin elem.com>: addedsupport for shared memory and additional diagnostic info.PPMatt Phillips <mphillips virage.com> and Mohamed Hendawi<mhendawi virage.com>: Win32 support.PPTorsten Foertsch <torsten.foertsch gmx.net>: Linux::Smaps support
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -