mraful has asked for the wisdom of the Perl Monks concerning the following question:

I am seeking perl wisdom. I am running a mod_perl2/Apache2.0 environment. I have written a Netflow collector which stuffs items into MS SQL Server ( no rants on Microsoft please, I am not responsible for our purchasing decisions.) This part works well and the web interface works reasonably well, except... Some the rows returned from the Netflow database run into the thousands and take a lonng time to load in the browser. Smaller amounts of data load quickly. The tables are indexed and the templates load through my startup.pl. I ran this as a straight script and not through Apache and the Perl dbi returns large result sets quickly. Is there something I am missing to speed things up or is HTML::Template too slow to handle large amounts of data returned and should I look at TT. Here is my startup.pl
#!/usr/bin/perl use HTML::Template; use File::Find; use ModPerl::Util; use ModPerl::Registry (); use Apache::DBI; use Apache2::RequestRec (); use Apache2::RequestIO (); use Apache2::Filter (); use Apache2::RequestUtil (); use Apache2::ServerRec (); use Apache2::ServerUtil (); use Apache2::Connection (); use Apache2::Log (); use APR::Pool (); use APR::Table (); use Apache2::Const -compile => ':common'; use APR::Const -compile => ':common'; use Socket qw(:DEFAULT :crlf); use Net::Ping; use Net::NBName; use POSIX qw(strftime); use Date::Calc qw( Today Add_Delta_Days ); use DBI; use DBD::ODBC; Apache::DBI->connect_on_init( 'dbi:ODBC:MRIServer2k', 'mriinventory', +'Wysiwyg@3044', { PrintError => 1, RaiseError => 0, AutoC +ommit => 1 } ); print STDERR "Pre-loading HTML Template...\n"; find ( sub { return unless /\.tmpl$/; HTML::Template->new( filename => "$File::Find:: +dir/$_", cache => 1, ); }, '/var/www/yanma/templates', );
Here is my "default" apache2 file:
NameVirtualHost * <VirtualHost *> ServerAdmin webmaster@localhost DocumentRoot /var/www/yanma ServerName yanma.usmc-mccs.org <Directory /var/www/yanma> DirectoryIndex index.html AllowOverride None Order allow,deny allow from all # Uncomment this directive is you want to see apache2's # default start page (in /apache2-default) when you go to / #RedirectMatch ^/$ /apache2-default/ </Directory> <Directory /var/www/yanma/administration> AuthName "Kerberos Login" AuthType Kerberos Krb5Keytab /etc/auth_kerb.keytab KrbAuthRealm WINDOWS.USMC-MCCS.ORG KrbMethodNegotiate off KrbSaveCredentials off KrbSaveCredentials off KrbVerifyKDC off </Directory> PerlModule Handlers::ChooseBase PerlModule Handlers::Devices PerlModule Handlers::PortMapper PerlModule Handlers::ChooseModel PerlModule Handlers::ActiveModels <Location /choosebase> SetHandler perl-script PerlResponseHandler Handlers::ChooseBase PerlOptions +ParseHeaders +GlobalRequest Order allow,deny Allow from all </Location> <Location /devices> SetHandler perl-script PerlResponseHandler Handlers::Devices PerlOptions +ParseHeaders +GlobalRequest Order allow,deny Allow from all </Location> <Location /portmapper> SetHandler perl-script PerlResponseHandler Handlers::PortMapper PerlOptions +ParseHeaders +GlobalRequest Order allow,deny Allow from all </Location> <Location /choosemodel> SetHandler perl-script PerlResponseHandler Handlers::ChooseModel PerlOptions +ParseHeaders +GlobalRequest Order allow,deny Allow from all </Location> <Location /activemodels> SetHandler perl-script PerlResponseHandler Handlers::ActiveModels PerlOptions +ParseHeaders +GlobalRequest Order allow,deny Allow from all </Location> <Location /chooserouter> SetHandler perl-script PerlResponseHandler Handlers::ChooseRouter PerlOptions +ParseHeaders +GlobalRequest Order allow,deny Allow from all </Location> <Location /flows> SetHandler perl-script PerlResponseHandler Handlers::Flows PerlOptions +ParseHeaders +GlobalRequest Order allow,deny Allow from all </Location> ErrorLog /var/log/apache2/error.log # Possible values include: debug, info, notice, warn, error, crit, # alert, emerg. LogLevel debug CustomLog /var/log/apache2/access.log combined ServerSignature On <Directory /var/www/yanma/templates> Options Indexes FollowSymLinks Multiviews AllowOverride None Order allow,deny allow from all # Uncomment this directive is you want to see apache2's # default start page (in /apache2-default) when you go to / #RedirectMatch ^/$ /apache2-default/ </Directory> Alias /doc/ "/usr/share/doc/" <Directory "/usr/share/doc/"> Options Indexes MultiViews FollowSymLinks AllowOverride None Order deny,allow Deny from all Allow from 127.0.0.0/255.0.0.0 ::1/128 </Directory> </VirtualHost>
Thanks in advance for the Perls of Wisdom.

Replies are listed 'Best First'.
Re: slow mod_perl2 or slow html::template
by moritz (Cardinal) on Jul 23, 2008 at 20:46 UTC
    If you don't know what's slow, profile it. Just the other day tim.bunce released Devel::NYTProf 2, which also has a good interface for profiling web applications.

    If the database is the bottleneck, see if you can add some indexes on relevant columns.

    If the template is the bottleneck, use HTML::Template::Compiled, which is a (nearly) drop-in replacement for HTML::Template, but which compiles the templates and caches the compiled form, if set up appropriately.

Re: slow mod_perl2 or slow html::template
by duckyd (Hermit) on Jul 23, 2008 at 21:39 UTC
    Browsers are often very slow to render large tables. Also keep in mind the size of the html generated. You might use a wget or somesuch to just see how fast it is to download the page itself - it might give you a starting place to determine if the browser is just slow to render the page.
      To those that responded, thanks! The database results return quickly. I loaded HTML::Template::Compiled. That made a difference and only required minor changes. The biggest drag, it turns out is rendering the large table. I removed the html tags for the table and displayed the data as lines of text. It loaded faster and my browser (firefox) was able to scroll through the data faster. Time to brush up on my CSS.