PoC: Use event bus to retrieve PeerCount from PeerPool by another process #1202
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What is this?
This is another PoC to demonstrate the concept of using an event bus for inter process communication. This time, a new independent process is interacting with the event bus to receive the current peer count from the
PeerPool
.Keep in mind this is a PoC. It is full of bugs and poor ergonomics
What happens:
PeerCountRequest
on the event bus every secondPeerCountResponse
objectsPeerPool
on the other hand listens forPeerCountRequest
and answers them withPeerCountResponse
Known issues
There's seems to be something wrong with the event loop. I could only get things to work if we don't
spawn
but ratherfork
processes. However, while that makes things work somehow I'm seeing duplicate log entries with that.The communication could be much much more efficient. Currently, the event bus just fans out each and every event to every participating process. In practice, we will want to limit the direction and flow of events to not waste resources
I anticipate the event bus being used a lot for loose async communication with one sender and many receivers. However, as demoed in this PoC, the event bus can also be used for classical request / response type of work. That said, currently the API for that simply doesn't exist and combining
broadcast
andstream
is both unergonomic and wasteful. It wouldn't be too hard to build the following API that would enable a simple request/response pattern between only two actors (without broadcasting to each and every participating actor)