I have an extremely simple function that does the following - loads DBI, requires a common functions block, and then selects one row out of a tiny (6 record) MySQL database and prints it. the database has indexes, and what I mentioned is literally ALL that it does. I still get upwards of 6% CPU load from it, on a robust Apache server that severs a million html pages a month. yikes!
further details with associated questions:
- the common functions block (require "common_functions.pl") has 113 subroutines in it, only one of which i use. could loading all those subroutines be the problem? would it be better to split those up, and only call the ones I need - and if so, would (for example) five 'requires' be more ponderous than one require that has 5 subroutines in it?
- is use DBI; really that much of a memory hog? All i do is Selects (regular and 'count(*)'s) , Updates, Inserts, and Deletes - is there something small I could be loading?
Thank you so much for any help - I tried to type this as concisely as possible.
--- actual code:
#!/usr/bin/perl
require "common_function.pl";
use DBI;
use Digest::MD5 qw(md5 md5_hex md5_base64);
############# this is here to check their authentication - that line
+ removed from this code, and the load still happens without it here
print "Content-type: text/html \n\n";
$dbh = DBI->connect('DBI:mysql:name-of-db', 'NOT COPIED INTO HERE', '
+NOT COPIED INTO HERE');
######### this is the subroutine called from that common block, copied
+ into here for clarity ##########
$query = 'SELECT flag_value FROM server_flags WHERE flag_name = ?'
+;
$sthcf2 = $dbh->prepare($query);
$result=$sthcf2->execute("announcements_today");
($currentnews) = $sthcf2->fetchrow();
$sthcf2->finish();
##################
if ($currentnews ne ""){
$currentnews=<<_MOOSE_;
<table style="border-color:black;border-width:1px;border-style:solid;f
+ont-size:14px" bgcolor=FFFFFF><tr><td align=center width=100>
$currentnews
</td></tr></table>
_MOOSE_
$dbh->disconnect();
}
print $currentnews;
$dbh->disconnect();
--------
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.