precache webgui config files

This commit is contained in:
JT Smith 2004-07-07 05:40:39 +00:00
parent 6bc2c33954
commit c39e7dc7b0
7 changed files with 196 additions and 34 deletions

View file

@ -57,6 +57,11 @@
performance gain while in admin mode.
- Changed the group and user management interfaces to work and scale better
with thousands of users and groups.
- Changed the config loader to preload the WebGUI config files into memory at
a cost of ~70k (mem) per site for a 2000% performance gain. It is a huge
gain, but it was already really fast, so relatively users aren't likely to
notice the difference. However, this change helps in the overall
scalability of WebGUI under load.
6.0.3

View file

@ -29,6 +29,13 @@ save you many hours of grief.
* Each user's language has been reset to the default language for
the site as specified in the profile settings.
* We removed a bunch of the cryptic-hack code that was allowing
backward compatibility all the way back to some 2.x, 3.x, and
4.x stuff. To be sure that your site will still work, copy
the gateway script (index.pl) over your old one. Also make
sure you have extrasPath and extrasURL defined in your config
file.
6.0.2
--------------------------------------------------------------------

156
lib/WebGUI/Config.pm Normal file
View file

@ -0,0 +1,156 @@
package WebGUI::Config;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2004 Plain Black LLC.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use Parse::PlainConfig;
our %config;
=head1 NAME
Package WebGUI::Config
=head1 DESCRIPTION
This package parses the WebGUI config file.
=head1 SYNOPSIS
use WebGUI::Config;
$hashRef = WebGUI::Config::getConfig($webguiRoot, $configFile);
$hashRef = WebGUI::Config::readConfig($webguiRoot, $configFile);
WebGUI::Config::loadAllConfigs($webguiRoot);
=head1 METHODS
These subroutines are available from this package:
=cut
#-------------------------------------------------------------------
=head2 getConfig ( webguiRoot , configFile )
Returns a hash reference containing the configuration data. It tries to get the data out of the memory cache first, but reads the config file directly if necessary.
=over
=item webguiRoot
The path to the WebGUI installation.
=item configFile
The filename of the config file to read.
=back
=cut
sub getConfig {
my $webguiPath = shift;
my $filename = shift;
if (exists $config{$filename}) {
return $config{$filename};
} else {
return readConfig($webguiPath,$filename);
}
}
#-------------------------------------------------------------------
=head2 loadAllConfigs ( webguiRoot )
Reads all the config file data for all defined sites into an in-memory cache.
=over
=item webguiRoot
The path to the WebGUI installation.
=back
=cut
sub laodAllConfigs {
my $webguiPath = shift;
opendir(DIR,$webguiPath."/etc");
my @files = readdir(DIR);
closedir(DIR);
foreach my $file (@files) {
if ($file =~ /\.conf$/) {
print "\tLoading ".$file."\n";
$config{$file} = readConfig($webguiPath,$file);
}
}
}
#-------------------------------------------------------------------
=head2 readConfig ( webguiRoot , configFile )
Returns a hash reference containing the configuration data. It reads the config data directly from the file.
=over
=item webguiRoot
The path to the WebGUI installation.
=item configFile
The filename of the config file to read.
=back
=cut
sub readConfig {
my $webguiPath = shift;
my $filename = shift;
my $config = Parse::PlainConfig->new('DELIM' => '=',
'FILE' => $webguiPath.'/etc/'.$filename,
'PURGE' => 1);
my %data;
foreach my $key ($config->directives) {
$data{$key} = $config->get($key);
}
if (ref $data{authMethods} ne "ARRAY") {
$data{authMethods} = [$data{authMethods}];
}
if( defined( $data{scripturl} ) ) {
# get rid of leading "/" if present.
$data{scripturl} =~ s/^\///;
}
if (ref $data{sitename} eq "ARRAY") {
$data{defaultSitename} = $data{sitename}[0];
} else {
$data{defaultSitename} = $data{sitename};
}
return \%data;
}
1;

View file

@ -15,7 +15,7 @@ use WebGUI::Session;
#-------------------------------------------------------------------
sub process {
return $session{config}{scripturl}.'/';
return ($session{config}{scripturl} || $session{env}{SCRIPT_NAME})."/";
}

View file

