diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index 05372d4c1..d6b81c1ed 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -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 diff --git a/docs/gotcha.txt b/docs/gotcha.txt index 075a2db6c..d238ed451 100644 --- a/docs/gotcha.txt +++ b/docs/gotcha.txt @@ -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 -------------------------------------------------------------------- diff --git a/lib/WebGUI/Config.pm b/lib/WebGUI/Config.pm new file mode 100644 index 000000000..65e92740b --- /dev/null +++ b/lib/WebGUI/Config.pm @@ -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; + diff --git a/lib/WebGUI/Macro/Slash_gatewayUrl.pm b/lib/WebGUI/Macro/Slash_gatewayUrl.pm index e9ef225dc..fbd04a6fd 100644 --- a/lib/WebGUI/Macro/Slash_gatewayUrl.pm +++ b/lib/WebGUI/Macro/Slash_gatewayUrl.pm @@ -15,7 +15,7 @@ use WebGUI::Session; #------------------------------------------------------------------- sub process { - return $session{config}{scripturl}.'/'; + return ($session{config}{scripturl} || $session{env}{SCRIPT_NAME})."/"; } diff --git a/lib/WebGUI/Session.pm b/lib/WebGUI/Session.pm index 8b994aee9..c4ea24723 100644 --- a/lib/WebGUI/Session.pm +++ b/lib/WebGUI/Session.pm @@ -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 }); diff --git a/lib/WebGUI/URL.pm b/lib/WebGUI/URL.pm index ea45eff13..1989fd2f4 100644 --- a/lib/WebGUI/URL.pm +++ b/lib/WebGUI/URL.pm @@ -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]); } diff --git a/sbin/preload.perl b/sbin/preload.perl index 5bf7b5f8a..c48ca3ea5 100644 --- a/sbin/preload.perl +++ b/sbin/preload.perl @@ -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;