user/dev discussion of public-inbox itself
 help / color / mirror / Atom feed
* [PATCH 0/5] more indexing improvements
@ 2020-08-07 10:52 Eric Wong
  2020-08-07 10:52 ` [PATCH 1/5] v2writable: fix batch size accounting Eric Wong
                   ` (4 more replies)
  0 siblings, 5 replies; 7+ messages in thread
From: Eric Wong @ 2020-08-07 10:52 UTC (permalink / raw)
  To: meta

VERY big batch sizes seem helpful on HDDs..  And I also blew up
a run because --compact ran in parallel with 32 shards :x

And --help should exist for all commands users may run from
the CLI.

Eric Wong (5):
  v2writable: fix batch size accounting
  index: --compact respects --sequential-shard
  index: max out XAPIAN_FLUSH_THRESHOLD if using --batch-size
  searchidx: use Perl truthiness to detect XAPIAN_FLUSH_THRESHOLD
  index: add built-in --help / -?

 Documentation/public-inbox-index.pod |  4 +-
 lib/PublicInbox/SearchIdx.pm         |  3 +-
 lib/PublicInbox/V2Writable.pm        | 10 ++++-
 script/public-inbox-index            | 58 ++++++++++++++++++++++------
 4 files changed, 58 insertions(+), 17 deletions(-)

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 1/5] v2writable: fix batch size accounting
  2020-08-07 10:52 [PATCH 0/5] more indexing improvements Eric Wong
@ 2020-08-07 10:52 ` Eric Wong
  2020-08-07 13:13   ` Eric Wong
  2020-08-07 10:52 ` [PATCH 2/5] index: --compact respects --sequential-shard Eric Wong
                   ` (3 subsequent siblings)
  4 siblings, 1 reply; 7+ messages in thread
From: Eric Wong @ 2020-08-07 10:52 UTC (permalink / raw)
  To: meta

We need to account for whether shard parallelization is
enabled or not, since users of parallelization are expected
to have more RAM.
---
 lib/PublicInbox/V2Writable.pm | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index a029fe4c..03320b9c 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -152,6 +152,12 @@ sub add {
 	$self->{ibx}->with_umask(\&_add, $self, $eml, $check_cb);
 }
 
