1 # Copyright (C) 2021 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
6 use Benchmark qw(:all);
7 use PublicInbox::TestCommon;
8 require_ok 'PublicInbox::SharedKV';
9 my ($tmpdir, $for_destroy) = tmpdir();
10 local $ENV{TMPDIR} = $tmpdir;
11 my $skv = PublicInbox::SharedKV->new;
12 my $ipc = bless {}, 'StressSharedKV';
13 $ipc->wq_workers_start('stress-sharedkv', $ENV{TEST_NPROC}//4);
14 my $nr = $ENV{TEST_STRESS_NR} // 100_000;
16 my $t = timeit(1, sub {
18 $ipc->wq_io_do('test_set_maybe', $ios, $skv, $i);
19 $ipc->wq_io_do('test_set_maybe', $ios, $skv, $i);
22 diag "$nr sets done ".timestr($t);
24 for my $w ($ipc->wq_workers) {
25 $ipc->wq_io_do('test_skv_done', $ios);
27 diag "done requested";
32 package StressSharedKV;
35 use parent qw(PublicInbox::IPC);
36 use Digest::SHA qw(sha1);
39 my ($self, $skv, $i) = @_;
40 my $wcb = $self->{wcb} //= do {
42 sub { $skv->set_maybe(sha1($_[0]), '') };