From 2c972f3d70caf99488fff300341450e48be6ebf1 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 9 Jul 2016 03:18:35 +0000 Subject: www: add configurable limiters 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 --- lib/PublicInbox/Config.pm | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) (limited to 'lib/PublicInbox/Config.pm') diff --git a/lib/PublicInbox/Config.pm b/lib/PublicInbox/Config.pm index d34d11ad..d7eaa3e8 100644 --- a/lib/PublicInbox/Config.pm +++ b/lib/PublicInbox/Config.pm @@ -20,6 +20,7 @@ sub new { $self->{-by_addr} ||= {}; $self->{-by_name} ||= {}; $self->{-by_newsgroup} ||= {}; + $self->{-limiters} ||= {}; $self; } @@ -85,6 +86,15 @@ sub lookup_newsgroup { undef; } +sub limiter { + my ($self, $name) = @_; + $self->{-limiters}->{$name} ||= do { + require PublicInbox::Qspawn; + my $key = "limiter.$name.max"; + PublicInbox::Qspawn::Limiter->new($self->{$key}); + }; +} + sub get { my ($self, $inbox, $key) = @_; @@ -131,7 +141,7 @@ sub _fill { my $rv = {}; foreach my $k (qw(mainrepo address filter url newsgroup - watch watchheader)) { + watch watchheader httpbackendmax)) { my $v = $self->{"$pfx.$k"}; $rv->{$k} = $v if defined $v; } @@ -139,6 +149,7 @@ sub _fill { my $name = $pfx; $name =~ s/\Apublicinbox\.//; $rv->{name} = $name; + $rv->{-pi_config} = $self; $rv = PublicInbox::Inbox->new($rv); my $v = $rv->{address}; if (ref($v) eq 'ARRAY') { -- cgit v1.2.3-24-ge0c7