about summary refs log tree commit homepage
path: root/lib/PublicInbox/DS.pm
DateCommit message (Collapse)
2019-06-10ds: do not distinguish between POLLHUP and POLLERR
In my experience, both are worthless as any normal read/write call path will be wanting to check errors and deal with them appropriately; so we can just call event_read, for now. Eventually, there'll probably be only one callback for dealing with all in/out/err/hup events to simplify logic, especially w.r.t TLS socket negotiation.
2019-06-10ds: remove read method, here, too
Since we stop using it in NNTP, we don't need it at all.
2019-06-10ds: remove steal_socket method
We won't be needing it, not even for TLS support.
2019-06-10ds: remove {fd} field
Storing the file descriptor was redundant as we can quickly call fileno($self->{sock}) and not have to store an extra hash table entry. Multiple sources of truth leads to confusion, confusion leads to bugs.
2019-06-10ds: reduce Errno imports and drop ->close reason
ECONNRESET and EPIPE are common on a big Internet filled with unreliable connections, and there's nothing our code can do about it. So no point in wasting code to log them and there are plenty of tracing tools to choose from if such diagnostics are needed.
2019-06-10ds: cleanup Errno imports and favor constant comparisons
Stop importing unused constants, and favor integer comparisons of `$!' over `$!{EFOO}' hash lookups. Integer comparisons are slightly faster, even: Benchmark: timing 30 iterations of cmp_eq, cmp_ne, hash_hit, hash_miss... cmp_eq: 1 wallclock secs ( 1.61 usr + 0.00 sys = 1.61 CPU) @ 18.63/s (n=30) cmp_ne: 2 wallclock secs ( 1.57 usr + 0.00 sys = 1.57 CPU) @ 19.11/s (n=30) hash_hit: 4 wallclock secs ( 3.85 usr + 0.00 sys = 3.85 CPU) @ 7.79/s (n=30) hash_miss: 4 wallclock secs ( 3.74 usr + 0.00 sys = 3.74 CPU) @ 8.02/s (n=30) #!/usr/bin/perl -w use Benchmark qw(:all); use Errno qw(EAGAIN EINTR); my ($r, $w); pipe($r, $w) or die 'pipe'; require IO::Handle; $r->blocking(0); my $buf; my $n = 30000; timethese(30, { hash_hit => sub { sysread($r, $buf, 1); for (0..$n) { next if $!{EAGAIN}; die 'FAIL'; } } , 'cmp_eq' => sub { sysread($r, $buf, 1); for (0..$n) { next if $! == EAGAIN; die 'FAIL'; } }, hash_miss => sub { sysread($r, $buf, 1); for (0..$n) { die 'FAIL' if $!{EINTR}; } }, 'cmp_ne' => sub { sysread($r, $buf, 1); for (0..$n) { die 'FAIL' if $! == EINTR; } }, });
2019-06-10ds: simplify write buffer accounting
Keeping track of write_buf_size was redundant and pointless when we can simply check the number of elements in the buffer array. Multiple sources of truth leads to confusion; confusion leads to bugs. Finally, rename the prefixes to 'wbuf' to ensure we loudly (instead of silently) break any external dependencies being ported over from Danga::Socket, as further changes are pending.
2019-06-03ds: remove PLCMap and per-socket PostLoopCallback
We don't need and won't be needing per-socket PostLoopCallbacks.
2019-06-02ds: drop write_set_watch field
We never enable write watches ourselves for HTTP and NNTP, and only enable the write watch with EvCleanup because it's an "always on" watch.
2019-06-02ds: drop unused EVENT: label in epoll code path
This was never used in Danga::Socket 1.61, either.
2019-06-02ds: drop checks for invalid descriptors
I've used Danga::Socket for well over a decade in various projects at this point and have never seen the need for it. If such a bug ever happens; the process should fall over so it gets fixed ASAP.
2019-06-02ds: drop set_writer_func support
This is not used by perlbal for OpenSSL support, either; and it does not appear to be the right layer for doing write translations anyways (IO::Socket::SSL uses `tie').
2019-06-02ds: add a note about planned future changes
Sometimes I get bored with the email part of this project and need a distraction :P
2019-06-02ds: drop more unused subs
ToClose and HaveEpoll are of no use to us and I see no future use for them, either.
2019-06-01ds: fix and test for FD leaks with kqueue on ->Reset
Even though we currently don't use it repeatedly, ->Reset should close() kqueue FDs and not cause the process to run out of descriptors. Add a close-on-exec test while we're at it.
2019-06-01ds: set close-on-exec flag on epoll descriptors
We should not be leaking these FDs to git(1) processes, in case git has a bug that causes it to access the wrong FD.
2019-05-22DS: warn on deprecations
Enabling deprecation warnings didn't seem to have any noticeable effects with "perl -w -c", so whatever reason Danga had for it is long irrelevant.
2019-05-22DS: remove IPPROTO_TCP import
Unlike Danga::Socket, we do not support TCP_CORK, either
2019-05-22DS: drop $VERSION var
It was only relevant to Danga::Socket.
2019-05-22DS: remove support OtherFds code
It's easy enough to wrap FDs in classes that can use all of the functionality of the event loop, not just the read-only interface AddOtherFds provided.
2019-05-22DS: get rid of unused methods and aliases
"make syntax" is clean, now
2019-05-08DS: epoll: fix misordered EPOLL_CTL_DEL call
Any operations on an fd after POSIX::close() are invalid, so epoll_ctl will fail. Worse off, in a multi-threaded Perl, the fd may be reused by another thread and EPOLL_CTL_DEL can hit the wrong file description as a result. cf. https://rt.cpan.org/Ticket/Display.html?id=129487
2019-05-08DS: drop unused "_undef" sub
No longer used since we removed the *_ip_string fields
2019-05-08DS: handle EINTR in IO::Poll path, too
IO::Poll::_poll returns -1, which is "true" to Perl. cf. https://rt.cpan.org/Ticket/Display.html?id=129484
2019-05-05DS: workaround IO::Kqueue EINTR (mis-)handling
IO::Kqueue seems unmaintained, so workaround a long-standing bug where it falls over on signals: https://rt.cpan.org/Ticket/Display.html?id=116615
2019-05-05DS: drop profiling support
There's other ways to profile and we don't need to add runtime branches to do this.
2019-05-05DS: remove unused fields and functions
More will likely be dropped in the future, but drop the obvious ones we aren't using, for now; especially since some of them are set at ->new time and unavoidable. This saves 579 bytes per-client on my 64-bit Debian stable system as measured by Devel::Size::total_size from PublicInbox::HTTP::event_read. This adds up in C10K or C100K situations. Things we drop are: * corked - MSG_MORE requires fewer syscalls * read_push_back - tried to use it, ate CPU with slow clients * IP/port fields - accept() already returns what we care about
2019-05-05listener: use EPOLLEXCLUSIVE for listen sockets
Since our listen sockets are non-blocking and we may run multiple httpd|nntpd processes; we need a way to avoid thundering herds when there are multiple httpd|nntpd worker processes. EPOLLEXCLUSIVE was added just for that in Linux 4.5
2019-05-04bundle Danga::Socket and Sys::Syscall
These modules are unmaintained upstream at the moment, but I'll be able to help with the intended maintainer once/if CPAN ownership is transferred. OTOH, we've been waiting for that transfer for several years, now... Changes I intend to make: * EPOLLEXCLUSIVE for Linux * remove unused fields wasting memory * kqueue bugfixes e.g. https://rt.cpan.org/Ticket/Display.html?id=116615 * accept4 support And some lower priority experiments: * switch to EV_ONESHOT / EPOLLONESHOT (incompatible changes) * nginx-style buffering to tmpfile instead of string array * sendfile off tmpfile buffers * io_uring maybe?