[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cgiapp] RE: HTMLTemplate::Expr consumes huge amounts of memory


From: Sam Tregar 
Sent: Sunday, 12 March 2006 06:21
> 
> On Sat, 11 Mar 2006, Dan Horne wrote:
> 
> > I'm using CGI::Application::Plugin::Anytemplate with 
> > HTML::Template::Expr for an application, and it uses a heck 
> of a lot 
> > of memory.
> 
> What version of HTML::Template::Expr?  Do you have caching 
> turned on? Can you reproduce this problem with a small test 
> script and test template?
> 
> > Trying to track down memory usage in Perl can be hard. Running 
> > Devel::FindGlobals, I see that the reported size for 
> > $HTML::Template::Expr::PARSER is 100,039,491 bytes after publishing 
> > 500 articles!
> 
> Wow.  I don't know why $PARSER would grow at all at 
> runtime...  That's the Parse::RecDescent object which is 
> initialized at compile-time. What version of 
> Parse::RecDescent are you using?
> 
> -sam
> 
Hi Sam,

My module versions are:

Parse::RecDescent 1.94
HTML::Template 2.8
HTML::Template::Expr 0.06
CGI::Application::Plugin::AnyTemplate 0.17

The problem can be reproduced with the following code. To test, just run
instance.pl from the OS prompt. Note that I direct the template output to
the filesytem as per the original code, but this shouldn't make any
difference. If you run the code, top will show the instance script gobbling
ever increasing amounts of memory. If you replace 'HTMLTemplateExpr' with
'HTMLTemplate' in line 10 of TestExpr.pm, the memory usage remains pretty
constant

TestExpr.pm
===========

package  TestExpr;
use base 'CGI::Application';
use CGI::Application::Plugin::AnyTemplate;
use Data::Dumper;
use strict;

sub cgiapp_init {
    my $self = shift;
    $self->template->config(
        default_type                => 'HTMLTemplateExpr',
    );
}

sub setup {
    my $self = shift;
    $self->start_mode('test_case');
    $self->run_modes(['test_case']);
}

sub test_publish {
    my $self = shift;
    my $template = $self->template->load(file => 'test');
    $template->param('title', 'This is my title');
    $template->param('summary', 'Just some summary text');
    
    open (my $fh, '>', '/tmp/output');
    print $fh ${$template->output};
    close $fh;    
    1;
}

sub test_case {
    my $self = shift;
    foreach my $j (0..50000) {
        $self->test_publish();
    }
    
    return 'ok';
}

1;

instance.pl
===========

#!/usr/local/bin/perl -w
use strict;
use CGI::Carp qw(fatalsToBrowser);
use CGI::Application::Dispatch;

CGI::Application::Dispatch->dispatch(
    CGIAPP_DISPATCH_DEFAULT => 'test_case',
    CGIAPP_DISPATCH_RM => 1,
    TABLE                   => {
        test_case        => 'TestExpr',
    }
);

test.html
=========

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html lang="en">
<head>
    <title>HTML::Template::Expr Test</title>
</head>
<body>
        Title: <tmpl_var title>
        Summary: <tmpl_var summary>
</body>
</html>

regards

Dan


---------------------------------------------------------------------
Web Archive:  http://www.mail-archive.com/suppressed/
              http://marc.theaimsgroup.com/?l=cgiapp&r=1&w=2
To unsubscribe, e-mail: suppressed
For additional commands, e-mail: suppressed


Mail converted by mhonarc 2.6.15
This archive provided courtesy of JSW4.NET, Internet Hosting Services for Small Business.