@ -19,9 +19,9 @@ use CGI;
use Date::Calc;
use DBI;
use Exporter;
use Parse::PlainConfig;
use strict;
use Tie::CPHash;
use WebGUI::Config;
use WebGUI::ErrorHandler;
use WebGUI::SQL;
use WebGUI::Utility;
@ -96,7 +96,7 @@ sub _setupPageInfo {
}
}
%page = WebGUI::SQL->quickHash("select * from page where pageId='".$pageId."'");
$page{url} = $session{config}{scripturl}."/".$page{urlizedTitle};
$page{url} = ($session{config}{scripturl} || $session{env}{SCRIPT_NAME})."/".$page{urlizedTitle};
$session{page} = \%page;
}
@ -291,7 +291,9 @@ The filename of the config file that WebGUI should operate from.
=cut
sub open {
my ($key, $config);
my $webguiRoot = shift;
my $configFile = shift;
my ($key);
###----------------------------
### operating system specific things
$session{os}{name} = $^O;
@ -304,32 +306,7 @@ sub open {
}
###----------------------------
### config variables
$session{config}{webguiRoot} = $_[0];
$session{config}{configFile} = $_[1] || "WebGUI.conf";
$config = Parse::PlainConfig->new('DELIM' => '=',
'FILE' => $session{config}{webguiRoot}.'/etc/'.$session{config}{configFile},
'PURGE' => 1);
foreach ($config->directives) {
$session{config}{$_} = $config->get($_);
}
if (ref $session{config}{authMethods} ne "ARRAY") {
$session{config}{authMethods} = [$session{config}{authMethods}];
}
if( defined( $session{config}{scripturl} ) ) {
# get rid of leading "/" if present.
$session{config}{scripturl} =~ s/^\///;
} else {
# default to the "real" path to script.
$session{config}{scripturl} = $ENV{SCRIPT_NAME};
}
$session{config}{extrasURL} = $session{config}{extrasURL} || $session{config}{extras} || "/extras";
$session{config}{extras} = $session{config}{extras} || $session{config}{extrasURL}; # for backward compatibility
$session{config}{extrasPath} = $session{config}{extrasPath} || "/data/WebGUI/www/extras";
if (ref $session{config}{sitename} eq "ARRAY") {
$session{config}{defaultSitename} = $session{config}{sitename}[0];
} else {
$session{config}{defaultSitename} = $session{config}{sitename};
}
$session{config} = WebGUI::Config::getConfig($webguiRoot,$configFile);
###----------------------------
### default database handler object
$session{dbh} = DBI->connect($session{config}{dsn},$session{config}{dbuser},$session{config}{dbpass},{ RaiseError=>0,AutoCommit=>1 });

View file

@ -148,7 +148,7 @@ Name value pairs to add to the URL in the form of:
=cut
sub gateway {
my $url = _getSiteURL().$session{config}{scripturl}.'/'.$_[0];
my $url = _getSiteURL().($session{config}{scripturl} || $session{env}{SCRIPT_NAME}).'/'.$_[0];
if ($_[1]) {
$url = append($url,$_[1]);
}

View file

@ -1,10 +1,16 @@
#!/usr/bin/perl
use strict;
use lib "/data/WebGUI/lib"; # Edit to match your WebGUI installation directory.
my $webguiRoot;
BEGIN {
$webguiRoot = "/data/WebGUI"; # Edit to match your WebGUI installation directory.
unshift (@INC, $webguiRoot."/lib");
}
print "Starting WebGUI ".$WebGUI::VERSION."\t\t";
$|=1;
print "\nStarting WebGUI ".$WebGUI::VERSION."\n";
$ENV{GATEWAY_INTERFACE} =~ /^CGI-Perl/ or die "GATEWAY_INTERFACE not Perl!";
#----------------------------------------
@ -14,6 +20,7 @@ $ENV{GATEWAY_INTERFACE} =~ /^CGI-Perl/ or die "GATEWAY_INTERFACE not Perl!";
use ModPerl::Registry (); # Uncomment this for use with mod_perl 2.0
#----------------------------------------
# System controlled Perl modules.
#----------------------------------------
@ -63,6 +70,7 @@ use WebGUI::Auth ();
use WebGUI::Cache ();
use WebGUI::Collateral ();
use WebGUI::CollateralFolder ();
use WebGUI::Config ();
use WebGUI::DatabaseLink ();
use WebGUI::DateTime ();
use WebGUI::ErrorHandler ();
@ -198,7 +206,16 @@ use WebGUI::Auth::WebGUI ();
use WebGUI::Macro::AdminBar ();
use WebGUI::Macro::Navigation ();
print "[ OK ]\n";
#----------------------------------------
# Preload all site configs.
#----------------------------------------
WebGUI::Config::laodAllConfigs($webguiRoot);
print "WebGUI Started!\n";
1;