Instead of doing fill_alternates for every epoch we're indexing,
just do it once at the start of index_sync invocation. This
will set us up for using a single "git cat-file" process for
indexing multiple epochs.
Eric Wong [Fri, 24 Jul 2020 05:55:49 +0000 (05:55 +0000)]
v2writable: introduce idx_stack
This avoids pinning a potentially large chunk of memory from
`git-log --reverse' into RAM (or triggering less predictable
swap behavior). Instead it uses a contiguous temporary file
with a fixed-size record for every blob we'll need to index.
Eric Wong [Fri, 24 Jul 2020 05:55:48 +0000 (05:55 +0000)]
v2: index forwards (via `git log --reverse')
Since we'll need to expose THREADID to JMAP and IMAP users,
index all messages in the order they were committed to ensure
our `tid' (thread ID) column ascends in mirrors the same way
they do in the source inbox.
This drastically simplifies our code but increases memory
usage of `git-log'. The next commit will bring memory use
back down at the expense of $TMPDIR usage.
Eric Wong [Fri, 24 Jul 2020 05:55:47 +0000 (05:55 +0000)]
index: support --rethread switch to fix old indices
Older versions of public-inbox < 1.3.0 had subtly
different semantics around threading in some corner
cases. This switch (when combined with --reindex)
allows us to fix them by regenerating associations.
Eric Wong [Fri, 17 Jul 2020 07:25:07 +0000 (07:25 +0000)]
v2writable: git_hash_raw: avoid $TMPDIR write
We can rely on FD_CLOEXEC being set by default (since Perl 5.6+)
on pipes to avoid FS/page-cache traffic, here. We also know
"git hash-object" won't output anything until it's consumed all
of its standard input; so there's no danger of a deadlock even
in the the unlikely case git uses a hash that can't fit into
PIPE_BUF :P
Eric Wong [Fri, 17 Jul 2020 06:31:55 +0000 (06:31 +0000)]
search: simplify unindexing
Since over.sqlite3 seems here to stay, we no longer need to do
Message-ID lookups against Xapian and can simply rely on the
docid <=> NNTP article number equivalancy SCHEMA_VERSION=15
gave us.
This rids us of the closure-using batch_do sub in the v1
code path and vastly simplifies both v1 and v2 unindexing.
Eric Wong [Fri, 17 Jul 2020 06:31:54 +0000 (06:31 +0000)]
searchidx: use v5.10.1, parent.pm, drop warnings
Prefer "parent" to "base" since the former is lighter and part
of Perl 5.10+. We'll also rely on warnings from "-w" globally
(or not) instead of via "use".
Eric Wong [Fri, 17 Jul 2020 06:31:53 +0000 (06:31 +0000)]
overidx: favor non-OO sub dispatch for internal subs
OO method dispatch was 10-15% slower when I was implementing the
NNTP server. It also serves as a helpful reminder to the reader
at the callsite as to whether a sub is likely in the same
package as the caller or not.
Eric Wong [Fri, 17 Jul 2020 06:31:49 +0000 (06:31 +0000)]
drop binmode usage
We only support Unix-like platforms where binmode (":raw") is
the default anyways, and v5.10 semantics means it won't do
unicode_strings (unlike v5.12). So save some lines of code.
Eric Wong [Fri, 17 Jul 2020 06:31:48 +0000 (06:31 +0000)]
v2: use v5.10.1, parent.pm, drop warnings
The "5.010_001" form was for Perl 5.6, which I doubt anybody
would attempt; so favor "v5.10.1" as it is more readable to
humans. Prefer "parent" to "base" since the former is lighter.
We'll also rely on warnings from "-w" globally (or not) instead
of via "use".
We'll also update "use" statements to reflect what's actually
used by V2Writable.
Eric Wong [Thu, 16 Jul 2020 21:54:24 +0000 (21:54 +0000)]
t/import: quiet warning, clobber variable
The eval in key2sub via t/run.perl ("make check-run") won't
trigger the warning, but running "prove -bvw t/import.t"
directly, does. In any case, ensure the contents of this
variable doesn't linger across runs.
Eric Wong [Fri, 17 Jul 2020 03:57:24 +0000 (03:57 +0000)]
doc: add some recommendations around slow HDDs
grok-pull is still painful with serialization on an old USB 2.0
HDD, but at least it can finish with flock(1) and disabling
parallelization. While parallel "git fetch" doesn't seem so
bad, slow seeks are exacerbated by parallel reads in Xapian.
That means some updates can take days instead of hours. The
same updates take only seconds or minutes on an SSD.
Eric Wong [Fri, 17 Jul 2020 06:07:10 +0000 (06:07 +0000)]
config: reject `\n' in `inboxdir'
"\n" and other characters requiring quoting and/or escaping in
in $GIT_DIR/objects/info/alternates was not supported in git 2.11
and earlier; nor does it seem supported at all in libgit2.
This will allow us to support sharing git-cat-file or similar
endpoints across multiple inboxes via alternates.
This breaks an existing use case for anybody wacky
enough to put `\n' in the `inboxdir' pathname; but I doubt
this affects anybody.
Eric Wong [Tue, 14 Jul 2020 10:06:40 +0000 (10:06 +0000)]
doc: release notes and version info updates
Update release notes with some features in the 1.6 timeline.
We'll note the version availability of some command-line
options, it may help users who are reading the latest
documentation online but running older versions.
Eric Wong [Tue, 14 Jul 2020 02:14:31 +0000 (02:14 +0000)]
nntpd+imapd: detect unlinked msgmap
While it's even less common to experience a replaced
msgmap.sqlite3 file, BOFHs may do the darndest things. This is
another step towards reducing the number of needless wakeups
we need to do in long-lived read-only daemons.
Eric Wong [Tue, 14 Jul 2020 02:14:30 +0000 (02:14 +0000)]
over: unset sqlite_unicode attribute
None of the human-readable strings stored in over.sqlite3
require UTF-8. Message-IDs do not, nor do the compressed
Subject IDs (sid) we use for Subject-based threading. And the
`ddd' (doc-data-deflated) column is of course binary data.
This frees us of having to use SQL_BLOB for the `ddd', column,
and will open the door for us to use dbh_new for Msgmap, too.
Eric Wong [Sun, 5 Jul 2020 21:51:31 +0000 (21:51 +0000)]
xapcmd: delay over->check_inodes trigger
We must not trigger wakeups on InboxIdle users until after we've
renamed all files into place. Otherwise, the InboxIdle caller
may just reopen the old (soon-to-be-unlinked) file.
Eric Wong [Mon, 13 Jul 2020 02:23:28 +0000 (02:23 +0000)]
xt/mem-imapd-tls: avoid EMFILE in -imapd process
Test::More dups standard FDs and may create FDs for other
purposes. run_mode => 0 lets us rely on FD_CLOEXEC to ensure
-imapd has enough FDs to accept all incoming connections at
the cost of higher (one-off) startup time.
Eric Wong [Tue, 7 Jul 2020 20:37:38 +0000 (20:37 +0000)]
wwwatomstream: avoid uninitialized warnings for $email
As in Import, we'll fall back to Sender: if From: is missing,
and use the primary_address of the inboxes to indicate the total
absence of those fields.
Eric Wong [Tue, 7 Jul 2020 06:17:24 +0000 (06:17 +0000)]
t/spawn: fix test reliability
Since Perl doesn't internally use a self-pipe for
sleep/select/poll/etc, wake up every 10ms to ensure
it can see the SIGCHLD; since neither signalfd nor EVFILT_SIGNAL
are always available.
Fixes: 761baa2a300e4268 ("spawn: unblock SIGCHLD in subprocess")
Eric Wong [Sun, 5 Jul 2020 22:44:52 +0000 (22:44 +0000)]
doc/technical/whyperl: note Perl 7 announcement
Right now[1] the Perl upstream plan is to maintain 5 compatibility
in Perl 7 for at least 5 years[1], and perhaps drop it when Perl 8
comes along. That said, distros may pick it and maintain 5 on their
own given the vast amounts of perfectly good legacy code out there.
Eric Wong [Sun, 5 Jul 2020 22:44:49 +0000 (22:44 +0000)]
git: use v5.10.1, parent.pm and Time::HiRes::stat
parent.pm is leaner than base.pm, and Time::HiRes::stat is
more accurate, so take advantage of these Perl 5.10+-isms
since it's been over a year since we left 5.8 behind.
Eric Wong [Sun, 5 Jul 2020 23:27:57 +0000 (23:27 +0000)]
gzipfilter: drop HTTP connection on bugs or data corruption
While all the {async_next} callbacks needed eval guards anyways
because of DS->write, {async_eml} callbacks did not.
Ensure any bugs in our code or data corruption result in
termination of the HTTP connection, so as not to leave clients
hanging on a response which never comes or is mangled in some
way.
Eric Wong [Sun, 5 Jul 2020 23:27:56 +0000 (23:27 +0000)]
wwwattach: support async blob retrievals
We can reuse some of the GzipFilter infrastructure used by other
WWW components to handle slow blob retrieval, here. The
difference from previous changes is we don't decide on the 200
status code until we've retrieved the blob and found the
attachment.
While we're at it, ensure we can compress text attachment
responses once again, since all text attachments are served
as text/plain.
Eric Wong [Sun, 5 Jul 2020 23:27:55 +0000 (23:27 +0000)]
wwwtext: simplify gzf_maybe use
gzf_maybe always returns a GzipFilter object, even if it uses
CompressNoop. We can also use ->zflush instead of
->translate(undef) here for the final bit.
Eric Wong [Sun, 5 Jul 2020 23:27:52 +0000 (23:27 +0000)]
wwwstream: eliminate ::response, use html_oneshot
All of our streaming responses use ::aresponse, now, and our
synchronous responses use html_oneshot. So there's no need
for the old WwwStream::response.
Eric Wong [Sun, 5 Jul 2020 23:27:51 +0000 (23:27 +0000)]
view: /$INBOX/$MSGID/t/: avoid extra hash lookup in eml case
We can build and buffer the HTML <head> section once the first
non-ghost message in a thread is loaded, so there's no need to
perform an extra check on $ctx->{nr} once the $eml is ready.
Eric Wong [Sun, 5 Jul 2020 23:27:41 +0000 (23:27 +0000)]
remove unused/redundant zlib-related imports
Z_FINISH is the default for Compress::Raw::Zlib::Deflate->flush,
anyways, so there's no reason to import it. And none of C::R::Z
is needed in WwwText now that gzf_maybe handles it all.
Eric Wong [Sun, 5 Jul 2020 23:27:40 +0000 (23:27 +0000)]
www: start making gzipfilter the parent response class
Virtually all of our responses are going to be gzipped, anyways.
This will allow us to utilize zlib as a buffering layer and
share common code for async blob retrieval responses.
To streamline this and allow GzipFilter to be a parent class,
we'll replace the NoopFilter with a similar CompressNoop class
which emulates the two Compress::Raw::Zlib::Deflate methods we
use.
This drops a bunch of redundant code and will hopefully make
upcoming WwwStream changes easier to reason about.
Eric Wong [Sun, 5 Jul 2020 23:27:39 +0000 (23:27 +0000)]
wwwstream: reduce blob fetch paths for ->getline
This will make it easier to support asynchronous blob
retrievals. The `$ctx->{nr}' counter is no longer implicitly
supplied since many users didn't care for it, so stack overhead
is slightly reduced.
Eric Wong [Sun, 5 Jul 2020 23:27:38 +0000 (23:27 +0000)]
wwwstream: reduce object graph depth
Like with WwwAtomStream and MboxGz, we can bless the existing
$ctx object directly to avoid allocating a new hashref. We'll
also switch from "->" to "::" to reduce stack utilization.
Eric Wong [Sun, 5 Jul 2020 23:27:37 +0000 (23:27 +0000)]
wwwatomstream: support async blob fetch
This allows -httpd to handle other requests while waiting
for git to retrieve and decode blobs. We'll also break
apart t/psgi_v2.t further to ensure tests run against
-httpd in addition to generic PSGI testing.
Using xt/httpd-async-stream.t to test against clones of meta@public-inbox.org
shows a 10-12% performance improvement with the following env:
TEST_JOBS=1000 TEST_CURL_OPT=--compressed TEST_ENDPOINT=new.atom
Eric Wong [Sun, 5 Jul 2020 23:27:32 +0000 (23:27 +0000)]
mbox: async blob fetch for "single message" raw mboxrd
This restores gzip-by-default behavior for /$INBOX/$MSGID/raw
endpoints for all indexed inboxes. Unindexed v1 inboxes will
remain uncompressed, for now.
Eric Wong [Sun, 5 Jul 2020 23:27:30 +0000 (23:27 +0000)]
mboxgz: do asynchronous git blob retrievals
This lets the -httpd worker process make better use of time
instead of waiting for git-cat-file to respond. With 4 jobs in
the new test case against a clone of
<https://public-inbox.org/meta/>, a speedup of 10-12% is shown.
Even a single job shows a 2-5% improvement on an SSD.
Eric Wong [Sun, 5 Jul 2020 23:27:29 +0000 (23:27 +0000)]
stop auto-loading Plack::Middleware::Deflater
Instead of gzipping some (mbox.gz, manifest.js.gz) responses and
leaving P::M::D to do the rest, we gzip everything ourselves,
now, so P::M::D is redundant.
Eric Wong [Sun, 5 Jul 2020 23:27:27 +0000 (23:27 +0000)]
wwwstatic: support gzipped directory listings
This will allow others to mimic our award-winning homepage
design without needing to rely on Plack::Middleware::Deflater
or varnish to compress responses.
Eric Wong [Sun, 5 Jul 2020 23:27:25 +0000 (23:27 +0000)]
{gzip,noop}filter: ->zmore returns undef, always
This simplifies callers, as witnessed by the change to
WwwListing. It adds overhead to NoopFilter, but NoopFilter
should see little use as nearly all HTTP clients request gzip.
Eric Wong [Sun, 5 Jul 2020 23:27:24 +0000 (23:27 +0000)]
gzipfilter: replace Compress::Raw::Deflate usages
The new ->zmore and ->zflush APIs make it possible to replace
existing verbose usages of Compress::Raw::Deflate and simplify
buffering logic for streaming large gzipped data.
One potentially user visible change is we now break the mbox.gz
response on zlib failures, instead of silently continuing onto
the next message. zlib only seems to fail on OOM, which should
be rare; so it's ideal we drop the connection anyways.
Eric Wong [Sun, 5 Jul 2020 23:27:18 +0000 (23:27 +0000)]
wwwstream: oneshot: perform gzip without middleware
Plack::Middleware::Deflater forces us to use a memory-intensive
closure. Instead, work towards building compressed strings in
memory to reduce the overhead of buffering large HTML output.
Eric Wong [Sun, 5 Jul 2020 23:27:17 +0000 (23:27 +0000)]
gzipfilter: minor cleanups
We currently don't use bytes::length in ->write, so there's no
need to `use bytes'. Favor `//=' to describe the intent of the
conditional assignment since the C::R::Z::Deflate object is
always truthy. Also use the local $gz variable to avoid
unnecessary {gz} hash lookups.
Eric Wong [Mon, 6 Jul 2020 06:11:02 +0000 (06:11 +0000)]
git_async_cat: unref pipes on EOF from git->cleanup
We avoided a managed circular reference in 10ee3548084c125f
but introduced a pipe FD leak, instead. So handle the EOF
we get when the "git cat-file --batch" process exits and
closes its stdout FD.
v2: remove ->close entirely. PublicInbox::Git->cleanup
handles all cleanup. This prevents us from inadvertantly
deleting the {async_cat} field associated with a different
pipe than the one GAC is monitoring.
Eric Wong [Sat, 4 Jul 2020 20:25:25 +0000 (20:25 +0000)]
t/import: test for nasty characters
Spammers may send emails with nasty characters which can throw
off git-fast-import. Users with non-existent or weaker spam
filters may be susceptible to corruption in the fast-import
stream as a result.
This was actually quietly fixed in git on 2020-06-01 by
commit 9ab886546cc89f37819e1ef09cb49fd9325b3a41
("smsg: introduce ->populate method"), but no test case
was created.
Eric Wong [Sat, 4 Jul 2020 21:33:13 +0000 (21:33 +0000)]
watch: don't burn CPU on IDLE failures
Network connections fail and need to be detected sooner rather
than later during IDLE to avoid backtrace floods. In case the
IDLE process dies completely, don't respawn right away, either,
to avoid entering a respawn loop.
Eric Wong [Wed, 1 Jul 2020 21:06:18 +0000 (21:06 +0000)]
tests: add use/require statements for TEST_RUN_MODE=0
The default (and fast) TEST_RUN_MODE=2 preloads most modules,
but TEST_RUN_MODE=0 is more realistic and can catch some
problems which may show up in real-world use.
Eric Wong [Wed, 1 Jul 2020 21:06:17 +0000 (21:06 +0000)]
watch: retry signals to kill IDLE and polling processes
To ensure reliable signal delivery in Perl, it seems we need to
repeatedly signal processes which aren't using signalfd (or
EVFILT_SIGNAL) with our event loop.
Eric Wong [Thu, 2 Jul 2020 03:32:56 +0000 (03:32 +0000)]
inboxidle: avoid per-inbox anonymous subs
Anonymous subs cost over 5K each on x86-64. So prefer the
less-recommended-but-still-documented way of using
Linux::Inotify2::watch to register watchers.
This also updates FakeInotify to detect modifications correctly
when used on systems with neither IO::KQueue nor
Linux::Inotify2.
Eric Wong [Mon, 29 Jun 2020 10:34:21 +0000 (10:34 +0000)]
watch: make waitpid() synchronous for Maildir scans
Maildir scanning still happens in the main process. Scanning
dozens of Maildirs is still time-consuming and monopolizes the
event loop during WatchMaildir::event_step. This can cause
cause zombies to accumulate before Sigfd::event_step triggers
DS::reap_pids.
Eric Wong [Mon, 29 Jun 2020 10:34:19 +0000 (10:34 +0000)]
watch: ensure SIGCHLD works in forked children
In case our git or spam checker subprocesses spawn
subprocesses of their own. We'll also ensure signal
handlers are properly setup before unblocking them.
Eric Wong [Mon, 29 Jun 2020 10:34:17 +0000 (10:34 +0000)]
watch: check for duplicates in ->over before spamcheck
It's cheaper to check for duplicates than run `spamc'
repeatedly when rechecking. We already do this for
v1 with by using the "ls" command with fast-import,
but v2 requires checking against over.sqlite3.
Eric Wong [Sat, 27 Jun 2020 10:04:00 +0000 (10:04 +0000)]
watch: simplify internal structures
We won't be attempting to reuse Mail::IMAPConnections used to
check authentication info, for now, so stop storing
$self->{mics}.
We can also combine $poll initialization for IMAP and NNTP
to avoid data structure duplication. Furthermore, rely on
autovivification to create {idle_pids} and {poll_pids}.
Eric Wong [Sat, 27 Jun 2020 10:03:59 +0000 (10:03 +0000)]
imaptracker: use flock(2) around writes
SQLite only issues non-blocking F_SETLK ops (not F_SETLKW) and
retries failures using a configurable busy_timeout. SQLite's
busy loop sleeps for a millisecond and retries the lock until
the configured busy_timeout is hit.
Trying to set ->sqlite_busy_timeout to larger values (e.g. 30000
milliseconds) still leads to failure when running the new stress
test with 8 processes with TMPDIR on a 7200 RPM HDD.
Inspection of SQLite source reveals there's no built-in way to
use F_SETLKW, so tack on the existing flock(2) support we use to
synchronize git + SQLite + Xapian for inbox writing. We use
flock(2) instead of POSIX fcntl(2) locks since Perl doesn't
provide a way to manipulate "struct flock" portably.
Eric Wong [Sat, 27 Jun 2020 10:03:58 +0000 (10:03 +0000)]
watch: support ~/.netrc via Net::Netrc
While git-credential-netrc exists in git.git contrib/, it may
not be widely known or installed. Net::Netrc is already a
standard part of most (if not all) Perl installations, so use it
directly if available.