1 # Copyright (C) 2018-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 :hireswallclock);
7 use PublicInbox::Inbox;
9 my $inboxdir = $ENV{GIANT_INBOX_DIR} // $ENV{GIANT_PI_DIR};
10 plan skip_all => "GIANT_INBOX_DIR not defined for $0" unless defined($inboxdir);
11 my ($host_port, $group, $s, $td, $tmp_obj);
12 use PublicInbox::TestCommon;
14 if (($ENV{NNTP_TEST_URL} || '') =~ m!\Anntp://([^/]+)/([^/]+)\z!) {
15 ($host_port, $group) = ($1, $2);
16 $host_port .= ":119" unless index($host_port, ':') > 0;
17 my $six = substr($host_port, 0, 1) eq '[' ? '6' : '';
18 my $cls = "IO::Socket::INET$six";
19 $cls->new(Proto => 'tcp', Timeout => 1, PeerAddr => $host_port);
21 $group = 'inbox.test.perf.nntpd';
22 my $ibx = { inboxdir => $inboxdir, newsgroup => $group };
23 $ibx = PublicInbox::Inbox->new($ibx);
25 ($tmpdir, $tmp_obj) = tmpdir();
27 my $pi_config = "$tmpdir/config";
29 open my $fh, '>', $pi_config or die "open($pi_config): $!";
30 print $fh <<"" or die "print $pi_config: $!";
34 address = test\@example.com
36 close $fh or die "close($pi_config): $!";
39 my $sock = tcp_server();
40 my $cmd = [ '-nntpd', '-W0' ];
41 $td = start_script($cmd, { PI_CONFIG => $pi_config }, { 3 => $sock });
42 $host_port = tcp_host_port($sock);
43 $s = tcp_connect($sock);
45 my $buf = $s->getline;
46 like($buf, qr/\A201 .* ready - post via email\r\n/s, 'got greeting');
48 my $t = timeit(10, sub {
49 ok($s->print("GROUP $group\r\n"), 'changed group');
52 diag 'GROUP took: ' . timestr($t);
54 my ($tot, $min, $max) = ($buf =~ /\A211 (\d+) (\d+) (\d+) /);
55 ok($tot && $min && $max, 'got GROUP response');
58 my $nmin = $max - $nmax;
59 $nmin = $min if $nmin < $min;
61 my $spec = "$nmin-$max";
64 sub read_until_dot ($) {
69 } until $buf eq ".\r\n";
74 $s->print("XOVER $spec\r\n");
75 $n = read_until_dot($s);
77 diag 'xover took: ' . timestr($t) . " for $n";
80 $s->print("HDR From $spec\r\n");
81 $n = read_until_dot($s);
84 diag "XHDR From ". timestr($t) . " for $n";
86 my $date = $ENV{NEWNEWS_DATE};
88 my (undef, undef, undef, $d, $m, $y) = gmtime(time - 30 * 86400);
89 $date = sprintf('%04u%02u%02u', $y + 1900, $m + 1, $d);
90 diag "NEWNEWS_DATE undefined, using $date";
93 $s->print("NEWNEWS * $date 000000 GMT\r\n");
94 $n = read_until_dot($s);
96 diag 'newnews took: ' . timestr($t) . " for $n";
99 $s->print("QUIT\r\n");