From a1a8cbab22adec879f97dccd9acfd0c5b2492ba9 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 16 Oct 2021 01:00:54 +0000 Subject: imapd+nntpd: drop timer-based expiration It's needlessly complex and O(n), so it doesn't scale well to a high number of clients nor is it easy-to-scale with the data structures available to us in pure Perl. In any case, I see no evidence of either -imapd nor -nntpd experiencing high connection loads on public-facing sites. -httpd has never had its own timer-based expiration, either. Fwiw, public-inbox.org itself has been running a public-facing HTTP/HTTPS server with no userspace idle client expiration for the past 8 years or with no ill effect. Clients can come and go as they wish, and SO_KEEPALIVE takes care of truly broken connections if they're gone for ~2 hours. Internet connections drop all time, so it should be harmless to drop connections w/o warning since both NNTP and IMAP protocols have well-defined semantics for determining if a message was truncated (as does HTTP/1.1+). --- lib/PublicInbox/DS.pm | 37 +------------------------------------ 1 file changed, 1 insertion(+), 36 deletions(-) (limited to 'lib/PublicInbox/DS.pm') diff --git a/lib/PublicInbox/DS.pm b/lib/PublicInbox/DS.pm index 9cca02d7..bf8c4466 100644 --- a/lib/PublicInbox/DS.pm +++ b/lib/PublicInbox/DS.pm @@ -37,9 +37,7 @@ our @EXPORT_OK = qw(now msg_more dwaitpid add_timer add_uniq_timer); my %Stack; my $nextq; # queue for next_tick my $wait_pids; # list of [ pid, callback, callback_arg ] -my $EXPMAP; # fd -> idle_time -our $EXPTIME = 180; # 3 minutes -my ($reap_armed); +my $reap_armed; my $ToClose; # sockets to close when event loop is done our ( %DescriptorMap, # fd (num) -> PublicInbox::DS object @@ -76,7 +74,6 @@ sub Reset { # we may be iterating inside one of these on our stack my @q = delete @Stack{keys %Stack}; for my $q (@q) { @$q = () } - $EXPMAP = undef; $wait_pids = $nextq = $ToClose = undef; $ep_io = undef; # closes real $Epoll FD $Epoll = undef; # may call DSKQXS::DESTROY @@ -251,9 +248,6 @@ sub PostEventLoop () { $ToClose = undef; # will be autovivified on push @$close_now = map { fileno($_) } @$close_now; - # order matters, destroy expiry times, first: - delete @$EXPMAP{@$close_now}; - # ->DESTROY methods may populate ToClose delete @DescriptorMap{@$close_now}; } @@ -655,35 +649,6 @@ sub dwaitpid ($;$$) { } } -sub expire_old () { - my $cur = $EXPMAP or return; - $EXPMAP = undef; - my $old = now() - $EXPTIME; - while (my ($fd, $idle_at) = each %$cur) { - if ($idle_at < $old) { - my $ds_obj = $DescriptorMap{$fd}; - $EXPMAP->{$fd} = $idle_at if !$ds_obj->shutdn; - } else { - $EXPMAP->{$fd} = $idle_at; - } - } - add_uniq_timer('expire', 60, \&expire_old) if $EXPMAP; -} - -sub update_idle_time { - my ($self) = @_; - my $sock = $self->{sock} or return; - $EXPMAP->{fileno($sock)} = now(); - add_uniq_timer('expire', 60, \&expire_old); -} - -sub not_idle_long { - my ($self, $now) = @_; - my $sock = $self->{sock} or return; - my $idle_at = $EXPMAP->{fileno($sock)} or return; - ($idle_at + $EXPTIME) > $now; -} - 1; =head1 AUTHORS (Danga::Socket) -- cgit v1.2.3-24-ge0c7