diff options
author | Eric Wong <e@80x24.org> | 2021-01-31 22:28:26 -1000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-02-01 11:38:19 +0000 |
commit | 7318712c430bdd15f4fb52cc6c4e10eeb7d0ded2 (patch) | |
tree | 3e905c7cced5e32bd23c14f0df10588187342594 /xt | |
parent | b436cf6e4794a32b3331a8727d10bf000ba55de2 (diff) | |
download | public-inbox-7318712c430bdd15f4fb52cc6c4e10eeb7d0ded2.tar.gz |
This allows us to avoid repeated open() and close() syscalls and speeds up the new xt/stress-sharedkv.t maintainer test by roughly 7%.
Diffstat (limited to 'xt')
-rw-r--r-- | xt/stress-sharedkv.t | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/xt/stress-sharedkv.t b/xt/stress-sharedkv.t new file mode 100644 index 00000000..70de9ffc --- /dev/null +++ b/xt/stress-sharedkv.t @@ -0,0 +1,50 @@ +# Copyright (C) 2021 all contributors <meta@public-inbox.org> +# License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt> +use strict; +use v5.10.1; +use Test::More; +use Benchmark qw(:all); +use PublicInbox::TestCommon; +require_ok 'PublicInbox::SharedKV'; +my ($tmpdir, $for_destroy) = tmpdir(); +local $ENV{TMPDIR} = $tmpdir; +my $skv = PublicInbox::SharedKV->new; +my $ipc = bless {}, 'StressSharedKV'; +$ipc->wq_workers_start('stress-sharedkv', $ENV{TEST_NPROC}//4); +my $nr = $ENV{TEST_STRESS_NR} // 100_000; +my $ios = []; +my $t = timeit(1, sub { + for my $i (1..$nr) { + $ipc->wq_do('test_set_maybe', $ios, $skv, $i); + $ipc->wq_do('test_set_maybe', $ios, $skv, $i); + } +}); +diag "$nr sets done ".timestr($t); + +for my $w ($ipc->wq_workers) { + $ipc->wq_do('test_skv_done', $ios); +} +diag "done requested"; + +$ipc->wq_close; +done_testing; + +package StressSharedKV; +use strict; +use v5.10.1; +use parent qw(PublicInbox::IPC); +use Digest::SHA qw(sha1); + +sub test_set_maybe { + my ($self, $skv, $i) = @_; + my $wcb = $self->{wcb} //= do { + $skv->dbh; + sub { $skv->set_maybe(sha1($_[0]), '') }; + }; + $wcb->($i + time); +} + +sub test_skv_done { + my ($self) = @_; + delete $self->{wcb}; +} |