After the talk of performance increase/decrease after the OS changes behind PerlMonks.org, I decided to create a tool that could be used to provide some actual statistics.
Basically it use LWP::Simple to fetch a page, Time::HiRes to measure the time it took, and mySQL/DBI to catalog the results. It can be used for other sites I guess, but their is PM specific code (extracting users from $content).
Comments/Suggestions very welcome (especially on the regex used for extracting the number of users). A tool for actually displaying some results is forthcoming.
Here is the code I used to create the web_load table:
create table web_load ( date datetime not null, url text not null, load_secs float unsigned not null, users int unsigned not null);
and here is the perl code:
#!/usr/bin/perl -w use DBI; use LWP::Simple; use Time::HiRes qw(gettimeofday tv_interval); use Getopt::Std; ####commandline config my (%options); getopts("w:u:p:h", \%options); if ($options{h}) { print <<'eof'; -w webpage: Webpage to fetch -u username: Username for mysql -p password: Password for mysql -h: This help file eof exit; } ####config my ($db_insert_time) = qq{INSERT web_load (date, url, load_secs, u +sers) VALUES(now(),?,?,?)}; #sql insert my ($url) = $options{w} || 'http://www.perlmonks.org/index.pl?node +_id=131'; #default webpage (perlmonks frontpage) my ($db_user_name) = $options{u} || ''; #default mysql username my ($db_password) = $options{p} || ''; #defualt mysql password my ($db_database) = 'DBI:mysql:website'; #default mysql database ####connect to db my ($DBH) = DBI->connect ($db_database, $db_user_name, $db_passwor +d, { RaiseError => 1 }); ####record start time, get frontpage, and calculate elapsed time my ($start_secs); $start_secs = [gettimeofday]; my ($content) = get($url); die ("Couldn't GET $url\n") unless defined $content; my ($load_secs) = tv_interval ($start_secs); ####extract users from $content and do some error checking (only for p +erlmonks) my ($users) = $content =~ /\((\d+?)\)<br \/><a HREF=/; die ("Couldn't extract users from $url\n") unless defined $users; ####insert users and load_secs into database my ($STH) = $DBH->prepare($db_insert_time); $STH->execute($url, load_secs, $users); ####database finish $STH->finish(); $DBH->disconnect();
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: mySQL Webpage Load Cataloger
by Coruscate (Sexton) on Feb 11, 2003 at 11:31 UTC | |
by smgfc (Monk) on Feb 11, 2003 at 16:29 UTC |