-
Notifications
You must be signed in to change notification settings - Fork 9
Description
What's needed?
The Sender class provides an async send() method, but most (if not all) our senders could currently send synchronously 1. Being async means that the control flow/CPU could be taken away from the caller, which is very inconvenient for cases where sync is guaranteed.
Proposed solution
Split Sender into SyncSender and AsyncSender (probably make them protocols instead of classes). SyncSender would provide a sync send() and AsyncSender would provide a async asend().
Use cases
- Data sourcing actor: Add & use close channel method in the registry frequenz-sdk-python#225 (comment)
- The resampling actor (
Resamplerclass) can also benefit from this, now the resampling functions need to beasyncbecausesend()isasync: https://github.com/frequenz-floss/frequenz-sdk-python/blob/ce6d19b869ed26c4df1e08a332f4e4fa4cbfc199/src/frequenz/sdk/timeseries/_resampling.py#L711-L716 - There could be channels that only provide a sync or an async sender interface.
- Broadcast channel could implement senders that support both operations,
send()would drop like now andasend()would wait until the queue has room for the message.
Alternatives and workarounds
Currently the Data sourcing actor is just spawning tasks for sending and assuming they will eventually finish, and successfully, as there is no error handling for the spawned tasks and if they don't end, we'll be leaking dangling tasks forever.
Additional context
- Even if we don't have
AsyncSenders now, we will probably need them in the future, at least for this issue: Have a way to avoid dropping messages in broadcast channels #20 - Experiment using
sync send()in the Data sourcing actor:
Footnotes
-
Actually, with the removal of
Bidirectional, now we only have 2 types of channels and 1 is sync (broadcast) and the other one is async (anycast). There is also an issue about having an option to makeBroadcastsenders block too. ↩
Metadata
Metadata
Assignees
Labels
Type
Projects
Status