user/dev discussion of public-inbox itself
 help / color / mirror / code / Atom feed
* [RFC] nntp: improve fairness during XOVER and similar commands
@ 2018-03-07  9:52 Eric Wong
  0 siblings, 0 replies; only message in thread
From: Eric Wong @ 2018-03-07  9:52 UTC (permalink / raw)
  To: meta

For other commands generating long responses, we generally want
to yield to another client after emitting 100 .  However,
XOVER-based responses already query 200 lines worth of responses
at a time, so we were sending 20000 lines before yielding to
other clients.  This may help avoid timeouts for some clients.
---
 lib/PublicInbox/NNTP.pm | 13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)

diff --git a/lib/PublicInbox/NNTP.pm b/lib/PublicInbox/NNTP.pm
index 56d8e01..1e56463 100644
--- a/lib/PublicInbox/NNTP.pm
+++ b/lib/PublicInbox/NNTP.pm
@@ -590,9 +590,10 @@ sub long_response ($$$$) {
 
 		my $err;
 		do {
-			eval { $cb->(\$beg) };
+			eval { $cb->(\$beg, \$lim) };
 		} until (($err = $@) || $self->{closed} ||
-			 ++$beg > $end || !--$lim || $self->{write_buf_size});
+			 ++$beg > $end || --$lim < 0 ||
+			 $self->{write_buf_size});
 
 		if ($err || $self->{closed}) {
 			$self->{long_res} = undef;
@@ -609,7 +610,7 @@ sub long_response ($$$$) {
 				update_idle_time($self);
 				$self->watch_read(1);
 			}
-		} elsif (!$lim || $self->{write_buf_size}) {
+		} elsif ($lim < 0 || $self->{write_buf_size}) {
 			# no recursion, schedule another call ASAP
 			# but only after all pending writes are done
 			update_idle_time($self);
@@ -715,11 +716,12 @@ sub hdr_searchmsg ($$$$) {
 		more($self, $xhdr ? r221 : r225);
 		my $off = 0;
 		long_response($self, $beg, $end, sub {
-			my ($i) = @_;
+			my ($i, $lim) = @_;
 			my $res = $srch->query_xover($beg, $end, $off);
 			my $msgs = $res->{msgs};
 			my $nr = scalar @$msgs or return;
 			$off += $nr;
+			$$lim -= $nr;
 			my $tmp = '';
 			foreach my $s (@$msgs) {
 				$tmp .= $s->num . ' ' . $s->$field . "\r\n";
@@ -853,11 +855,12 @@ sub cmd_xover ($;$) {
 	my $srch = $self->{ng}->search;
 	my $off = 0;
 	long_response($self, $beg, $end, sub {
-		my ($i) = @_;
+		my ($i, $lim) = @_;
 		my $res = $srch->query_xover($beg, $end, $off);
 		my $msgs = $res->{msgs};
 		my $nr = scalar @$msgs or return;
 		$off += $nr;
+		$$lim -= $nr;
 
 		# OVERVIEW.FMT
 		more($self, join("\r\n", map {
-- 
EW


^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2018-03-07  9:52 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-07  9:52 [RFC] nntp: improve fairness during XOVER and similar commands Eric Wong

Code repositories for project(s) associated with this public 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).