]> git.ipfire.org Git - thirdparty/public-inbox.git/log
thirdparty/public-inbox.git
13 months agoxt/perf-threading: modernize + remove Xapian dependency
Eric Wong [Mon, 10 Jun 2024 11:34:26 +0000 (11:34 +0000)] 
xt/perf-threading: modernize + remove Xapian dependency

Threading hasn't required Xapian (only SQLite) for a while now;
but I'm revisiting this test for another minor optimization.

13 months agogzip_filter: use zlib DEF_MEM_LEVEL for gzip
Eric Wong [Sun, 9 Jun 2024 20:05:23 +0000 (20:05 +0000)] 
gzip_filter: use zlib DEF_MEM_LEVEL for gzip

Compress::Raw::Zlib uses MAX_MEM_LEVEL by default which deviates
fom the zlib default.  Since the zlib default is good enough for
git, nginx and varnish: it's good enough for our use.  This
change reduces maximum zlib memory use by 1/3.

There's also a new note explaining why gzip happens in Perl
instead of varnish || nginx.

13 months agowww: reduce fragmentation in /t/ and /T/ endpoints
Eric Wong [Thu, 6 Jun 2024 07:44:16 +0000 (07:44 +0000)] 
www: reduce fragmentation in /t/ and /T/ endpoints

For giant threads with /t/ and /T/ endpoints, avoid generating a
large string with a medium lifetime for the thread skeleton
($ctx->{skel}).  Instead, make $ctx->{skel} an arrayref and use
it to store a bunch of smaller strings, instead.

While keeping many small strings is inefficient due to pointer
chasing; forcing a smaller distribution of sizes makes it easier
for the malloc implementation to organize and find small chunks
of memory instead of having to find (and hold) larger contiguous
chunks.  When a large string is created now, it's lifetime is
kept as short as possible to decrease its likelyhood of causing
fragmentation.

Preliminary testing shows this appears to reduce RSS by roughly
20-40% under both glibc malloc (using a tiny
MALLOC_MMAP_THRESHOLD_=67000) on 32-bit and jemalloc 5.2.1 on
64-bit with standard settings.

13 months agotreewide: use cached git executable lookup
Eric Wong [Thu, 6 Jun 2024 07:44:15 +0000 (07:44 +0000)] 
treewide: use cached git executable lookup

Repeated stat(2) syscalls are more expensive nowadays due
to CPU vulnerability mitigations and this change also
allows bypassing some heap allocations done by Perl.

13 months agotest_common: use cached git lookup to reduce stat(2)
Eric Wong [Thu, 6 Jun 2024 07:44:14 +0000 (07:44 +0000)] 
test_common: use cached git lookup to reduce stat(2)

This reduces syscalls required to run tests and IMHO improves
readability since we're not having to import `git_exe' everywhere.

13 months agogit: decouple git_version from git_exe
Eric Wong [Thu, 6 Jun 2024 07:44:13 +0000 (07:44 +0000)] 
git: decouple git_version from git_exe

No need to check for the git version number unless we actually
want it.

13 months agotreewide: use \*STD(IN|OUT|ERR) consistently
Eric Wong [Thu, 6 Jun 2024 07:44:12 +0000 (07:44 +0000)] 
treewide: use \*STD(IN|OUT|ERR) consistently

