This means all Inbox, Git, Over, Msgmap, Search objects also get
deduplicated if they belong to the same config file, reducing
memory and FD usage. This helps save memory and improve cache
hit rates in -netd setups where NNTP, IMAP, HTTP, and POP3
servers run in the same process.
InboxIdle was the only bit which needed adjustment, but there
may be other bugs lurking despite all tests passing.
use PublicInbox::Inbox;
use PublicInbox::Spawn qw(popen_rd);
our $LD_PRELOAD = $ENV{LD_PRELOAD}; # only valid at startup
use PublicInbox::Inbox;
use PublicInbox::Spawn qw(popen_rd);
our $LD_PRELOAD = $ENV{LD_PRELOAD}; # only valid at startup
+our $DEDUPE; # set to {} to dedupe or clear cache
sub _array ($) { ref($_[0]) eq 'ARRAY' ? $_[0] : [ $_[0] ] }
sub _array ($) { ref($_[0]) eq 'ARRAY' ? $_[0] : [ $_[0] ] }
my ($class, $file, $errfh) = @_;
$file //= default_file();
my $self;
my ($class, $file, $errfh) = @_;
$file //= default_file();
my $self;
if (ref($file) eq 'SCALAR') { # used by some tests
open my $fh, '<', $file or die; # PerlIO::scalar
$self = config_fh_parse($fh, "\n", '=');
bless $self, $class;
} else {
if (ref($file) eq 'SCALAR') { # used by some tests
open my $fh, '<', $file or die; # PerlIO::scalar
$self = config_fh_parse($fh, "\n", '=');
bless $self, $class;
} else {
+ if (-f $file && $DEDUPE) {
+ $file = rel2abs_collapsed($file);
+ $self = $DEDUPE->{$file} and return $self;
+ $set_dedupe = 1;
+ }
$self = git_config_dump($class, $file, $errfh);
$self->{'-f'} = $file;
}
$self = git_config_dump($class, $file, $errfh);
$self->{'-f'} = $file;
}
if (my $css = delete $self->{'publicinbox.css'}) {
$self->{css} = _array($css);
}
if (my $css = delete $self->{'publicinbox.css'}) {
$self->{css} = _array($css);
}
+ $DEDUPE->{$file} = $self if $set_dedupe;
use PublicInbox::Git;
use PublicInbox::GitAsyncCat;
use PublicInbox::Eml;
use PublicInbox::Git;
use PublicInbox::GitAsyncCat;
use PublicInbox::Eml;
+use PublicInbox::Config;
our $SO_ACCEPTFILTER = 0x1000;
my @CMD;
my ($set_user, $oldset);
our $SO_ACCEPTFILTER = 0x1000;
my @CMD;
my ($set_user, $oldset);
sub daemon_loop ($) {
my ($xnetd) = @_;
sub daemon_loop ($) {
my ($xnetd) = @_;
+ local $PublicInbox::Config::DEDUPE = {}; # enable dedupe cache
my $refresh = sub {
my ($sig) = @_;
my $refresh = sub {
my ($sig) = @_;
+ %$PublicInbox::Config::DEDUPE = (); # clear cache
for my $xn (values %$xnetd) {
delete $xn->{tlsd}->{ssl_ctx}; # PublicInbox::TLS::start
eval { $xn->{refresh}->($sig) };
for my $xn (values %$xnetd) {
delete $xn->{tlsd}->{ssl_ctx}; # PublicInbox::TLS::start
eval { $xn->{refresh}->($sig) };
my $old_ibx = $cur->[0];
$cur->[0] = $ibx;
if ($old_ibx) {
my $old_ibx = $cur->[0];
$cur->[0] = $ibx;
if ($old_ibx) {
- $ibx->{unlock_subs} and
- die "BUG: $dir->{unlock_subs} should not exist";
+ my $u = $ibx->{unlock_subs};
$ibx->{unlock_subs} = $old_ibx->{unlock_subs};
$ibx->{unlock_subs} = $old_ibx->{unlock_subs};
+ %{$ibx->{unlock_subs}} = (%$u, %{$ibx->{unlock_subs}}) if $u;
# Linux::Inotify2::Watch::name matches if watches are the
# same, no point in replacing a watch of the same name
# Linux::Inotify2::Watch::name matches if watches are the
# same, no point in replacing a watch of the same name