about summary refs log tree commit homepage
path: root/lib/PublicInbox/Inbox.pm
diff options
context:
space:
mode:
authorEric Wong <e@80x24.org>2016-07-09 03:18:35 +0000
committerEric Wong <e@80x24.org>2016-07-09 03:20:25 +0000
commit2c972f3d70caf99488fff300341450e48be6ebf1 (patch)
tree066ba4c048b2fb64c271de1bc8096cdca46551ec /lib/PublicInbox/Inbox.pm
parentf89bd1444a595b569606679293d2d01b0b7a049e (diff)
downloadpublic-inbox-2c972f3d70caf99488fff300341450e48be6ebf1.tar.gz
Currently only for git-http-backend use, this allows limiting
the number of spawned processes per-inbox or by group, if there
are multiple large inboxes amidst a sea of small ones.

For example, a "big" repo limiter could be used for big inboxes:
which would be shared between multiple repos:

[limiter "big"]
	max = 4
[publicinbox "git"]
	address = git@vger.kernel.org
	mainrepo = /path/to/git.git
	; shared limiter with giant:
	httpbackendmax = big
[publicinbox "giant"]
	address = giant@project.org
	mainrepo = /path/to/giant.git
	; shared limiter with git:
	httpbackendmax = big

; This is a tiny inbox, use the default limiter with 32 slots:
[publicinbox "meta"]
	address = meta@public-inbox.org
	mainrepo = /path/to/meta.git
Diffstat (limited to 'lib/PublicInbox/Inbox.pm')
-rw-r--r--lib/PublicInbox/Inbox.pm25
1 files changed, 24 insertions, 1 deletions
diff --git a/lib/PublicInbox/Inbox.pm b/lib/PublicInbox/Inbox.pm
index dc9980b7..23b77213 100644
--- a/lib/PublicInbox/Inbox.pm
+++ b/lib/PublicInbox/Inbox.pm
@@ -34,6 +34,7 @@ sub new {
         my $v = $opts->{address} ||= 'public-inbox@example.com';
         my $p = $opts->{-primary_address} = ref($v) eq 'ARRAY' ? $v->[0] : $v;
         $opts->{domain} = ($p =~ /\@(\S+)\z/) ? $1 : 'localhost';
+        weaken($opts->{-pi_config});
         bless $opts, $class;
 }
 
@@ -44,11 +45,33 @@ sub _weaken_fields {
         }
 }
 
+sub _set_limiter ($$$) {
+        my ($self, $git, $pfx) = @_;
+        my $lkey = "-${pfx}_limiter";
+        $git->{$lkey} = $self->{$lkey} ||= eval {
+                my $mkey = $pfx.'max';
+                my $val = $self->{$mkey} or return;
+                my $lim;
+                if ($val =~ /\A\d+\z/) {
+                        require PublicInbox::Qspawn;
+                        $lim = PublicInbox::Qspawn::Limiter->new($val);
+                } elsif ($val =~ /\A[a-z][a-z0-9]*\z/) {
+                        $lim = $self->{-pi_config}->limiter($val);
+                        warn "$mkey limiter=$val not found\n" if !$lim;
+                } else {
+                        warn "$mkey limiter=$val not understood\n";
+                }
+                $lim;
+        }
+}
+
 sub git {
         my ($self) = @_;
         $self->{git} ||= eval {
                 _weaken_later($self);
-                PublicInbox::Git->new($self->{mainrepo});
+                my $g = PublicInbox::Git->new($self->{mainrepo});
+                _set_limiter($self, $g, 'httpbackend');
+                $g;
         };
 }