Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(multiplexer): Allow fine-grained control of concurrency strategy #106

Merged
merged 7 commits into from
Jun 4, 2022

Conversation

scarmuega
Copy link
Member

This PR removes the hardcoded threads from inside the multiplexer and provides fine-grained methods for the implementor to decide how to approach concurrency.

A multiplexer is now divided into two different structs: Muxer and Demuxer. Each of this structures provides the following methods:

  • tick: to perform a single atomic mux / demux operation.
  • block: to enter a continuous loop of muxing / demuxing operations, blocking the thread indefinitely.

To achieve the same thread-based concurrency as before, two helper methods are included as part of the refactoring: spawn_muxer and spawn_demuxer, which creates a thread that performs the corresponding block operation.

Having the low-level operations exposed to the library consumer opens up the possibility to explore other concurrency mechanism:

  • no concurrency: single thread where muxer, demuxer and mini-protocols tick sequentially
  • single-thread per bearer: use a single thread for muxer / demuxer and different threads for miniprotocols
  • async (maybe?): treat each muxer / demuxer loop as a stream of futures
  • rayon join mechanism (maybe?): single loop where muxer / demuxer ticks are parallelized only if threads are available

@scarmuega scarmuega requested review from rvcas and SmaugPool May 28, 2022 15:53
rvcas
rvcas previously approved these changes May 28, 2022
@scarmuega scarmuega merged commit a39682a into main Jun 4, 2022
@scarmuega scarmuega deleted the feat/new-multiplexer branch June 4, 2022 00:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants