threads / rfc / 43448

RFC patchgitweb: Add some mod_perl specific support

Subject: [RFC/PATCH (take 3)] gitweb: Add some mod_perl specific support

## tl;dr

5 messages between Dec 15, 2006 and Dec 16, 2006. Diffs are folded; open one to read it.

replies: 4people: 2as markdown or json

Jakub Narebski· Dec 15, 2006, 21:18 UTC · lore

[PATCH] gitweb: Add some mod_perl specific support

Add $r variable which holds Apache::RequestRec if script is run under mod_perl (if $ENV{MOD_PERL} is defined). It is used as argument to constructor of CGI object (needs CGI module version at least 2.93). It is needed for further mod_perl support, for example adding headers using Apache::RequestRec methods instead of making Apache to have to parse headers (to add it's own HTTP headers like Server: header).

Following advice from CGI(3pm) man page, precompile all CGI routines for mod_perl.

Use $r->path_info() instead of $ENV{"PATH_INFO"}.

All this makes gitweb slightly faster under mod_perl (436 +/- 23.9 ms for summary of git.git before, 429 +/- 12.0 ms after, according to 'ab -n 10 -k "http://localhost/perl/gitweb/gitweb.cgi?p=git.git"').

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
This is the same patch as previous
  'gitweb: Sprinkle some mod_perl goodies'
 gitweb/gitweb.perl |   11 +++++++++--
 1 files changed, 9 insertions(+), 2 deletions(-)
Show changes to gitweb/gitweb.perl +9 −2
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 902c514..7df253c 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -18,11 +18,18 @@ use File::Find qw();
 use File::Basename qw(basename);
 binmode STDOUT, ':utf8';
 
-our $cgi = new CGI;
+# mod_perl request
+my $r;
+$r = shift @_ if $ENV{MOD_PERL};
+
+our $cgi = new CGI($r);
 our $version = "++GIT_VERSION++";
 our $my_url = $cgi->url();
 our $my_uri = $cgi->url(-absolute => 1);
 
+# speeding up mod_perl and FastCGI (later)
+$cgi->compile() if $r;
+
 # core git executable to use
 # this can just be "git" if your webserver has a sensible PATH
 our $GIT = "++GIT_BINDIR++/git";
@@ -364,7 +371,7 @@ if (defined $searchtype) {
 # now read PATH_INFO and use it as alternative to parameters
 sub evaluate_path_info {
 	return if defined $project;
-	my $path_info = $ENV{"PATH_INFO"};
+	my $path_info = $r ? $r->path_info() : $ENV{"PATH_INFO"};
 	return if !$path_info;
 	$path_info =~ s,^/+,,;
 	return if !$path_info;
-- 
1.4.4.1
Jakub Narebski· Dec 16, 2006, 16:12 UTC · re: Jakub Narebski · lore

Add $r variable which holds Apache2::RequestRec if script is run under mod_perl (if $ENV{MOD_PERL} is defined). It is used as argument to constructor of CGI object (needs CGI module version at least 2.93). It is needed for further mod_perl support, for example adding headers using Apache2::RequestRec methods instead of making Apache to have to parse headers (to add it's own HTTP headers like Server: header).

Following advice from CGI(3pm) man page, precompile all CGI routines for mod_perl.

All this makes gitweb slightly faster under mod_perl (436 +/- 23.9 ms for summary of git.git before, 429 +/- 12.0 ms after, according to 'ab -n 10 -k "http://localhost/perl/gitweb/gitweb.cgi?p=git.git"').

Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
The idea is to have gitweb run under CGI and under mod_perl 1.0 and 2.0
without modifications, but making use of mod_perl features which make script
faster, like for example adding headers via mod_perl API and not via parsing
headers by Apache.  In the future the plan is to be able to run gitweb under
not only current ModPerl::Registry (or Apache::Registry in mod_perl 1.0) but
also as a mod_perl handler, and as a FastCGI script using CGI::Fast.

Current portion of mod_perl cpecific additions is mod_perl version agnostic, and avoids loading any mod_perl Perl modules.

I'd like to have it (and further mod_perl patches) reviewed by someone better versed in mod_perl.

 gitweb/gitweb.perl |    9 ++++++++-
 1 files changed, 8 insertions(+), 1 deletions(-)
Show changes to gitweb/gitweb.perl +8 −1
diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 902c514..f834c64 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -18,11 +18,18 @@ use File::Find qw();
 use File::Basename qw(basename);
 binmode STDOUT, ':utf8';
 
-our $cgi = new CGI;
+# mod_perl request
+my $r;
+$r = shift @_ if $ENV{MOD_PERL};
+
+our $cgi = new CGI($r);
 our $version = "++GIT_VERSION++";
 our $my_url = $cgi->url();
 our $my_uri = $cgi->url(-absolute => 1);
 
+# speeding up mod_perl and FastCGI (later)
+$cgi->compile() if $r;
+
 # core git executable to use
 # this can just be "git" if your webserver has a sensible PATH
 our $GIT = "++GIT_BINDIR++/git";
-- 
1.4.4.1
Jakub Narebski· Dec 16, 2006, 20:03 UTC · re: Junio C Hamano · lore

Re: [RFC/PATCH (take 3)] gitweb: Add some mod_perl specific support

Junio C Hamano wrote:
> I have your (take 2) merged already last night in my tree but
> haven't pushed the result out.  Does this replace it?
Yes, that replaces it. I'm very sorry for the confusion.

I have noticed that I would need to add "use Apache2::RequestRec" or it's mod_perl 1.0 equivalent before I can use $r->path_info().

-- 
Jakub Narebski
Junio C Hamano· Dec 16, 2006, 21:30 UTC · re: Jakub Narebski · lore

Re: [RFC/PATCH (take 3)] gitweb: Add some mod_perl specific support

Jakub Narebski <jnareb@gmail.com> writes:
Show 8 quoted lines
> Junio C Hamano wrote:
>> I have your (take 2) merged already last night in my tree but
>> haven't pushed the result out.  Does this replace it?
>
> Yes, that replaces it. I'm very sorry for the confusion.
>
> I have noticed that I would need to add "use Apache2::RequestRec"
> or it's mod_perl 1.0 equivalent before I can use $r->path_info().

I noticed the difference by applying the patch to the parent of (take 2) commit I made and diffing. It would be nice to have the above two line comment somewhere in the message, probably immediately after the three-dash lines, but no biggie.

Thanks for the clarification.

← back to recent threads