You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Igor Chudov <ic...@yahoo.com> on 2005/05/09 19:24:40 UTC
Debugging memory allocation
my website algebra.com is 100% mod_perl. I use
Apache::SizeLimit to kill my httpd children when they
grow too big.
What I do not like is that they grow. Sometimes they
would live for a couple of hours, and sometimes they
would die after 5 minutes and not so many requests.
I would like to at least have a log that lists pid,
page requested, parameters, starting memory and memory
after the request was processed. O rsome other ideas
like that. Any thoughts?
- Igor
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
Re: Debugging memory allocation
Posted by Perrin Harkins <pe...@elem.com>.
On Tue, 2005-05-10 at 15:59 -0500, David Nicol wrote:
> Undoubtably. But how do you get the memory usage? read /proc/$$/mem or
> something?
That's what Apache::SizeLimit does, and it was as fast as
Apache::GTopLimit the last time I checked it.
- Perrin
Re: Debugging memory allocation
Posted by Igor Chudov <ic...@yahoo.com>.
I already have a function to get memory usage,
borrowed from Zpache::SizeLimit and modified.
sub linux_memory_size {
my($size, $resident, $share) = (0, 0, 0);
my $file = "/proc/self/statm";
if (open my $fh, "<$file") {
($size, $resident, $share) = split /\s/, scalar
<$fh>;
close $fh;
} else {
error_log("Fatal Error: couldn't access $file");
}
# linux on intel x86 has 4KB page size...
#return ($size * 4, $share * 4);
return $size * 4;
}
--- David Nicol <da...@gmail.com> wrote:
> On 5/10/05, Igor Chudov <ic...@yahoo.com> wrote:
> > LogHandler seems
> > like such a place.
>
> Undoubtably. But how do you get the memory usage?
> read /proc/$$/mem or
> something? there is not, AFAICTFRAQG (as far as I
> can tell from recollection
> and quick googling) a line noise variable for
> current memory usage, and cpan
> only has a procfs module defined for Solaris. So
> the question remains, after
> choosing loghandler as the way to write to the log,
> how to get the memory
> usage information? Is there a better way than ps in
> backticks?
> Proc::ProcessTable
> might be the thing -- it appears to reimplement ps
> with the output as
> a perl data
> structure rather than linefeed-separated records.
> There is also Unix::Process,
> but that is merely a wrapper for ps in backticks.
>
- Igor
__________________________________________________
Do You Yahoo!?
Tired of spam? Yahoo! Mail has the best spam protection around
http://mail.yahoo.com
Re: Debugging memory allocation
Posted by David Nicol <da...@gmail.com>.
On 5/10/05, Igor Chudov <ic...@yahoo.com> wrote:
> LogHandler seems
> like such a place.
Undoubtably. But how do you get the memory usage? read /proc/$$/mem or
something? there is not, AFAICTFRAQG (as far as I can tell from recollection
and quick googling) a line noise variable for current memory usage, and cpan
only has a procfs module defined for Solaris. So the question remains, after
choosing loghandler as the way to write to the log, how to get the memory
usage information? Is there a better way than ps in backticks?
Proc::ProcessTable
might be the thing -- it appears to reimplement ps with the output as
a perl data
structure rather than linefeed-separated records. There is also Unix::Process,
but that is merely a wrapper for ps in backticks.
Re: Debugging memory allocation
Posted by Igor Chudov <ic...@yahoo.com>.
I have a lot of code in a lot of places, and something
like 2-3 hits per second. It is a relatively busy
website. I cannot afford doing what was just
suggested, I would prefer some indirect perl
invocation at the appropriate place. LogHandler seems
like such a place.
i
--- David Nicol <da...@gmail.com> wrote:
> how about declaring something like
>
> sub LogMemoryUsage(){
> open PIDLOG, ">>pidlog";
> flock PIDLOG, LOCK_EX;
> print PIDLOG, "$$ $ENV{SCRIPT_NAME} ",`ps -p $$
> -os`
> close PIDLOG;
> };
>
> and then calling LogMemoryUsage() at the beginning
> (and end) of
> every routine that you suspect might have the leak?
> Examining the
> resulting log would provide clues.
>
> On 5/10/05, Igor Chudov <ic...@yahoo.com> wrote:
> > --- Sam Tregar <sa...@tregar.com> wrote:
> >
> > > On Mon, 9 May 2005, Igor Chudov wrote:
> > >
> > > > I would like to at least have a log that lists
> > > pid,
> > > > page requested, parameters, starting memory
> and
> > > memory
> > > > after the request was processed. O rsome other
> > > ideas
> > > > like that. Any thoughts?
>
>
> --
> David L Nicol
> Ask not, "who are you?", but rather, "are you
> allowed?"
> This was always the crucial question anyway.
> (from Marc Stiegler's SecurityPictureBook:
>
http://www.skyhunter.com/marcs/SecurityPictureBook.ppt)
>
- Igor
__________________________________
Do you Yahoo!?
Make Yahoo! your home page
http://www.yahoo.com/r/hs
Re: Debugging memory allocation
Posted by David Nicol <da...@gmail.com>.
how about declaring something like
sub LogMemoryUsage(){
open PIDLOG, ">>pidlog";
flock PIDLOG, LOCK_EX;
print PIDLOG, "$$ $ENV{SCRIPT_NAME} ",`ps -p $$ -os`
close PIDLOG;
};
and then calling LogMemoryUsage() at the beginning (and end) of
every routine that you suspect might have the leak? Examining the
resulting log would provide clues.
On 5/10/05, Igor Chudov <ic...@yahoo.com> wrote:
> --- Sam Tregar <sa...@tregar.com> wrote:
>
> > On Mon, 9 May 2005, Igor Chudov wrote:
> >
> > > I would like to at least have a log that lists
> > pid,
> > > page requested, parameters, starting memory and
> > memory
> > > after the request was processed. O rsome other
> > ideas
> > > like that. Any thoughts?
--
David L Nicol
Ask not, "who are you?", but rather, "are you allowed?"
This was always the crucial question anyway.
(from Marc Stiegler's SecurityPictureBook:
http://www.skyhunter.com/marcs/SecurityPictureBook.ppt)
Re: Debugging memory allocation
Posted by Perrin Harkins <pe...@elem.com>.
On Mon, 2005-05-09 at 14:46 -0400, Sam Tregar wrote:
> On Mon, 9 May 2005, Igor Chudov wrote:
>
> > I would like to at least have a log that lists pid,
> > page requested, parameters, starting memory and memory
> > after the request was processed. O rsome other ideas
> > like that. Any thoughts?
>
> Check out GTop.pm. You should be able to write a LogHandler which
> produces the stats you want.
Or use the subs in Apache::SizeLimit for calculating size. In fact,
expanding the logging in SizeLimit would be a nice patch if you're
interested and can do it without adding overhead for users that don't
want it.
- Perrin
(Who is sitting right next to Sam, amusingly enough...)
Re: Debugging memory allocation
Posted by Stas Bekman <st...@stason.org>.
> Can you point me to some LogHandler example that works
> under the latest released mod_perl 2.0?
http://perl.apache.org/docs/2.0/user/handlers/http.html#PerlLogHandler
--
__________________________________________________________________
Stas Bekman JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/ mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org http://ticketmaster.com
Re: Debugging memory allocation
Posted by Igor Chudov <ic...@yahoo.com>.
--- Sam Tregar <sa...@tregar.com> wrote:
> On Mon, 9 May 2005, Igor Chudov wrote:
>
> > I would like to at least have a log that lists
> pid,
> > page requested, parameters, starting memory and
> memory
> > after the request was processed. O rsome other
> ideas
> > like that. Any thoughts?
>
> Check out GTop.pm. You should be able to write a
> LogHandler which
> produces the stats you want.
Thanks.
Can you point me to some LogHandler example that works
under the latest released mod_perl 2.0?
thanks
i
- Igor
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250
Re: Debugging memory allocation
Posted by Sam Tregar <sa...@tregar.com>.
On Mon, 9 May 2005, Igor Chudov wrote:
> I would like to at least have a log that lists pid,
> page requested, parameters, starting memory and memory
> after the request was processed. O rsome other ideas
> like that. Any thoughts?
Check out GTop.pm. You should be able to write a LogHandler which
produces the stats you want.
-sam