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

Users supervision tree #175

Merged
merged 25 commits into from
Feb 21, 2024
Merged

Users supervision tree #175

merged 25 commits into from
Feb 21, 2024

Conversation

NelsonVides
Copy link
Collaborator

@NelsonVides NelsonVides commented Dec 16, 2023

Dedup controller and users sup #172

In the original implementation, the process is monitored by two supervisors, the original amoc_users_sup, and the amoc_controller one. But this means that bursts of ups and downs overflow the mailbox of two processes, one of them being actually the very critical controller.

With this reimplementation, only the amoc_users_sup tracks the processes, and all requests from the controller are asynchronous. This ensures the controller does not get blocked and can remain responsive to control requests.

Interarrival of zero #173

Useful if for example we want to spawn a big pool of users all at once. Optimised by not setting any timers, but simply looping new user requests.

Pool user supervision trees

If users go up and down too fast, amoc_users_sup becomes a bottleneck as it
can’t keep up with the requests. Improve the performance by creating a pool of
supervisors whose size is proportional to the number of schedulers, and ensure
distribution of users among them by for example hashing on the user_id.

We do this by creating a pool of amoc_users_worker_sup supervisors and having the whole API through amoc_users_sup choose supervisors according to requests.

@NelsonVides NelsonVides force-pushed the controller/interarrival_of_zero branch from 433ef34 to bd0690a Compare December 19, 2023 09:28
@NelsonVides NelsonVides force-pushed the controller/interarrival_of_zero branch from bd0690a to 56da56b Compare January 15, 2024 08:10
@NelsonVides NelsonVides changed the base branch from controller/interarrival_of_zero to master January 15, 2024 09:12
In the original implementation, the process is monitored by two supervisors, the
original amoc_users_sup, and the amoc_controller one. But this means that bursts
of ups and downs overflow the mailbox of _two_ processes, one of them being
actually the very critical controller.

With this reimplementation, only the amoc_users_sup tracks the processes, and
all requests from the controller are asynchronous. This ensures the controller
does not get blocked and can remain responsive to control requests.
Useful if for example we want to spawn a big pool of users all at once.
Optimised by not setting any timers, but simply looping new user requests.
If users go up and down too fast, amoc_users_sup becomes a bottleneck as it
can’t keep up with the requests. Improve the performance by creating a pool of
supervisors whose size is proportional to the number of schedulers, and ensure
distribution of users among them by for example hashing on the user_id.

We do this by creating a pool of supervisors and having the whole API through
`amoc_users_sup_sup` choose supervisors according to requests.
Have the user supervisors loop over the users start
instead of the controller.
@codecov-commenter
Copy link

codecov-commenter commented Jan 15, 2024

Codecov Report

Attention: 20 lines in your changes are missing coverage. Please review.

Comparison is base (9870612) 73.44% compared to head (623a89f) 75.00%.
Report is 14 commits behind head on master.

Files Patch % Lines
src/users/amoc_users_worker_sup.erl 77.19% 13 Missing ⚠️
src/users/amoc_users_sup.erl 94.73% 4 Missing ⚠️
src/amoc_controller.erl 90.32% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #175      +/-   ##
==========================================
+ Coverage   73.44%   75.00%   +1.55%     
==========================================
  Files          29       31       +2     
  Lines        1043     1160     +117     
==========================================
+ Hits          766      870     +104     
- Misses        277      290      +13     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@NelsonVides NelsonVides marked this pull request as ready for review January 15, 2024 15:56
@NelsonVides NelsonVides changed the title Users/pool supervision tree Users supervision tree Jan 15, 2024
Copy link
Collaborator

@DenysGonchar DenysGonchar left a comment

Choose a reason for hiding this comment

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

this new implementation sufferrs from the same issues as the existing one. removal operation is async and if we call amoc_controller:remove_users/2 two times in a row, it may select the same users for removal. so it won't remove the expected amount of users (the number returned by amoc_controller:remove_users/2). I don't think that we need to worry about it, but we must to add a note in the documentation about this behaviour.

stop(Pid, false) when is_pid(Pid), Pid =/= self() ->
proc_lib:stop(Pid, shutdown, ?SHUTDOWN_TIMEOUT);
stop(Pid, true) when is_pid(Pid), Pid =/= self() ->
proc_lib:stop(Pid, kill, ?SHUTDOWN_TIMEOUT).
Copy link
Collaborator

Choose a reason for hiding this comment

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

this implementation is not acceptable, we should never kill the user without giving it a chance to finalize its jobs. this interface must be based on some amoc_users_worker_sup API. The code must be unified, SHUTDOWN_TIMEOUT must be defined at amoc_users_worker_sup only.

src/users/amoc_user.erl Outdated Show resolved Hide resolved
.github/workflows/ci.yml Outdated Show resolved Hide resolved
integration_test/extra_code_paths/path2/dummy_scenario.erl Outdated Show resolved Hide resolved
src/amoc_controller.erl Show resolved Hide resolved
src/users/amoc_users_sup.erl Outdated Show resolved Hide resolved
src/users/amoc_users_sup.erl Outdated Show resolved Hide resolved
src/users/amoc_users_sup.erl Outdated Show resolved Hide resolved
src/users/amoc_users_sup.erl Outdated Show resolved Hide resolved
src/users/amoc_users_worker_sup.erl Outdated Show resolved Hide resolved
@NelsonVides NelsonVides force-pushed the users/pool_supervision_tree branch 5 times, most recently from 7effd57 to 29d9ea2 Compare February 21, 2024 11:10
@NelsonVides NelsonVides force-pushed the users/pool_supervision_tree branch 2 times, most recently from b55455c to 8ad85c5 Compare February 21, 2024 11:36
Copy link
Collaborator

@DenysGonchar DenysGonchar left a comment

Choose a reason for hiding this comment

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

thanks for the huge amount of work, it looks really greate :)

@DenysGonchar DenysGonchar merged commit 7b1ea3d into master Feb 21, 2024
6 checks passed
@DenysGonchar DenysGonchar deleted the users/pool_supervision_tree branch February 21, 2024 22:14
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