Each pollset in pollex has a lock, grabbed upon adding an FD
to the pollset. Since this is called on a per-call basis,
there is a flat array caching the FDs of the pollset, to
avoid unnecessarily calling epoll_ctl multiple times for
the same FD.
This has two problems:
1) When multiple threads add FDs to the same pollset,
we will have contention on the pollset lock.
2) When we have many FDs we simply run out of cache storage,
and call epoll_ctl().
This commit changes the caching strategy by simply storing
the pollsets of an FD inside that FD, when we are in PO_MULTI
mode. This results in address in both (1) and (2).
Moreover, this commit fixes another performance bug.
When we have a release FD callback, we do not call close().
That FD will remain in our epollset, until the new owner of
the FD actually call close(). This results in a lot of spurious
wake ups when we simply hand off gRPC FDs to other FDs.
There were spurious TSAN errors on PR #17823 because
TSAN doesn't really understand how `g_uncovered_notifications_pending`
works. It's odd in the sense that we destroy the backup
poller, when the ref count reaches 1 (instead of 0 which is commonly
used).
Prior to PR #17823, TSAN doesn't complain because we (unnecessarily)
always grab the pollset's lock, which TSAN understands.
This commit uses full_fetch_add to explain the synchronization
primitive to TSAN.
Python 3 exceptions include a `__traceback__` attribute that includes
refs to all local variables. Saving the exception results in leaking
references to the, among other things, the Cython grpc_call wrapper and
prevents garbage collection and release of core resources, even after
the server is shutdown.
See
https://www.python.org/dev/peps/pep-3134/#open-issue-garbage-collection
Ref-counted and inlined slices both have a lenght value, but
they are not in the same byte offset. As a result, we will
have two different loads based on a branch.
Instead move them to the same byteoffset, so that we will have
one move and the same number of branches.
Difference can be seen on:
https://godbolt.org/z/kqFZcP