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: add basic actor model #29

Merged
merged 7 commits into from
Nov 27, 2022
Merged

feat: add basic actor model #29

merged 7 commits into from
Nov 27, 2022

Conversation

Keith-CY
Copy link
Member

@Keith-CY Keith-CY commented Nov 16, 2022

This PR adds the actor model in a basic format for future development, an actor should have

  • ref: reference to the actor;
  • static method call/cast: send call/cast request to the message queue;
  • instance method call/cast: wrapped static method call/cast;
  • handleCall/handleCast: unified API to handle messages, and the messages will be delegated to user-defined business methods.

Only actor is the key module implemented in this PR so it's covered by unit tests,
message-queue will be replaced with redis stream
and registry will be replaced with inversify so they are not covered by tests.

Besides, an example of how to use actors is added in src/examples/app

Ref: #4

@Keith-CY Keith-CY force-pushed the add-kuai-components branch 2 times, most recently from e6ab5f0 to bdf0c8b Compare November 16, 2022 19:36
@Keith-CY Keith-CY added the enhancement New feature or request label Nov 17, 2022
@Keith-CY Keith-CY added this to the 2022/11/17 - 2022/11/24 milestone Nov 17, 2022
@Keith-CY Keith-CY force-pushed the add-kuai-components branch 4 times, most recently from 223293d to 0510aff Compare November 21, 2022 03:31
@Keith-CY Keith-CY marked this pull request as ready for review November 21, 2022 03:45
@Keith-CY Keith-CY changed the title wip: add actor model feat: add basic actor model Nov 21, 2022
@Keith-CY
Copy link
Member Author

Keith-CY commented Nov 21, 2022

The most basic actor model is added for other components to interact, and an example of how the model should run is added in this PR, please have a review @PainterPuppets @felicityin @yanguoyu

@Keith-CY Keith-CY self-assigned this Nov 21, 2022
packages/models/src/actor/interface.ts Outdated Show resolved Hide resolved
packages/models/src/actor/interface.ts Outdated Show resolved Hide resolved
packages/models/src/actor/message-queue.ts Show resolved Hide resolved
@Keith-CY Keith-CY mentioned this pull request Nov 23, 2022
3 tasks
@felicityin
Copy link
Contributor

Does a example of communication between two actors need to be added?

@Keith-CY
Copy link
Member Author

Does a example of communication between two actors need to be added?

The example in the PR shows how actors communicate with each other, the root actor requests its child to increment its state by one and gets a response saying the child one has updated its state.

> handle call request from root with symbol Symbol(one)
> /root: increment 1
> handle cast request from child_one with symbol Symbol(done)
> task is done

@felicityin
Copy link
Contributor

Does a example of communication between two actors need to be added?

The example in the PR shows how actors communicate with each other, the root actor requests its child to increment its state by one and gets a response saying the child one has updated its state.

> handle call request from root with symbol Symbol(one)
> /root: increment 1
> handle cast request from child_one with symbol Symbol(done)
> task is done

I see it.

@felicityin felicityin self-requested a review November 24, 2022 08:08
@Keith-CY Keith-CY force-pushed the add-kuai-components branch from 2f1dccf to b7ac004 Compare November 25, 2022 07:09
@Keith-CY
Copy link
Member Author

Please have a review @PainterPuppets

Copy link
Contributor

@PainterPuppets PainterPuppets left a comment

Choose a reason for hiding this comment

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

The main idea delivered by the actor model is Divide-and-Conquer. If a heavy task is assigned to actor_a, the task would be split into sub-tasks and delegated to actor_a's child actors, recursively, until sub-tasks are small enough to be handled in one piece.

Is this part of the documentation implemented in another pr?

The current code does not seem to describe the behavior between parents and children

@Keith-CY
Copy link
Member Author

The main idea delivered by the actor model is Divide-and-Conquer. If a heavy task is assigned to actor_a, the task would be split into sub-tasks and delegated to actor_a's child actors, recursively, until sub-tasks are small enough to be handled in one piece.

Is this part of the documentation implemented in another pr?

The current code does not seem to describe the behavior between parents and children

How to model users' business logic depends on their goals and kuai won't tell users how to split their tasks.

But one target of kuai is to help users to divide their big task into small tasks easily and suitable for cell model so some paradigms are adopted in kuai and expected to prevail in dapps built on kuai. Once these paradigms prevades, interoperability among dapps would increase.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

4 participants