All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jakub Narebski <jnareb@gmail.com>
To: git@vger.kernel.org
Cc: Sam Vilain <sam.vilain@catalyst.net.nz>,
	Eric Wong <normalperson@yhbt.net>,
	Juan Jose Comellas <juanjo@comellas.org>,
	Peter Vereshagin <peter@vereshagin.org>,
	John Goerzen <jgoerzen@complete.org>
Subject: [RFC/PATCHv2 2/2] gitweb: Add support for FastCGI, using CGI::Fast
Date: Sat, 8 May 2010 09:59:00 +0200	[thread overview]
Message-ID: <201005080959.01800.jnareb@gmail.com> (raw)
In-Reply-To: <1273236845-6523-3-git-send-email-jnareb@gmail.com>

From: Sam Vilain <sam.vilain@catalyst.net.nz>

Former run() subroutine got renamed to run_request().  The new run()
subroutine can run multiple requests at once if run as FastCGI script.

To run gitweb as FastCGI script you must specify '--fastcgi' / '-f'
command line option to gitweb, otherwise it runs as an ordinary CGI
script.

[jn: cherry picked from 56d7d436644ab296155a697552ea1345f2701620
 in http://utsl.gen.nz/gitweb/?p=gitweb which was originally based
 on v264 (2326acfa95ac86a53804ca8eeeb482c2f9265e34) by Kay Sievers;
 updated to reflect current gitweb code]

TODO: update 'gitweb/README' and/or 'gitweb/INSTALL' files.

Signed-off-by: Sam Vilain <sam.vilain@catalyst.net.nz>
Signed-off-by: Jakub Narebski <jnareb@gmail.com>
---
Changes since v1:
* Fix $pre_dispatch_hook -> $post_dispatch_hook typo.

* Leave DONE_GITWEB label in run_request() subroutine.  This way "HTTP
  exceptions" thrown using die_error(), such as '404 Not Found', would
  correctly end current request, instead of exiting FCGI script.

  Note that in original patch by Sam Vilain "HTTP exceptions" would
  not run $post_dispatch_hook.

 gitweb/gitweb.perl |   54 ++++++++++++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 52 insertions(+), 2 deletions(-)

diff --git a/gitweb/gitweb.perl b/gitweb/gitweb.perl
index 41bf992..9a3eaf5 100755
--- a/gitweb/gitweb.perl
+++ b/gitweb/gitweb.perl
@@ -1012,7 +1012,7 @@ sub dispatch {
 	$actions{$action}->();
 }
 
-sub run {
+sub run_request {
 	our $t0 = [Time::HiRes::gettimeofday()]
 		if defined $t0;
 
@@ -1036,7 +1036,57 @@ sub run {
  DONE_GITWEB:
 	1;
 }
-our $cgi = CGI->new();
+
+our $is_last_request = sub { 1 };
+our ($pre_dispatch_hook, $post_dispatch_hook, $pre_listen_hook);
+our $CGI = 'CGI';
+our $cgi;
+sub evaluate_argv {
+	return unless (@ARGV);
+
+	require Getopt::Long;
+	Getopt::Long::GetOptions(
+		'fastcgi|fcgi|f' => sub {
+			require CGI::Fast;
+			our $CGI = 'CGI::Fast';
+
+			my $request_number = 0;
+			# let each child service 100 requests
+			our $is_last_request = sub { ++$request_number > 100 };
+		},
+		'nproc|n=i' => sub {
+			my ($arg, $val) = @_;
+			return unless eval { require FCGI::ProcManager; 1; };
+			my $proc_manager = FCGI::ProcManager->new({
+				n_processes => $val,
+			});
+			our $pre_listen_hook    = sub { $proc_manager->pm_manage()        };
+			our $pre_dispatch_hook  = sub { $proc_manager->pm_pre_dispatch()  };
+			our $post_dispatch_hook = sub { $proc_manager->pm_post_dispatch() };
+		},
+	);
+}
+
+sub run {
+	evaluate_argv();
+
+	$pre_listen_hook->()
+		if $pre_listen_hook;
+
+ REQUEST:
+	while ($cgi = $CGI->new()) {
+		$pre_dispatch_hook->()
+			if $pre_dispatch_hook;
+
+		run_request();
+
+		$post_dispatch_hook->()
+			if $post_dispatch_hook;
+
+		last REQUEST if ($is_last_request->());
+	}
+}
+
 run();
 
 ## ======================================================================
-- 
1.7.0.1

  reply	other threads:[~2010-05-08  7:59 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-05-07 12:54 [PATCH 0/2] gitweb: Add support for running gitweb as FastCGI script Jakub Narebski
2010-05-07 12:54 ` [PATCH/RFC 1/2] gitweb: Put all per-connection code in run() subroutine Jakub Narebski
2010-05-07 12:54 ` [RFC/PATCH 2/2] gitweb: Add support for FastCGI, using CGI::Fast Jakub Narebski
2010-05-08  7:59   ` Jakub Narebski [this message]
2010-05-08 22:41 ` [PATCH 0/2] gitweb: Add support for running gitweb as FastCGI script Jakub Narebski
2010-05-09  9:31   ` Eric Wong
2010-05-09 11:48     ` Ævar Arnfjörð Bjarmason
2010-05-09 12:39     ` Jakub Narebski
2010-05-09 16:47       ` Peter Vereshagin
2010-05-09 18:18         ` Jakub Narebski
2010-05-10  7:13           ` Peter Vereshagin
2010-05-10 15:29             ` Jakub Narebski
2010-05-11  6:24               ` Peter Vereshagin
2010-05-11  8:35                 ` Petr Baudis
2010-05-11 10:58                 ` Jakub Narebski
2010-05-11 12:09                   ` Peter Vereshagin
2010-05-11 13:51                     ` Jakub Narebski
2010-05-13 13:10                       ` Peter Vereshagin
2010-05-13 17:13                         ` Ævar Arnfjörð Bjarmason
2010-05-14 15:58                           ` Peter Vereshagin
2010-05-14 10:53                         ` Jakub Narebski
2010-05-14 15:36                           ` Peter Vereshagin
2010-05-14 17:58                             ` Jakub Narebski
2010-05-14 18:43                               ` Jakub Narebski
2010-05-15 10:06                               ` Peter Vereshagin
2010-05-15 13:58                                 ` Jakub Narebski
2010-05-16 10:15                                   ` Peter Vereshagin
2010-05-18  1:06                                     ` Jakub Narebski
2010-05-16 10:26                                   ` Petr Baudis
2010-05-15 11:51                           ` Petr Baudis

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=201005080959.01800.jnareb@gmail.com \
    --to=jnareb@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=jgoerzen@complete.org \
    --cc=juanjo@comellas.org \
    --cc=normalperson@yhbt.net \
    --cc=peter@vereshagin.org \
    --cc=sam.vilain@catalyst.net.nz \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.