Referencing the {IO} slot may not always be populated or work
(e.g. with `-t' filetest) if there's no IO handle.  Using merely
using `\*' is shorter than typing out `{GLOB}', so just use the
shortest form consistently.

This may fix occasional and difficult-to-reproduce failures from
redirecting STDERR in t/imap_searchqp.t

13 months agosearchview: avoid uninitialized vals in %rmap_inc
Eric Wong [Wed, 5 Jun 2024 20:03:23 +0000 (20:03 +0000)] 
searchview: avoid uninitialized vals in %rmap_inc

Modules (e.g. `PublicInbox::Gcf2') may have an undef value in
the %rmap_inc hash table if an attempt has been made to load it
and failed due to a missing libgit2-dev dependency.  Avoid using
it in interpolation to avoid warnings.

13 months agomda: do not auto-create Xapian indices
Eric Wong [Tue, 4 Jun 2024 22:25:20 +0000 (22:25 +0000)] 
mda: do not auto-create Xapian indices

As with -learn, -mda now detects indexlevel=basic without an
explicit config setting for inboxes which only have SQLite
files.  Omitting indexlevel=basic in the config file allows
users to reduce configuration file size (and RAM usage).

We'll also ensure completely unindexed v1 inboxes can stay
unindexed despite the default being indexlevel=full.

13 months agogit_http_backend: bypass safe.directory restrictions
Eric Wong [Mon, 3 Jun 2024 22:05:53 +0000 (22:05 +0000)] 
git_http_backend: bypass safe.directory restrictions

git.git commit f4aa8c8b (fetch/clone: detect dubious ownership
of local repositories, 2024-04-10) has proven to be overly aggressive
and breaks existing setups where git-http-backend is serving
read-only repositories from reasonably trusted sources and not
running hooks of any sort.

Just mark everything as safe since our public-facing instances
have always assumed writes to all git repos come from a
different user than whatever user -netd/-httpd runs as.

13 months agogit: reduce spawning for rev-parse --git-path
Eric Wong [Thu, 30 May 2024 09:45:15 +0000 (09:45 +0000)] 
git: reduce spawning for rev-parse --git-path

Since every non-worktree git repo has an `objects' directory, we
can quickly stat(2) to check for its presence and avoid an
expensive process spawn.  This should be the common case on
servers since it's rare to use worktrees on servers for
coderepos (or inboxes).

13 months agogit: prefer WNOHANG for `git cat-file --batch-*'
Eric Wong [Thu, 30 May 2024 09:45:14 +0000 (09:45 +0000)] 
git: prefer WNOHANG for `git cat-file --batch-*'

When inside our DS event loop, ensure we don't stall on
synchronous waitpid when stopping `--batch-*' processes.
Instead of calling PublicInbox::IO::close explicitly, let
refcounting close the socket via PublicInbox::IO::DESTROY and
the SIGCHLD handler will deal with it when the kernel and event
loop get to it.

13 months agogcf2: eliminate unnecessary autodie::close import
Eric Wong [Thu, 30 May 2024 09:45:13 +0000 (09:45 +0000)] 
gcf2: eliminate unnecessary autodie::close import

We no longer call close() in Gcf2.  I noticed this since I plan
on eliminating some needless ->close calls in PublicInbox::Git.

13 months agosearch: forbid getopt(3) switch injection in query
Eric Wong [Tue, 28 May 2024 21:25:02 +0000 (21:25 +0000)] 
search: forbid getopt(3) switch injection in query

Search queries may start with `-', confusing getopt(3) and
Getopt::Long; so we use `--' to separate the query string
from switches.

Consequences of this bug were limited to a single broken HTTP
response for the requesting client.

It didn't didn't allow writes to on-disk Xapian DBs, but caused
aborts on some searches or nonsensical results when using the
optional external xap_helper processes.  There was no risk of
data leaks since the mset xap_helper endpoint only returns
document IDs (unsigned integers), and not terms.

The biggest danger from this bug was that it could run systems
out of space if they are configured to write out core dumps.

14 months agowww_coderepo: improve handling of broken repos
Eric Wong [Fri, 24 May 2024 00:56:38 +0000 (00:56 +0000)] 
www_coderepo: improve handling of broken repos

The {readme} arrayref may be completely unset if a repo goes
missing, so account for that when the summary page runs.

14 months agogit: don't break from event loop if cat-file fails
Eric Wong [Fri, 24 May 2024 00:56:37 +0000 (00:56 +0000)] 
git: don't break from event loop if cat-file fails

`git cat-file' can OOM or fail by other means.  Don't let it
bring down the event loop with an uncaught exception.

14 months agot/lei-tag: allow changing time for --commit-delay test
Eric Wong [Tue, 21 May 2024 07:14:23 +0000 (07:14 +0000)] 
t/lei-tag: allow changing time for --commit-delay test

Sometimes `lei ls-label' can run slowly enough that the
previously-scheduled delayed commit happens by the time it runs.
So support tuning the delay and add a helpful message to someone
analyzing failures on slow/overloaded machines.

14 months agoxap_helper.h: fix CPP error on non-glibc
Eric Wong [Mon, 20 May 2024 18:59:24 +0000 (18:59 +0000)] 
xap_helper.h: fix CPP error on non-glibc

Noticed on a FreeBSD system.

14 months agowww_text: fix /$INBOX/_/text/help/raw endpoint
Eric Wong [Sun, 19 May 2024 21:55:09 +0000 (21:55 +0000)] 
www_text: fix /$INBOX/_/text/help/raw endpoint

It wasn't ever documented, but since config/raw exists, it makes
sense for help/raw to exist, too.

14 months agolei_saved_search: drop ->altid_map method
Eric Wong [Sun, 19 May 2024 21:55:08 +0000 (21:55 +0000)] 
lei_saved_search: drop ->altid_map method

->altid_map is not currently used by lei.  The only caller is
WwwText which should only see public inboxes, not lei storage.

14 months agoxap_helper: drop DB handles on EMFILE/ENFILE/etc...
Eric Wong [Sun, 19 May 2024 21:55:07 +0000 (21:55 +0000)] 
xap_helper: drop DB handles on EMFILE/ENFILE/etc...

This allows the process to recover in case we get the SHARD_COST
calculation wrong in case Xapian uses more FDs than expected in
new versions.  We'll no longer attempt to recover from ENOMEM
and similar errors during Xapian DB initialization and instead
just tear down the process (as we do in other places).

14 months agoxap_helper: expire DB handles when FD table is near full
Eric Wong [Sun, 19 May 2024 21:55:06 +0000 (21:55 +0000)] 
xap_helper: expire DB handles when FD table is near full

For long-lived daemons across config reloads, we shouldn't keep
Xapian DBs open forever under FD pressure.  So estimate the
number of FDs we need per-shard and start clearing some out
if we have too many open.

While we're at it, hoist out our ulimit_n helper and share it
across extindex and the Perl XapHelper implementation.

14 months agoxap_helper.h: memoize Xapian handles with khashl
Eric Wong [Sun, 19 May 2024 21:55:05 +0000 (21:55 +0000)] 
xap_helper.h: memoize Xapian handles with khashl

Since we're already using khashl in the C++ implementation,
get rid of tsearch(3) and friends as well.  Relying on hash
tables in both the Perl and C(++) implementation reduces
cognitive load for hackers.

14 months agoxap_helper.h: use xcalloc to simplify error checking
Eric Wong [Sun, 19 May 2024 21:55:04 +0000 (21:55 +0000)] 
xap_helper.h: use xcalloc to simplify error checking

Since we introduced xcalloc for khashl.h usage, we might as well
use it elsewhere.

14 months agoxap_helper.h: use khashl.h instead of hsearch(3)
Eric Wong [Sun, 19 May 2024 21:55:03 +0000 (21:55 +0000)] 
xap_helper.h: use khashl.h instead of hsearch(3)

hsearch(3) and friends are just too horrid of APIs and subject
to fatal problems due to system-dependent ENTRY.key use of
strdup(3).  So replace it with khashl (which is a newer, smaller
version of the widely-used khash in git.git).

We'll also be able to use khashl in the future for
the FUSE shim if liburcu isn't available.

14 months agoxap_helper: key search instances by -Q params, too
Eric Wong [Sun, 19 May 2024 21:55:02 +0000 (21:55 +0000)] 
xap_helper: key search instances by -Q params, too

In addition to the shards which comprise the xap_helper search
instance, we also account for changes in altid and indexheader
in case xap_helper lifetime exceeds the given
PublicInbox::Config.

xap_helper will be Config lifetime agnostic since it's possible
to run -netd and -httpd instances with multiple Config files,
but a single xap_helper instance (with workers) should be able
to service all of them.

14 months agoconfig: dedupe ibx->{newsgroup}
Eric Wong [Sun, 19 May 2024 21:55:01 +0000 (21:55 +0000)] 
config: dedupe ibx->{newsgroup}

We definitely use newsgroup names as hash keys, so get rid
of the duplicate value for some memory savings when we have
hundreds or thousands of newsgroups.

14 months agodoc: limit jemalloc recommendation to 64-bit systems
Eric Wong [Tue, 14 May 2024 06:38:06 +0000 (06:38 +0000)] 
doc: limit jemalloc recommendation to 64-bit systems

My 32-bit server seems less happy with jemalloc; likely since
munmap is creating holes and it's not using sbrk by default.
jemalloc seems to need large VM space (not actual memory)
to work well, and that isn't a possibility for constrained
32-bit systems.

14 months agosolver: eliminate a few more git path lookups
Eric Wong [Sat, 11 May 2024 23:29:41 +0000 (23:29 +0000)] 
solver: eliminate a few more git path lookups

This eliminates a few more stat syscalls and malloc+free sequences.

14 months agosolver: quiet complex regexp warning for old Perl
Eric Wong [Sat, 11 May 2024 23:29:40 +0000 (23:29 +0000)] 
solver: quiet complex regexp warning for old Perl

I'm not sure when the actual recursion limit was removed,
but the warning was removed for Perl 5.37.1.  In any case,
it's probably not worth doing anything about for older Perls
it since it's rarely triggered and it seems nobody cares too
much about solver, anyways :<

14 months agotreewide: reduce $PATH checks for `git' executable
Eric Wong [Thu, 9 May 2024 00:39:01 +0000 (00:39 +0000)] 
treewide: reduce $PATH checks for `git' executable

Repeatedly checking $PATH for `git' when we need to call it
multiple times in quick succession doesn't seem useful.  So
avoid some expensive stat(2) syscalls to make things less bad
for systems which require expensive CPU vulnerability
mitigations.

This also saves a bunch of memory allocations since we do the
$PATH lookup in pure Perl to avoid doing the uncacheable lookup
in a vfork-ed child.

14 months agoxap_helper: unconditionally reopen DBs on reuse
Eric Wong [Tue, 7 May 2024 19:14:27 +0000 (19:14 +0000)] 
xap_helper: unconditionally reopen DBs on reuse

Reopening Xapian DBs is a fairly cheap operation and Xapian
avoids doing work when nothing's changed, so just do it
to ensure we always get the latest updates in search results.

The old synchronous search interface worked around this by
having a timer based expiration in hopes of mitigating
fragmentation problems, but perhaps that's not worth doing
anymore now that memory fragmentation from Perl itself is
better understood.

14 months agosearchidx: fix Xapian version comparison
Eric Wong [Mon, 6 May 2024 23:19:53 +0000 (23:19 +0000)] 
searchidx: fix Xapian version comparison

We must use Perl v-strings consistently on both sides of the
comparison.  Fortunately, this was merely a no-op and didn't
cause any data integrity problems (aside from increased wear on
the storage device).

Fixes: c25c66af0a8a (searchidx: use vstring to improve readability, 2023-04-07)
14 months agosearch: fix altid search with XapHelper process
Eric Wong [Sun, 5 May 2024 23:35:10 +0000 (23:35 +0000)] 
search: fix altid search with XapHelper process

External Xapian helper processes need to support non-standard
QueryParser prefixes.  The only way to do this is to specify
these prefixes in every `mset' request since we have no idea
if the XH worker servicing the request has initialized the
extra prefixes, yet.

14 months agoextindex: support --no-multi-pack-index
Eric Wong [Sun, 28 Apr 2024 21:15:24 +0000 (21:15 +0000)] 
extindex: support --no-multi-pack-index

git multi-pack-index files were creating swap storms and OOM-ing
on my system; so providing an option to disable it seems prudent
given the minor startup time regression.

14 months agot/imap_searchqp: hopefully fix test reliability
Eric Wong [Sun, 28 Apr 2024 20:08:01 +0000 (20:08 +0000)] 
t/imap_searchqp: hopefully fix test reliability

Localizing assignments to *STDERR doesn't seem to always work
with scalar (String) IO objects.  Fortunately, doing actual dup2
redirects always seems reliable, so do that instead of
attempting to understand why PerlIO sometimes fails with the
assignment.

14 months agoxap_helper: implement alarm(2)-based timeout
Eric Wong [Fri, 26 Apr 2024 11:29:44 +0000 (11:29 +0000)] 
xap_helper: implement alarm(2)-based timeout

alarm(2) delivering SIGALRM seems sufficient for Xapian since
Xapian doesn't block signals (which would necessitate the use of
SIGKILL via RLIMIT_CPU hard limit).  When Xapian gets stuck in
`D' state on slow storage, SIGKILL would not make a difference,
either (at least not on Linux).

Relying on RLIMIT_CPU is also trickier since we must account for
CPU time already consumed by a process for unrelated requests.
Thus we just rely on a simple alarm-based timeout.  This also
avoids requiring the optional BSD::Resource module in the (mostly)
Perl implementation (and avoids potential bugs given my meager
arithmetic skills).

14 months agoxap_helper: reopen logs in daemons
Eric Wong [Fri, 26 Apr 2024 11:29:43 +0000 (11:29 +0000)] 
xap_helper: reopen logs in daemons

When read-only daemons reopen log files via SIGUSR1, be sure to
propagate it to Xapian helper processes to ensure old log files
can be closed and archived.

14 months agosearch: remove auto-start for async_mset
Eric Wong [Fri, 26 Apr 2024 11:29:42 +0000 (11:29 +0000)] 
search: remove auto-start for async_mset

Only public-facing daemons use it, currently, and all
public-facing daemons will pre-spawn it as early as feasible.
lei will need it eventually to handle queries requiring C++,
but I'm not certain what path to take with lei, yet...

14 months agotest_common: don't needlessly rebuild C++ Xapian helper
Eric Wong [Fri, 26 Apr 2024 11:29:41 +0000 (11:29 +0000)] 
test_common: don't needlessly rebuild C++ Xapian helper

We should almost always be calling `check_build' instead of
`build'.  Using ccache masked some of the overhead from
this, but various linker implementations are still slow.

14 months agodaemon: share and allow configuring Xapian helpers
Eric Wong [Thu, 25 Apr 2024 21:31:46 +0000 (21:31 +0000)] 
daemon: share and allow configuring Xapian helpers

Xapian helper processes are disabled by default once again.
However, they can be enabled via the new `-X INTEGER' parameter.
One big positive is the Xapian helpers being spawned by the
top-level daemon means they can be shared freely across all
workers for improved load balancing and memory reduction.

14 months agosearch: async_mset: pass resource errors to callback
Eric Wong [Thu, 25 Apr 2024 21:31:45 +0000 (21:31 +0000)] 
search: async_mset: pass resource errors to callback

We need to be able to handle resource limitation errors in
public-facing daemons.

14 months agosend_cmd4: make `tries' a per-call parameter
Eric Wong [Thu, 25 Apr 2024 21:31:44 +0000 (21:31 +0000)] 
send_cmd4: make `tries' a per-call parameter

While existing callers are private (lei, *-index, -watch) are
private, we should not be blocking the event loop in
public-facing servers when we hit ETOOMANYREFS, ENOMEM, or
ENOBUFS.

14 months agowww: mbox*: use Perl 5.12
Eric Wong [Thu, 25 Apr 2024 21:31:43 +0000 (21:31 +0000)] 
www: mbox*: use Perl 5.12

We were already silently relying on v5.10 features (`//') and
all the regexps to work correctly with v5.12 unicode_strings.

14 months agot/cindex: require DBD::SQLite for now
Eric Wong [Thu, 25 Apr 2024 21:31:42 +0000 (21:31 +0000)] 
t/cindex: require DBD::SQLite for now

Technically it's not required, but -compact blindly requires
DBD::SQLite at the moment since it was designed for inboxes in
mind.  Furthermore, cindex isn't useful at the moment without
inboxes to associate with, and inboxes can't be indexed without
SQLite.

15 months agoxap_helper: PERL_INLINE_DIRECTORY fallback for JAOT build
Eric Wong [Wed, 24 Apr 2024 09:39:36 +0000 (09:39 +0000)] 
xap_helper: PERL_INLINE_DIRECTORY fallback for JAOT build

systemd setups may use role accounts (e.g. `news') with
XDG_CACHE_HOME unset and a non-existent HOME directory
which the user has no permission to create.

In those cases, fallback to using PERL_INLINE_DIRECTORY if
available for building the just-ahead-of-time C++ binary.

15 months agowww: wire up search to use async xap_helper
Eric Wong [Wed, 24 Apr 2024 06:44:47 +0000 (06:44 +0000)] 
www: wire up search to use async xap_helper

The C++ version of xap_helper will allow more complex and
expensive queries.  Both the Perl and C++-only version will
allow offloading search into a separate process which can be
killed via ITIMER_REAL or RLIMIT_CPU in the face of overload.

The xap_helper `mset' command wrapper is simplified to
unconditionally return rank, percentage, and estimated matches
information.  This may slightly penalize mbox retrievals and
lei users, but perhaps that can be a different command entirely.

15 months agombox: hoist out refill_result_ids
Eric Wong [Wed, 24 Apr 2024 06:44:46 +0000 (06:44 +0000)] 
mbox: hoist out refill_result_ids

This makes upcoming changes easier to understand.

15 months agoxap_helper: drop terms+data from `mset' command
Eric Wong [Wed, 24 Apr 2024 06:44:45 +0000 (06:44 +0000)] 
xap_helper: drop terms+data from `mset' command

Retrieving Xapian document terms, data (and possibly values) and
transferring to the Perl side would be an increase in complexity
and I/O both the Perl and C++ sides.  It would require more I/O
in C++ and transient memory use on the Perl side where slow mset
iteration gives an opportunity to dictate memory release rate.

So lets ignore the document-related stuff here for now for
ease-of-development.  We can reconsider this change if dropping
Xapian Perl bindings entirely and relying on JAOT C++ ever
becomes a possibility.

15 months agoxap_helper.h: remove _SC_NPROCESSORS_ONLN default
Eric Wong [Wed, 24 Apr 2024 06:44:44 +0000 (06:44 +0000)] 
xap_helper.h: remove _SC_NPROCESSORS_ONLN default

It's never straightforward to pick an ideal number of processes
for anything and Xapian helper processes are no exception since
there may be a massive disparities in CPU count and I/O
performance.  So default to a single worker for now in the C++
version since that's the default is for the Perl/(XS|SWIG)
version, and also the same as for our normal public-facing
daemons.

This keeps the behavior between the Perl+(XS|SWIG) and C++
version as similar as possible.

15 months agosearchview: get rid of unused adump callback arg
Eric Wong [Wed, 24 Apr 2024 06:44:43 +0000 (06:44 +0000)] 
searchview: get rid of unused adump callback arg

It hasn't been used since 2016 when we started working on
improved streamability of gigantic responses.

Fixes: 95d4bf7aded4 (atom: switch to getline/close for response bodies, 2016-12-03)
15 months agodoc: strongly recommend MALLOC_MMAP_THRESHOLD_=131072 for glibc
Eric Wong [Thu, 18 Apr 2024 19:46:16 +0000 (19:46 +0000)] 
doc: strongly recommend MALLOC_MMAP_THRESHOLD_=131072 for glibc

The 131072 byte lower bound was the old default before the
sliding mmap window was introduced in modern glibc malloc.
While the sliding mmap window was intended to be faster by
reducing syscalls, zeroing and kernel overhead, it is also prone
to fragmentation from allocation patterns seen in evented Perl
servers.

Individual allocations over 128K are rare in our codebase since
there aren't many messages this large, making any performance
impact tiny.  Furthermore, the reduction in fragmentation and
memory use will be a speedup for memory-constrained systems
since they can avoid swap and have more leftover for the page
cache.

15 months agolei: use async barrier for --import-before
Eric Wong [Tue, 16 Apr 2024 20:56:29 +0000 (20:56 +0000)] 
lei: use async barrier for --import-before

Write barriers can take a long time to finish, especially when
commands are issues in parallel.  So handle it asynchronously
without blocking lei-daemon by making EOFpipe a little more
flexible by supporting arguments to the callback function.

This is another step towards improving parallel use of lei.

15 months agolei/store: stop shard workers + cat-file on idle
Eric Wong [Tue, 16 Apr 2024 20:56:28 +0000 (20:56 +0000)] 
lei/store: stop shard workers + cat-file on idle

Schedule a timer to stop shard workers and the git-cat-file
process after a `barrier' command.  This allows us to save some
memory again when the lei-daemon is idle but preserves the fork
overhead reduction when issuing many commands in parallel or in
quick succession.

15 months agolei: use ->barrier to commit to lei/store
Eric Wong [Tue, 16 Apr 2024 20:56:27 +0000 (20:56 +0000)] 
lei: use ->barrier to commit to lei/store

barrier (synchronous checkpoint) is better than ->done with
parallel lei commands being issued (via '&' or different
terminals), since repeatedly stopping and restarting processes
doesn't play nicely with expensive tasks like `lei reindex'.

This introduces a slight regression in maintaining more
processes (and thus resource use) when lei is idle, but that'll
be fixed in the next commit.

15 months agov2 + lei/store: always wait for fast-import checkpoint
Eric Wong [Tue, 16 Apr 2024 20:56:26 +0000 (20:56 +0000)] 
v2 + lei/store: always wait for fast-import checkpoint

Since data going to git is the most important, always ensure
data is written to git before attempting to write anything to
SQLite or Xapian.

15 months agodoc: note MALLOC_MMAP_THRESHOLD_ as a potential workaround
Eric Wong [Mon, 15 Apr 2024 19:50:56 +0000 (19:50 +0000)] 
doc: note MALLOC_MMAP_THRESHOLD_ as a potential workaround

Large string processing + concurrency + caching/memoization
really brings out the worst in glibc malloc :<

15 months agolei: remove leftover debugging message
Eric Wong [Fri, 12 Apr 2024 18:04:14 +0000 (18:04 +0000)] 
lei: remove leftover debugging message

Noticed while working on other things...

Fixes: 299aac294ec3 (lei: do label/keyword parsing in optparse, 2023-10-02)
15 months agoio: avoid redundant waitpid in DESTROY
Eric Wong [Fri, 12 Apr 2024 18:04:13 +0000 (18:04 +0000)] 
io: avoid redundant waitpid in DESTROY

We shouldn't attempt to reap a process again after it's been
reaped asynchronously in the SIGCHLD handler.  Noticed while
working on changes to get lei/store to use checkpointing.

15 months agolei_remote: solver supports uncommitted blobs
Eric Wong [Fri, 12 Apr 2024 18:04:12 +0000 (18:04 +0000)] 
lei_remote: solver supports uncommitted blobs

This should improve `lei blob' and `lei rediff' functionality
for folks relying on `lei index' and allows future work to
improve parallelism via checkpointing in lei/store.

15 months agodoc: mknews: fix warnings when generating NEWS.html
Eric Wong [Fri, 12 Apr 2024 06:59:04 +0000 (06:59 +0000)] 
doc: mknews: fix warnings when generating NEWS.html

We need these values in the PSGI $env to generate the cache key,
even if we're not linkifying anything.

Fixes: 48cbe0c3 (www: linkify inbox addresses in To/Cc headers, 2024-01-09)
15 months agolei q: support --thread-id=$MSGID || -T $MSGID
Eric Wong [Fri, 12 Apr 2024 02:01:03 +0000 (02:01 +0000)] 
lei q: support --thread-id=$MSGID || -T $MSGID

This adds support for the "POST /$INBOX/$MSGID/?x=m?q=..."
added last year to support per-thread searches
764035c83 (www: support POST /$INBOX/$MSGID/?x=m&q=, 2023-03-30)
This only supports instances of public-inbox since 764035c83,
but unfortunately there hasn't been a release since then.

15 months agolei blob: fix attachment extraction for unimported||inflight
Eric Wong [Thu, 11 Apr 2024 18:58:26 +0000 (18:58 +0000)] 
lei blob: fix attachment extraction for unimported||inflight

Noticed while trying to make other reliability improvements to
lei...

15 months agowww: speed up global manifest.js.gz w/ "all" extindex
Eric Wong [Mon, 8 Apr 2024 09:49:21 +0000 (09:49 +0000)] 
www: speed up global manifest.js.gz w/ "all" extindex

By reducing internal event loop iterations, this brings 300+
inboxes down ~32ms to ~27ms.  It should also be more consistent
on servers with busy event loops since all the Xapian DB traffic
happens at once, theoretically mproving cache utilization.

15 months agosyscall: set default constants for Inline::C platforms
Eric Wong [Mon, 8 Apr 2024 09:48:43 +0000 (09:48 +0000)] 
syscall: set default constants for Inline::C platforms

This fixes compile errors on platforms we can't explicitly
support from pure Perl due to the lack of syscall stability
guarantees by the OS developers.

Reported-by: Gaelan Steele <gbs@canishe.com>
Tested-by: Gaelan Steele <gbs@canishe.com>
15 months agotreewide: avoid getpid for more ownership checks
Eric Wong [Mon, 1 Apr 2024 06:49:38 +0000 (06:49 +0000)] 
treewide: avoid getpid for more ownership checks

There are still some places where on_destroy isn't suitable,
This gets rid of getpid() calls in most of those cases to
reduce syscall costs and cleanup syscall trace output.

15 months agotreewide: avoid getpid() for OnDestroy checks
Eric Wong [Mon, 1 Apr 2024 06:49:37 +0000 (06:49 +0000)] 
treewide: avoid getpid() for OnDestroy checks

getpid() isn't cached by glibc nowadays and system calls are
more expensive due to CPU vulnerability mitigations.  To
ensure we switch to the new semantics properly, introduce
a new `on_destroy' function to simplify callers.
Furthermore, most OnDestroy correctness is often tied to the
process which creates it, so make the new API default to
guarded against running in subprocesses.

For cases which require running in all children, a new
PublicInbox::OnDestroy::all call is provided.

15 months agolock: get rid of PID guard
Eric Wong [Mon, 1 Apr 2024 06:49:36 +0000 (06:49 +0000)] 
lock: get rid of PID guard

PID guards for OnDestroy will be the default in an upcoming
change.  In the meantime, LeiMirror was the only user and
didn't actually need it.

16 months agoINSTALL: try to be less confusing about optional modules
Štěpán Němec [Sat, 16 Mar 2024 22:37:18 +0000 (23:37 +0100)] 
INSTALL: try to be less confusing about optional modules

16 months agoFix some typos and language nits in docs and comments
Štěpán Němec [Fri, 15 Mar 2024 14:30:48 +0000 (15:30 +0100)] 
Fix some typos and language nits in docs and comments

16 months agodoc: update release notes, marketing, and install
Eric Wong [Wed, 13 Mar 2024 21:02:11 +0000 (21:02 +0000)] 
doc: update release notes, marketing, and install

INSTALL now covers more of lei since I'm less uncomfortable
about it for 2.0 and points users towards the install/ helpers
if installing from source.

16 months agocodesearch: deduplicate $git->{nick} field
Eric Wong [Mon, 11 Mar 2024 19:40:12 +0000 (19:40 +0000)] 
codesearch: deduplicate $git->{nick} field

While PublicInbox::Config is responsible for some instances of
setting $git->{nick}, more PublicInbox::Git objects may be
created from loading the cindex and we should do our best to
reuse that memory, too.

Followup-to: 84ed7ec1c887 (dedupe inbox names, coderepo nicks + git dirs, 2024-03-04)
16 months agodoc: tuning: note reduced fragmentation w/ jemalloc
Eric Wong [Mon, 11 Mar 2024 19:40:11 +0000 (19:40 +0000)] 
doc: tuning: note reduced fragmentation w/ jemalloc

I may be mistaken, but I suspect the reason jemalloc handles
long-lived processes better than glibc is due to granularity
reduction being scaled to larger size classes.  This can waste
20% of an individual allocation, but increases the likelyhood
of reuse (without splitting/consolidating into other sizes).

In other words, glibc seems to try too hard to make the best fit
for initial allocations.  This ends up being suboptimal over
time as those allocations are freed and similar (but not
identical) allocations come in.  jemalloc sacrifices the best
initial fit for better fits over a long process lifetime.

16 months agocodesearch: deduplicate {ibx_score} name pairs
Eric Wong [Mon, 11 Mar 2024 19:40:10 +0000 (19:40 +0000)] 
codesearch: deduplicate {ibx_score} name pairs

With my current mirror of lore + gko, this saves over 300K
allocations and brings the allocation count in this area down
to under 5K.  The reduction in AV refs saves around 45MB RAM
according to measurements done live via Devel::Mwrap.

16 months agowww: use a dedicated limiter for blob solver
Eric Wong [Mon, 11 Mar 2024 19:40:09 +0000 (19:40 +0000)] 
www: use a dedicated limiter for blob solver

Wrap the entire solver command chain with a dedicated limiter.
The normal limiter is designed for longer-lived commands or ones
which serve a single HTTP request (e.g. git-http-backend or
cgit) and not effective for short memory + CPU intensive commands
used for solver.

Each overall solver request is both memory + CPU intensive: it
spawns several short-lived git processes(*) in addition to a
longer-lived `git cat-file --batch' process.

Thus running parallel solvers from a single -netd/-httpd worker
(which have their own parallelization) results in excessive
parallelism that is both memory and CPU-bound (not network-bound)
and cascade into slowdowns for handling simpler memory/CPU-bound
requests.  Parallel solvers were also responsible for the
increased lifetime and frequency of zombies since the event loop
was too saturated to reap them.

We'll also return 503 on excessive solver queueing, since these
require an FD for the client HTTP(S) socket to be held onto.

(*) git (update-index|apply|ls-files) are all run by solver and
    short-lived

16 months agolistener: don't loop on errors
Eric Wong [Mon, 11 Mar 2024 10:06:15 +0000 (10:06 +0000)] 
listener: don't loop on errors

Fortunately, this only affects `--multi-accept=' users, with
`--multi-accept=-1' users getting infinite loops.

I noticed this when EMFILE was reached on my setup, but any
error should cause us to give up accept(2) (at least
temporarily) and allow work for other items in the event loop to
be processed.

16 months agoimport: fix handling of init.defaultBranch
Eric Wong [Sun, 10 Mar 2024 21:41:30 +0000 (21:41 +0000)] 
import: fix handling of init.defaultBranch

We must chomp the newline in the branch name if it's set.

Reported-by: Rob Herring <robh@kernel.org>
Link: https://public-inbox.org/meta/CAL_JsqK7P4gjLPyvzxNEcYmxT4j6Ah5f3Pz1RqDHxmysTg3aEg@mail.gmail.com/
Fixes: 73830410e4336b77 (treewide: use run_qx where appropriate, 2023-10-27)
16 months agoimport: croak (instead of die) on write failures
Eric Wong [Fri, 8 Mar 2024 21:05:04 +0000 (21:05 +0000)] 
import: croak (instead of die) on write failures

This allows accurate reporting of the error location and can be
made to dump a Perl backtrace via PERL5OPT='-MCarp=verbose'.
Noticed while tracking down fast-import failures.

Link: https://public-inbox.org/meta/CAL_JsqK7P4gjLPyvzxNEcYmxT4j6Ah5f3Pz1RqDHxmysTg3aEg@mail.gmail.com/
16 months agolei: prevent empty {bytes} field in saved search
Eric Wong [Fri, 8 Mar 2024 21:05:03 +0000 (21:05 +0000)] 
lei: prevent empty {bytes} field in saved search

Noticed while tracking down fast-import crash bug report.

Link: https://public-inbox.org/meta/CAL_JsqK7P4gjLPyvzxNEcYmxT4j6Ah5f3Pz1RqDHxmysTg3aEg@mail.gmail.com/
16 months agodedupe inbox names, coderepo nicks + git dirs
Eric Wong [Mon, 4 Mar 2024 21:10:46 +0000 (21:10 +0000)] 
dedupe inbox names, coderepo nicks + git dirs

Inbox names, coderepo nicks, git_dir values are used heavily
as hash keys by the read-only coderepo WWW pieces.

Relying on CoW for mutable scalars on newer Perl doesn't work
well since CoW for those scalars are limited to 256 CoW references
and blow past that number when mapping thousands of coderepos
and inboxes to each other.  Instead, make the hash key up-front
and get the resulting string to point directly to the pointer
used by the hash key.

17 months agoeml: reuse ->decode buffer
Eric Wong [Tue, 13 Feb 2024 09:42:42 +0000 (09:42 +0000)] 
eml: reuse ->decode buffer

It's not really relevant at the moment, but a sufficiently
smart implementation could eventually save some memory here.
Perl already optimizes in-place sort (@x = sort @x), so there's
precedent for a potential future where a Perl implementation
could generally optimize in-place operations for non-builtin
subroutines, too.

17 months agoeml: avoid anonymous __WARN__ sub for encode/decode
Eric Wong [Tue, 13 Feb 2024 09:42:41 +0000 (09:42 +0000)] 
eml: avoid anonymous __WARN__ sub for encode/decode

Repeatedly allocating an anonymous sub is an expensive operation
and a potential source of leaks in older Perl.  Instead,
`local'-ize a global and use a permanent sub to workaround the
old Encode 2.87..3.12 leak.

17 months agocodesearch: generate_cxx: drop unused variables
Eric Wong [Mon, 12 Feb 2024 21:28:04 +0000 (21:28 +0000)] 
codesearch: generate_cxx: drop unused variables

We are just using the odd ref+deref (`${\...}') syntax and
don't need to calculate line numbers ourselves, nowadays.

17 months agoxap_helper_cxx: -O2 optimize read-only files by default
Eric Wong [Mon, 12 Feb 2024 21:28:03 +0000 (21:28 +0000)] 
xap_helper_cxx: -O2 optimize read-only files by default

While fast build times from -O0 is critical to my sanity when
actively working on C++, the files installed via package
managers or `make install' aren't likely to change frequently.

In that case, expensive -O2 optimizations make sense since the
10-20s saved from a single large --join more than covers the
cost of waiting on g++ to optimize.

17 months agodoc: fix formatting for CLI switch aliases
Eric Wong [Tue, 13 Feb 2024 09:31:29 +0000 (09:31 +0000)] 
doc: fix formatting for CLI switch aliases

`=item' elements in Pod need to be surrounded by empty lines.
It's an unfortunate waste of vertical space, but Pod is still better
than *roff and usually available out-of-the-box.

17 months agodoc: config: cgit=rewrite isn't implemented, yet
Eric Wong [Tue, 13 Feb 2024 09:31:28 +0000 (09:31 +0000)] 
doc: config: cgit=rewrite isn't implemented, yet

It'll probably be done for another release, I doubt most cgit
users are willing to completely replace it with our coderepo
viewer just yet...

17 months agowww: cgit: support non-standard cgitrc locations
Eric Wong [Tue, 13 Feb 2024 09:31:27 +0000 (09:31 +0000)] 
www: cgit: support non-standard cgitrc locations

If publicinbox.cgitrc is set in the config file, we'll ensure
cgit sees it as CGIT_CONFIG since the configured
publicinbox.cgitrc knob may not be the default path the cgit.cgi
binary was configured to use.

Furthermore, we'll respect CGIT_CONFIG in the environment if
publicinbox.cgitrc is unset in the config file at -httpd/-netd
startup.

17 months agoviewvcs: HTML fixes for commits
Eric Wong [Mon, 12 Feb 2024 13:13:50 +0000 (13:13 +0000)] 
viewvcs: HTML fixes for commits

The "patch is too large to show" text is now broken by an <hr>
to prevent it from being confused as part of a commit message
(or having somebody intentionally insert that text in a commit
message to confuse readers).  A missing </pre> is also necessary
before the <hr> tag for the related commit search form.

17 months agoviewvcs: parallelize commit display
Eric Wong [Mon, 12 Feb 2024 13:13:49 +0000 (13:13 +0000)] 
viewvcs: parallelize commit display

Similar to commit cbe2548c91859dfb923548ea85d8531b90d53dc3
(www_coderepo: use OnDestroy to render summary view,
2023-04-09), we can rely on OnDestroy and Qspawn to run
dependencies in a structured way and with some extra parallelism
for SMP users.

Perl (as opposed to POSIX sh) allows us to easily avoid
expensive patch generation for large root commits, and also avoid
needless `git patch-id' invocations for patches which are too
big to show.

Avoiding patch-id alone saved nearly 2s from the linux.git root
commit[1] with patch generation enabled and brought response
times down to ~6s (still slow).  Avoiding patch generation for
root commits brings it down to a few hundred milliseconds on a
public-facing server (nobody wants a 355MB patch rendered as
HTML, right?).

[1] torvalds/linux.git 1da177e4c3f41524e886b7f1b8a0c1fc7321cac2

17 months agowww: quiet errors for git-{archive,http-backend}
Eric Wong [Fri, 9 Feb 2024 17:37:05 +0000 (17:37 +0000)] 
www: quiet errors for git-{archive,http-backend}

SIGPIPE (13) can be quite common with unreliable connections
and impatient clients, so just ignore them.

17 months agoview: decode In-Reply-To comments added by some MUAs
Eric Wong [Fri, 9 Feb 2024 09:33:01 +0000 (09:33 +0000)] 
view: decode In-Reply-To comments added by some MUAs

Štěpán Němec <stepnem@smrk.net> wrote:
> Eric Wong wrote:
> > Subject: [PATCH] view: decode In-Reply-To comments added by Gnus

> Or just "some MUAs"?  Who knows who else...

Yeah, I wouldn't be surprised if there were more...

---8<---
Subject: [PATCH] view: decode In-Reply-To comments added by some MUAs

Emacs-based MUAs (e.g. Gnus and rmail) can do it, and maybe
some others, too.  I noticed it in
<https://yhbt.net/lore/git/xmqqr0ho9oi9.fsf@gitster.g/>
while scanning for something else.

17 months agodaemon: quiet Email::Address::XS warnings properly
Eric Wong [Wed, 7 Feb 2024 22:49:19 +0000 (22:49 +0000)] 
daemon: quiet Email::Address::XS warnings properly

Setting $SIG{__WARN__} at the top-level no longer has any effect
since we localize $SIG{__WARN__} when entering ->event_step on
a per-listener basis.

Fixes: 60d262483a4d (daemon: use per-listener SIG{__WARN__} callbacks, 2022-08-08)
17 months agopop3d: support fcntl locks on OpenBSD i386
Eric Wong [Thu, 1 Feb 2024 20:59:48 +0000 (20:59 +0000)] 
pop3d: support fcntl locks on OpenBSD i386

The packaged Perl on OpenBSD i386 supports 64-bit file offsets
but not 64-bit integer support for 'q' and 'Q' with `pack'.
Since servers aren't likely to require lock files larger than
2 GB (we'd need an inbox with >2 billion messages), we can
workaround the Perl build limitation with explicit padding.

File::FcntlLock isn't packaged for OpenBSD <= 7.4 (but should be
in future releases), but I can test i386 OpenBSD on an extremely
slow VM.

Big endian support can be done, too, but I have no idea if
there's 32-bit BE users around nowadays...

17 months agolei: sort MH inputs sequentially by default
Eric Wong [Wed, 31 Jan 2024 10:20:20 +0000 (10:20 +0000)] 
lei: sort MH inputs sequentially by default

MH sequence numbers can be analogous to IMAP UIDs and NNTP
article numbers (or more like IMAP MSNs with clients which
pack).  In any case, sort then numerically by default to avoid
surprising users who treat NNTP spools and mlmmj archives as MH
folders.  This gives more coherent git history and resulting
NNTP/IMAP numbering when round-tripping MH -> v2 -> (NNTP|IMAP) -> MH

17 months agoscripts/import_*: update usage to include lei tips
Eric Wong [Wed, 31 Jan 2024 10:20:19 +0000 (10:20 +0000)] 
scripts/import_*: update usage to include lei tips

These scripts probably don't offer anything useful now that
lei has fleshed out read-only MH support and v2 outputs.

17 months agoscripts/slrnspool2maildir: use MHreader and LeiToMail
Eric Wong [Wed, 31 Jan 2024 10:20:18 +0000 (10:20 +0000)] 
scripts/slrnspool2maildir: use MHreader and LeiToMail

This contains gmane-specific header munging to unmunge the
things gmane dones to headers.  While we're at it, document the
generic `lei convert' invocation for users who don't need the
gmane-specific header munging.

17 months agoimport: drop redundant `use' statement
Eric Wong [Wed, 31 Jan 2024 10:20:17 +0000 (10:20 +0000)] 
import: drop redundant `use' statement

We don't need multiple `use PublicInbox::IO' statements to
import a subroutine.

17 months agolei convert: explicitly allow --sort for inputs
Eric Wong [Wed, 31 Jan 2024 10:20:16 +0000 (10:20 +0000)] 
lei convert: explicitly allow --sort for inputs

LeiToMail can't sort v2 output, but sorting MH input (and
NNTP spool + mlmmj archives) numerically makes sense.

17 months agolei_to_mail: improve SIGPIPE handling
Eric Wong [Tue, 30 Jan 2024 10:20:49 +0000 (10:20 +0000)] 
lei_to_mail: improve SIGPIPE handling

I can't reproduce this in t/lei-sigpipe.t with GIANT_INBOX_DIR.
In real-world usage, having a large `lei q -f text ...' output
piped to a pager and killing the pager prematurely could
trigger:

non-fatal error from PublicInbox::LeiToMail $?=256

messages in my terminal.  This is because $self->{lei} was
becoming undefined in the process cleanup process of
git_to_mail.  So flip the cleanup logic around and
unconditionally check for Git::cleanup state to bail out
early.

With this change, the `non-fatal error ...' message no longer
appears when I stop reading results early.

17 months agospawn: support some rlimit uses via Inline::C
Eric Wong [Tue, 30 Jan 2024 07:22:21 +0000 (07:22 +0000)] 
spawn: support some rlimit uses via Inline::C

BSD::Resource isn't packaged for Alpine (as of 3.19), but we
also have optional Inline::C support and already rely on calling
setrlimit(2) directly from the Inline::C version of pi_fork_exec.