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

Detsim in golang #2

Open
vitorguidi opened this issue Feb 5, 2024 · 2 comments
Open

Detsim in golang #2

vitorguidi opened this issue Feb 5, 2024 · 2 comments

Comments

@vitorguidi
Copy link

vitorguidi commented Feb 5, 2024

I noticed there is a seed for the testing in the screenshot for this repo, which belongs to a deterministic simulation, tiger beetle style. Having said that, is there any reason why the same approach would not be possible in golang?

Asking because I intend to implement raft, but I do not want to learn rust in order to do that. Also, I do not see a detsim in your previous go implementation, so this made me wonder if there is any language level restriction, in order to do it in go.

@eatonphil
Copy link
Owner

Yeah that was a sketch to see if it was feasible in Rust. The gist for Rust and Go is that either threads/goroutines themselves or synchronizing between them is nondeterministic. So you'd need to do the whole thing single-threaded which means you need some sort of async io. But neither Go nor Rust have builtin support for async io. Which would make an implementation without third-party libraries (which I prefer to do) pretty cumbersome.

@vitorguidi
Copy link
Author

vitorguidi commented Feb 19, 2024

It might be a very dumb question, but I honestly do not understand why:

So you'd need to do the whole thing single-threaded which means you need some sort of async io

To be more precise, the jump from determinism to async io is not immediately clear to mel

Gonna throw my mental model here, on how async IO can help achieve determinism. Please help me understand the gist of it:

  • Main program is called, we define an executor and a scheduler (from the java world). All of them are running on the same thread
  • We launch servers and clients as async tasks (ie, raft server), and they get scheduled
  • Main program (simulation) delegates control to the scheduler
  • Scheduler gets first in priority queue, pops it, runs in executor
  • Executor gladly runs raft client, async operations within the client are enqueued in the executor; Whenever we find an await statement, raft client yields control;
  • Scheduler gets control back, pops from PQ, tosses to executor
  • Repeat until done, insert invriant assertions in between

Is that how it works? Trying to form a mental model as I read here => https://jbaker.io/2022/05/09/project-loom-for-distributed-systems/

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

No branches or pull requests

2 participants