]> Sergey Matveev's repositories - public-inbox.git/commitdiff
daemon: do more immortal allocations up front
authorEric Wong <e@yhbt.net>
Thu, 19 Mar 2020 08:32:55 +0000 (03:32 -0500)
committerEric Wong <e@yhbt.net>
Fri, 20 Mar 2020 18:24:21 +0000 (18:24 +0000)
Doing immortal allocations late can cause those allocations
to end up in places where it fragments the heap.  So do more
things up front for long-lived daemons.

lib/PublicInbox/NNTPD.pm
lib/PublicInbox/WWW.pm

index 7a917169c70fd8841a3a3fd830b8c6f0e98beb5e..451f4d4183bf52875e5f3e800f269c331ccffa14 100644 (file)
@@ -45,6 +45,10 @@ sub refresh_groups () {
                        # Only valid if msgmap and search works
                        $new->{$ngname} = $ng;
                        push @list, $ng;
                        # Only valid if msgmap and search works
                        $new->{$ngname} = $ng;
                        push @list, $ng;
+
+                       # preload to avoid fragmentation:
+                       $ng->description;
+                       $ng->base_url;
                }
        });
        @list = sort { $a->{newsgroup} cmp $b->{newsgroup} } @list;
                }
        });
        @list = sort { $a->{newsgroup} cmp $b->{newsgroup} } @list;
index 534ee0285c8b6c5294b27b71ec605ed25fc5e828..2434f2f581b2b0fbd1d48d1a08881bf0a1c1187b 100644 (file)
@@ -132,7 +132,9 @@ sub call {
        }
 }
 
        }
 }
 
-# for CoW-friendliness, MOOOOO!
+# for CoW-friendliness, MOOOOO!  Even for single-process setups,
+# we want to get all immortal allocations done early to avoid heap
+# fragmentation since common allocators favor a large contiguous heap.
 sub preload {
        my ($self) = @_;
        require PublicInbox::ExtMsg;
 sub preload {
        my ($self) = @_;
        require PublicInbox::ExtMsg;
@@ -148,18 +150,29 @@ sub preload {
                require PublicInbox::Search;
                PublicInbox::Search::load_xapian();
        };
                require PublicInbox::Search;
                PublicInbox::Search::load_xapian();
        };
-       foreach (qw(PublicInbox::SearchView
-                       PublicInbox::MboxGz
-                       PublicInbox::NewsWWW)) {
+       foreach (qw(PublicInbox::SearchView PublicInbox::MboxGz)) {
                eval "require $_;";
        }
        if (ref($self)) {
                eval "require $_;";
        }
        if (ref($self)) {
+               my $pi_config = $self->{pi_config};
+               if (defined($pi_config->{'publicinbox.cgitrc'})) {
+                       $pi_config->limiter('-cgit');
+               }
                $self->cgit;
                $self->stylesheets_prepare($_) for ('', '../', '../../');
                $self->www_listing;
                $self->cgit;
                $self->stylesheets_prepare($_) for ('', '../', '../../');
                $self->www_listing;
+               $self->news_www;
+               $pi_config->each_inbox(\&preload_inbox);
        }
 }
 
        }
 }
 
+sub preload_inbox {
+       my $ibx = shift;
+       $ibx->cloneurl;
+       $ibx->description;
+       $ibx->base_url;
+}
+
 # private functions below
 
 sub r404 {
 # private functions below
 
 sub r404 {