Skip to content
This repository has been archived by the owner on Feb 28, 2023. It is now read-only.

Proposal for threading and syscall interface redesign #66

Open
lachlansneff opened this issue Aug 7, 2018 · 2 comments
Open

Proposal for threading and syscall interface redesign #66

lachlansneff opened this issue Aug 7, 2018 · 2 comments
Labels
design Design Discussions enhancement New feature or request help wanted Extra attention is needed

Comments

@lachlansneff
Copy link
Contributor

lachlansneff commented Aug 7, 2018

Asynchronous code seems to be all the rage these days. I figured out a way of implementing coroutines in Nebulet that appear to be normal threads to the user, but are, in fact, lightweight coroutines. This would allow the syscall interface to be completely asynchronous, but actually appear to be blocking. This would simplify writing applications for Nebulet and improve performance.

This would involve removing preemption for threads and each process would only run on a single core at a time (essentially making processes the defacto unit of true concurrency), eliding the need for expensive synchronization.

Gist

  • No preemption at the thread level. A process only executes on one cpu at a time.
  • Create threads normally, but thread switching code is injected at specific points, like external function calls and in some loops.
  • To run on multiple cpus, create multiple processes.
  • To the user, threads appear to be fully-preemptive, but under the hood, they are coroutines.
  • Can mark spots as thread switch locations and mark functions where no thread switches should be generated.

Advantages

  • May result in better overall performance.
  • No locks or atomics are necessary for tables or thread queues.
  • The syscall interface can appear to be blocking, but actually be asynchronous.
  • No language support required for coroutines.

Disadvantages

  • May constrict some usages.

Design Challenges

  • Requires some way of generating and saving new wasm stacks.
  • Requires a complete rewrite of the threading support in Nebulet.

Thoughts?

@lachlansneff lachlansneff added enhancement New feature or request help wanted Extra attention is needed design Design Discussions labels Aug 7, 2018
@AleVul
Copy link

AleVul commented Aug 9, 2018

would only allow a single cpu to run in a process at a time

wouldn't this mean that the number of processes that can run at one time is limited by the number of cpu's?

To run on multiple cpus, create multiple processes.

I guess this would negate the speed bump gained from not synchronizing threads since the process has to consider clones of itself that access same resources.

@lachlansneff
Copy link
Contributor Author

@AleVul I think I didn't describe that part well enough. It's not that each core gets pinned to a process, it's just that a process will only run on a single core at a time.

The second part would have to be determined when and if this idea is actually implemented. Since the processes could share their linear memory, any synchronization would be controlled by whatever code is running there, same as any normal multithreaded code

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
design Design Discussions enhancement New feature or request help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants