user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
Search results ordered by [date|relevance]  view[summary|nested|Atom feed]
thread overview below | download mbox.gz: |
* [PATCH 5/6] daemon: do more immortal allocations up front
  2020-03-19  8:32  6% [PATCH 0/6] daemon: reduce fragmentation via preload Eric Wong
@ 2020-03-19  8:32  7% ` Eric Wong
  0 siblings, 0 replies; 2+ results
From: Eric Wong @ 2020-03-19  8:32 UTC (permalink / raw)
  To: meta

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 |  4 ++++
 lib/PublicInbox/WWW.pm   | 21 +++++++++++++++++----
 2 files changed, 21 insertions(+), 4 deletions(-)

diff --git a/lib/PublicInbox/NNTPD.pm b/lib/PublicInbox/NNTPD.pm
index 7a917169..451f4d41 100644
--- a/lib/PublicInbox/NNTPD.pm
+++ b/lib/PublicInbox/NNTPD.pm
@@ -45,6 +45,10 @@ sub refresh_groups () {
 			# 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;
diff --git a/lib/PublicInbox/WWW.pm b/lib/PublicInbox/WWW.pm
index 534ee028..2434f2f5 100644
--- a/lib/PublicInbox/WWW.pm
+++ b/lib/PublicInbox/WWW.pm
@@ -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;
@@ -148,18 +150,29 @@ sub preload {
 		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)) {
+		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->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 {

^ permalink raw reply related	[relevance 7%]

* [PATCH 0/6] daemon: reduce fragmentation via preload
@ 2020-03-19  8:32  6% Eric Wong
  2020-03-19  8:32  7% ` [PATCH 5/6] daemon: do more immortal allocations up front Eric Wong
  0 siblings, 1 reply; 2+ results
From: Eric Wong @ 2020-03-19  8:32 UTC (permalink / raw)
  To: meta

For long-lived daemons, perform immortal allocations as early as
possible to reduce the likelyhood of heap fragmentation due to
mixed-lifetime allocations happening once the process is fully
loaded and serving requests, since per-request allocations
should all be short-lived.

On a side note, I'm wondering if WWW should just preload by
default.  I'm not sure if anybody uses public-inbox.cgi (or
should be using it :P).  It's not like we don't ship
public-inbox-httpd; and any PSGI implementation could be used
for smaller inboxes (or powerful-enough hardware).

Eric Wong (6):
  www: update ->preload for newer modules
  wwwlisting: favor "use" over require
  wwwlisting: avoid lazy loading JSON module
  www: avoid `state' usage to perform allocations up-front
  daemon: do more immortal allocations up front
  viewdiff: favor `qr' to precompile regexps

 lib/PublicInbox/NNTPD.pm      |  4 +++
 lib/PublicInbox/SolverGit.pm  | 13 +++++----
 lib/PublicInbox/ViewDiff.pm   | 53 +++++++++++++++++++----------------
 lib/PublicInbox/WWW.pm        | 29 ++++++++++++++-----
 lib/PublicInbox/WwwListing.pm | 30 +++++++++-----------
 t/www_listing.t               |  4 +--
 6 files changed, 78 insertions(+), 55 deletions(-)

^ permalink raw reply	[relevance 6%]

Results 1-2 of 2 | reverse | options above
-- pct% links below jump to the message on this page, permalinks otherwise --
2020-03-19  8:32  6% [PATCH 0/6] daemon: reduce fragmentation via preload Eric Wong
2020-03-19  8:32  7% ` [PATCH 5/6] daemon: do more immortal allocations up front Eric Wong

Code repositories for project(s) associated with this public inbox

	https://80x24.org/public-inbox.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).