Keep subscription fanout worker warm with adaptive linger policy by joshua-spacetime · Pull Request #4805 · clockworklabs/SpacetimeDB

Description of Changes

Similar to #4801, after we evaluate subscriptions on the main database thread, we send the results to a worker whose job it is to fan out the updates for the relevant clients. Hence we want to make sure this worker is not constantly parked on recv() as each send on the main thread will incur overhead waking the task.

To avoid this I've added a utility that wraps an mpsc UnboundedReceiver with an adaptive "linger" policy. On each message recv, the worker will now "linger" for a period of time and wait for any more messages before parking itself on the recv() again.

API and ABI breaking changes

None

Expected complexity level and risk

1

Testing

Manual performance testing for now. Automation to follow.