user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
70de9ffcb263c07386eb6526d6284f63d5833645 blob 1171 bytes (raw)

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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};
}
debug log:

solving 70de9ffc ...
found 70de9ffc in https://80x24.org/public-inbox.git

Code repositories for project(s) associated with this inbox:

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

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).