+sub batch_bytes ($) {
+	my ($self) = @_;
+	$self->{parallel} ? $PublicInbox::SearchIdx::BATCH_BYTES
+		: $PublicInbox::SearchIdx::BATCH_BYTES * $self->{shards};
+}
+
 # indexes a message, returns true if checkpointing is needed
 sub do_idx ($$$$) {
 	my ($self, $msgref, $mime, $smsg) = @_;
@@ -160,7 +166,7 @@ sub do_idx ($$$$) {
 	my $idx = idx_shard($self, $smsg->{num} % $self->{shards});
 	$idx->index_raw($msgref, $mime, $smsg);
 	my $n = $self->{transact_bytes} += $smsg->{raw_bytes};
-	$n >= ($PublicInbox::SearchIdx::BATCH_BYTES * $self->{shards});
+	$n >= batch_bytes($self);
 }
 
 sub _add {
@@ -1195,7 +1201,7 @@ sub index_xap_step ($$$;$) {
 	my $ibx = $self->{ibx};
 	my $all = $ibx->git;
 	my $over = $ibx->over;
-	my $batch_bytes = $PublicInbox::SearchIdx::BATCH_BYTES;
+	my $batch_bytes = batch_bytes($self);
 	$step //= $self->{shards};
 	my $end = $sync->{art_end};
 	if (my $pr = $sync->{-opt}->{-progress}) {

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 2/5] index: --compact respects --sequential-shard
  2020-08-07 10:52 [PATCH 0/5] more indexing improvements Eric Wong
  2020-08-07 10:52 ` [PATCH 1/5] v2writable: fix batch size accounting Eric Wong
@ 2020-08-07 10:52 ` Eric Wong
  2020-08-07 10:52 ` [PATCH 3/5] index: max out XAPIAN_FLUSH_THRESHOLD if using --batch-size Eric Wong
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-08-07 10:52 UTC (permalink / raw)
  To: meta

Since the --compact switch works on Xapian shards,
it makes sense that --sequential-shard affects our
usage of xapian-compact(1).
---
 script/public-inbox-index | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/script/public-inbox-index b/script/public-inbox-index
index dc9bdde1..56df5bfe 100755
--- a/script/public-inbox-index
+++ b/script/public-inbox-index
@@ -83,5 +83,8 @@ EOL
 		$ibx_opt = { %$opt, sequentialshard => $v };
 	}
 	PublicInbox::Admin::index_inbox($ibx, undef, $ibx_opt);
-	PublicInbox::Xapcmd::run($ibx, 'compact', $compact_opt) if $compact_opt;
+	if ($compact_opt) {
+		local $compact_opt->{jobs} = 0 if $ibx_opt->{sequentialshard};
+		PublicInbox::Xapcmd::run($ibx, 'compact', $compact_opt);
+	}
 }

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 3/5] index: max out XAPIAN_FLUSH_THRESHOLD if using --batch-size
  2020-08-07 10:52 [PATCH 0/5] more indexing improvements Eric Wong
  2020-08-07 10:52 ` [PATCH 1/5] v2writable: fix batch size accounting Eric Wong
  2020-08-07 10:52 ` [PATCH 2/5] index: --compact respects --sequential-shard Eric Wong
@ 2020-08-07 10:52 ` Eric Wong
  2020-08-07 10:52 ` [PATCH 4/5] searchidx: use Perl truthiness to detect XAPIAN_FLUSH_THRESHOLD Eric Wong
  2020-08-07 10:52 ` [PATCH 5/5] index: add built-in --help / -? Eric Wong
  4 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-08-07 10:52 UTC (permalink / raw)
  To: meta

If XAPIAN_FLUSH_THRESHOLD is unset, Xapian will default to
10000.  That limits the effectiveness of users specifying
extremely large values of --batch-size.

While we're at it, localize the changes to globals since -index
may be eval-ed in tests (and perhaps production code in the
future).
---
 script/public-inbox-index | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)

diff --git a/script/public-inbox-index b/script/public-inbox-index
index 56df5bfe..e2bca16e 100755
--- a/script/public-inbox-index
+++ b/script/public-inbox-index
@@ -42,11 +42,16 @@ if (defined $max_size) {
 		die "`publicInbox.indexMaxSize=$max_size' not parsed\n";
 }
 
-if (my $bs = $opt->{batchsize} // $cfg->{lc('publicInbox.indexBatchSize')}) {
+my $bs = $opt->{batchsize} // $cfg->{lc('publicInbox.indexBatchSize')};
+if (defined $bs) {
 	PublicInbox::Admin::parse_unsigned(\$bs) or
 		die "`publicInbox.indexBatchSize=$bs' not parsed\n";
-	$PublicInbox::SearchIdx::BATCH_BYTES = $bs;
 }
+local $PublicInbox::SearchIdx::BATCH_BYTES = $bs if defined($bs);
+
+# out-of-the-box builds of Xapian 1.4.x are still limited to 32-bit
+# https://getting-started-with-xapian.readthedocs.io/en/latest/concepts/indexing/limitations.html
+local $ENV{XAPIAN_FLUSH_THRESHOLD} ||= '4294967295' if defined($bs);
 
 my $s = $opt->{sequentialshard} //
 			$cfg->{lc('publicInbox.indexSequentialShard')};

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 4/5] searchidx: use Perl truthiness to detect XAPIAN_FLUSH_THRESHOLD
  2020-08-07 10:52 [PATCH 0/5] more indexing improvements Eric Wong
                   ` (2 preceding siblings ...)
  2020-08-07 10:52 ` [PATCH 3/5] index: max out XAPIAN_FLUSH_THRESHOLD if using --batch-size Eric Wong
@ 2020-08-07 10:52 ` Eric Wong
  2020-08-07 10:52 ` [PATCH 5/5] index: add built-in --help / -? Eric Wong
  4 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-08-07 10:52 UTC (permalink / raw)
  To: meta

XAPIAN_FLUSH_THRESHOLD is a C string in the environment, so
users may be tempted to assign an empty string in in their
shell, e.g. `XAPIAN_FLUSH_THRESHOLD= <command>' instead of using
`unset' POSIX shell built-in.

With either a value of "0" or "" (empty string), Xapian will
fall back to its default (10000 documents), which causes grief
for memory-starved users.
---
 lib/PublicInbox/SearchIdx.pm | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/lib/PublicInbox/SearchIdx.pm b/lib/PublicInbox/SearchIdx.pm
index 22489731..01b9f52d 100644
--- a/lib/PublicInbox/SearchIdx.pm
+++ b/lib/PublicInbox/SearchIdx.pm
@@ -25,8 +25,7 @@ our @EXPORT_OK = qw(crlf_adjust log2stack is_ancestor check_size nodatacow_dir);
 my $X = \%PublicInbox::Search::X;
 my ($DB_CREATE_OR_OPEN, $DB_OPEN);
 our $DB_NO_SYNC = 0;
-our $BATCH_BYTES = defined($ENV{XAPIAN_FLUSH_THRESHOLD}) ?
-			0x7fffffff : 1_000_000;
+our $BATCH_BYTES = $ENV{XAPIAN_FLUSH_THRESHOLD} ? 0x7fffffff : 1_000_000;
 use constant DEBUG => !!$ENV{DEBUG};
 
 my $xapianlevels = qr/\A(?:full|medium)\z/;

^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH 5/5] index: add built-in --help / -?
  2020-08-07 10:52 [PATCH 0/5] more indexing improvements Eric Wong
                   ` (3 preceding siblings ...)
  2020-08-07 10:52 ` [PATCH 4/5] searchidx: use Perl truthiness to detect XAPIAN_FLUSH_THRESHOLD Eric Wong
@ 2020-08-07 10:52 ` Eric Wong
  4 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-08-07 10:52 UTC (permalink / raw)
  To: meta

Eventually, commonly-used commands run by the user will all
support --help / -? for user-friendliness.   The changes from
up-front `use' to lazy `require' speed up `--help' by 3x or so.
---
 Documentation/public-inbox-index.pod |  4 +--
 script/public-inbox-index            | 44 +++++++++++++++++++++++-----
 2 files changed, 38 insertions(+), 10 deletions(-)

diff --git a/Documentation/public-inbox-index.pod b/Documentation/public-inbox-index.pod
index a4edc57a..56dec993 100644
--- a/Documentation/public-inbox-index.pod
+++ b/Documentation/public-inbox-index.pod
@@ -40,8 +40,8 @@ Influences the number of Xapian indexing shards in a
 C<--jobs=0> is accepted as of public-inbox 1.6.0 (PENDING)
 to disable parallel indexing.
 
-If the inbox has not been indexed, C<JOBS - 1> shards
-will be created (one job is always needed for indexing
+If the inbox has not been indexed or initialized, C<JOBS - 1>
+shards will be created (one job is always needed for indexing
 the overview and article number mapping).
 
 Default: the number of existing Xapian shards
diff --git a/script/public-inbox-index b/script/public-inbox-index
index e2bca16e..73ca2953 100755
--- a/script/public-inbox-index
+++ b/script/public-inbox-index
@@ -1,4 +1,4 @@
-#!/usr/bin/perl -w
+#!perl -w
 # Copyright (C) 2015-2020 all contributors <meta@public-inbox.org>
 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
 # Basic tool to create a Xapian search index for a public-inbox.
@@ -6,22 +6,47 @@
 # highly recommended: eatmydata public-inbox-index INBOX_DIR
 
 use strict;
-use warnings;
+use v5.10.1;
 use Getopt::Long qw(:config gnu_getopt no_ignore_case auto_abbrev);
-my $usage = "public-inbox-index INBOX_DIR";
-use PublicInbox::Admin;
-PublicInbox::Admin::require_or_die('-index');
-use PublicInbox::Xapcmd;
+my $usage = 'public-inbox-index [options] INBOX_DIR';
+my $help = <<EOF; # the following should fit w/o scrolling in 80x24 term:
+usage: $usage
+
+  Create and update search indices
+
+options:
 
+  --no-fsync          speed up indexing, risk corruption on power outage
+  --indexlevel=LEVEL  `basic', 'medium', or `full' (default: full)
+  --compact | -c      run public-inbox-compact(1) after indexing
+  --sequential-shard  index Xapian shards sequentially for slow storage
+  --jobs=NUM          set or disable parallelization (NUM=0)
+  --batch-size=BYTES  flush changes to OS after a given number of bytes
+  --max-size=BYTES    do not index messages larger than the given size
+  --reindex           index previously indexed data (if upgrading)
+  --rethread          regenerate thread IDs (if upgrading, use sparingly)
+  --prune             prune git storage on discontiguous history
+  --verbose | -v      increase verbosity (may be repeated)
+  --help | -?         show this help
+
+BYTES may use `k', `m', and `g' suffixes (e.g. `10m' for 10 megabytes)
+See public-inbox-index(1) man page for full documentation.
+EOF
 my $compact_opt;
 my $opt = { quiet => -1, compact => 0, maxsize => undef, fsync => 1 };
 GetOptions($opt, qw(verbose|v+ reindex rethread compact|c+ jobs|j=i prune
 		fsync|sync! xapianonly|xapian-only
 		indexlevel|L=s maxsize|max-size=s batchsize|batch-size=s
-		sequentialshard|seq-shard|sequential-shard))
+		sequentialshard|seq-shard|sequential-shard
+		help|?))
 	or die "bad command-line args\n$usage";
+if ($opt->{help}) { print $help; exit 0 };
 die "--jobs must be >= 0\n" if defined $opt->{jobs} && $opt->{jobs} < 0;
 
+# require lazily to speed up --help
+require PublicInbox::Admin;
+PublicInbox::Admin::require_or_die('-index');
+
 if ($opt->{compact}) {
 	require PublicInbox::Xapcmd;
 	PublicInbox::Xapcmd::check_compact();
@@ -31,7 +56,7 @@ if ($opt->{compact}) {
 	}
 }
 
-my $cfg = PublicInbox::Config->new;
+my $cfg = PublicInbox::Config->new; # Config is loaded by Admin
 my @ibxs = PublicInbox::Admin::resolve_inboxes(\@ARGV, undef, $cfg);
 PublicInbox::Admin::require_or_die('-index');
 unless (@ibxs) { print STDERR "Usage: $usage\n"; exit 1 }
@@ -47,7 +72,9 @@ if (defined $bs) {
 	PublicInbox::Admin::parse_unsigned(\$bs) or
 		die "`publicInbox.indexBatchSize=$bs' not parsed\n";
 }
+no warnings 'once';
 local $PublicInbox::SearchIdx::BATCH_BYTES = $bs if defined($bs);
+use warnings 'once';
 
 # out-of-the-box builds of Xapian 1.4.x are still limited to 32-bit
 # https://getting-started-with-xapian.readthedocs.io/en/latest/concepts/indexing/limitations.html
@@ -72,6 +99,7 @@ foreach my $ibx (@ibxs) {
 }
 
 PublicInbox::Admin::require_or_die(keys %$mods);
+require PublicInbox::InboxWritable;
 PublicInbox::Admin::progress_prepare($opt);
 for my $ibx (@ibxs) {
 	$ibx = PublicInbox::InboxWritable->new($ibx);

^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH 1/5] v2writable: fix batch size accounting
  2020-08-07 10:52 ` [PATCH 1/5] v2writable: fix batch size accounting Eric Wong
@ 2020-08-07 13:13   ` Eric Wong
  0 siblings, 0 replies; 7+ messages in thread
From: Eric Wong @ 2020-08-07 13:13 UTC (permalink / raw)
  To: meta

Eric Wong <e@yhbt.net> wrote:
> We need to account for whether shard parallelization is
> enabled or not, since users of parallelization are expected
> to have more RAM.
> ---
>  lib/PublicInbox/V2Writable.pm | 10 ++++++++--
>  1 file changed, 8 insertions(+), 2 deletions(-)
> 
> diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
> index a029fe4c..03320b9c 100644
> --- a/lib/PublicInbox/V2Writable.pm
> +++ b/lib/PublicInbox/V2Writable.pm
> @@ -152,6 +152,12 @@ sub add {
>  	$self->{ibx}->with_umask(\&_add, $self, $eml, $check_cb);
>  }
>  
> +sub batch_bytes ($) {
> +	my ($self) = @_;
> +	$self->{parallel} ? $PublicInbox::SearchIdx::BATCH_BYTES
> +		: $PublicInbox::SearchIdx::BATCH_BYTES * $self->{shards};
> +}

Oops, that was backwards :x  Will squash this in:

diff --git a/lib/PublicInbox/V2Writable.pm b/lib/PublicInbox/V2Writable.pm
index 03320b9c0..f7a318e5b 100644
--- a/lib/PublicInbox/V2Writable.pm
+++ b/lib/PublicInbox/V2Writable.pm
@@ -154,8 +154,8 @@ sub add {
 
 sub batch_bytes ($) {
 	my ($self) = @_;
-	$self->{parallel} ? $PublicInbox::SearchIdx::BATCH_BYTES
-		: $PublicInbox::SearchIdx::BATCH_BYTES * $self->{shards};
+	($self->{parallel} ? $self->{shards} : 1) *
+		$PublicInbox::SearchIdx::BATCH_BYTES;
 }
 
 # indexes a message, returns true if checkpointing is needed

>  sub do_idx ($$$$) {
>  	my ($self, $msgref, $mime, $smsg) = @_;
> @@ -160,7 +166,7 @@ sub do_idx ($$$$) {
>  	my $idx = idx_shard($self, $smsg->{num} % $self->{shards});
>  	$idx->index_raw($msgref, $mime, $smsg);
>  	my $n = $self->{transact_bytes} += $smsg->{raw_bytes};
> -	$n >= ($PublicInbox::SearchIdx::BATCH_BYTES * $self->{shards});
> +	$n >= batch_bytes($self);
>  }

...Because the old code always assumed parallel shards (even
with --jobs=0).

>  sub _add {
> @@ -1195,7 +1201,7 @@ sub index_xap_step ($$$;$) {
>  	my $ibx = $self->{ibx};
>  	my $all = $ibx->git;
>  	my $over = $ibx->over;
> -	my $batch_bytes = $PublicInbox::SearchIdx::BATCH_BYTES;
> +	my $batch_bytes = batch_bytes($self);
>  	$step //= $self->{shards};
>  	my $end = $sync->{art_end};
>  	if (my $pr = $sync->{-opt}->{-progress}) {

And the new index_xap_step was not designed for parallel
operation, initially.

^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2020-08-07 13:13 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-07 10:52 [PATCH 0/5] more indexing improvements Eric Wong
2020-08-07 10:52 ` [PATCH 1/5] v2writable: fix batch size accounting Eric Wong
2020-08-07 13:13   ` Eric Wong
2020-08-07 10:52 ` [PATCH 2/5] index: --compact respects --sequential-shard Eric Wong
2020-08-07 10:52 ` [PATCH 3/5] index: max out XAPIAN_FLUSH_THRESHOLD if using --batch-size Eric Wong
2020-08-07 10:52 ` [PATCH 4/5] searchidx: use Perl truthiness to detect XAPIAN_FLUSH_THRESHOLD Eric Wong
2020-08-07 10:52 ` [PATCH 5/5] index: add built-in --help / -? Eric Wong

user/dev discussion of public-inbox itself

This inbox may be cloned and mirrored by anyone:

	git clone --mirror https://public-inbox.org/meta
	git clone --mirror http://czquwvybam4bgbro.onion/meta
	git clone --mirror http://hjrcffqmbrq6wope.onion/meta
	git clone --mirror http://ou63pmih66umazou.onion/meta

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V1 meta meta/ https://public-inbox.org/meta \
		meta@public-inbox.org
	public-inbox-index meta

Example config snippet for mirrors.
Newsgroups are available over NNTP:
	nntp://news.public-inbox.org/inbox.comp.mail.public-inbox.meta
	nntp://ou63pmih66umazou.onion/inbox.comp.mail.public-inbox.meta
	nntp://czquwvybam4bgbro.onion/inbox.comp.mail.public-inbox.meta
	nntp://hjrcffqmbrq6wope.onion/inbox.comp.mail.public-inbox.meta
	nntp://news.gmane.io/gmane.mail.public-inbox.general
 note: .onion URLs require Tor: https://www.torproject.org/

code repositories for the project(s) associated with this inbox:

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

AGPL code for this site: git clone https://public-inbox.org/public-inbox.git