Skip to content

Add actor concurrency model(similar to Elixir) #17214

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

Open
wants to merge 13 commits into
base: compatible
Choose a base branch
from
Open

Conversation

glyh
Copy link
Member

@glyh glyh commented May 18, 2025

Next in train: #17224

NOTE: CI Nightly is passing in the last PR in this train: #17225

NOTE2: This indeed needs careful review, I've spotted several bugs already.

Purpose

This is Actor model, going to be used to refactor transition router. Well, not strictly because it also supports a server model where an actor could process requests and return responses.

Potential Improvements

For now we only have 3 inboxes for an Actor: request, control and data, in that priority order. request support handling dependently typed requests defined by GADTs. control is just a normal queue that never drops any messages. data is supposed to partially simulate strict_pipe's behavior.

This model could be generalized to any number of channels. Utilizing Heterogeneous Lists. This could further be refactored using a heterogeneous priority queue so messages can have customized priority. But it seems for now we don't have a good use case of such actor.

Benefits

Hooking into an actor

If everything is modeled as actor, we could design a supervisor system by hooking into Actor implementation, and then we can have a good flamegraph implementation knowing at which time, which actor is running.

Inspecting an actor

You could just look into the struct to inspect what messages in queue an actor has, and its state. Previously all such abstraction is inside lambda functions -- You just can't identify an lambda without some quirks I guess.

Mitigate concurrency issues

The very reason I'm trying to introduce this is Transition_router has some nasty synchronization bugs, I haven't been able to figure out the fix even knowing the issue. One of the blockers is that there's virtually no good way to debug Async code due to everything being lambda, and abusing don't_wait_for made the code worse.

@glyh glyh requested a review from a team as a code owner May 18, 2025 07:32
@glyh glyh changed the title Actor: add actor concurrency model(similar to Elixir) Add actor concurrency model(similar to Elixir) May 18, 2025
@glyh glyh force-pushed the corvo/actor-2 branch 9 times, most recently from 892ba18 to 928e19f Compare May 18, 2025 10:17
@glyh glyh force-pushed the corvo/actor-2 branch from 928e19f to 4a0a196 Compare May 18, 2025 10:53
@glyh glyh force-pushed the corvo/actor-2 branch from 4a0a196 to 1eb8d75 Compare May 18, 2025 11:02
@glyh
Copy link
Member Author

glyh commented May 18, 2025

!ci-build-me

@dannywillems
Copy link
Member

!ci-bypass-changelog

@glyh
Copy link
Member Author

glyh commented May 18, 2025

It seems buildkite still requires a change log

NVM, somehow rerun CI fixed the issue.

@glyh
Copy link
Member Author

glyh commented May 19, 2025

!ci-build-me

@glyh glyh force-pushed the corvo/actor-2 branch from f4eaa7c to 3a27745 Compare May 19, 2025 14:30
@glyh
Copy link
Member Author

glyh commented May 19, 2025

!ci-build-me

MNext state
| RExit resp ->
(* NOTE: for some reason OCaml can't infer this type here *)
Ivar.fill response_ivar (Obj.magic resp) ;
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately OCaml can't infer the type here :(

@glyh
Copy link
Member Author

glyh commented May 20, 2025

!ci-build-me

Copy link
Member

@georgeee georgeee left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a doc-comment to each module defined in actor.ml.

Please describe tests in terms of which workflow they simulate and how.

@glyh
Copy link
Member Author

glyh commented May 21, 2025

Added all descriptions in a interface file.

@glyh
Copy link
Member Author

glyh commented May 21, 2025

!ci-build-me

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.

3 participants