-
Notifications
You must be signed in to change notification settings - Fork 159
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
refactor: Split PendingSession
Scheduler into PendingSession
Scheduler and AgentSelector
#1655
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
github-actions
bot
added
comp:manager
Related to Manager component
size:XL
500~ LoC
labels
Oct 25, 2023
jopemachine
force-pushed
the
fix/improve-rr
branch
from
October 26, 2023 06:16
b51a9fe
to
0eeebf7
Compare
jopemachine
changed the title
fix - Replace RoundRobin flag with AgentSelectionStrategy.RoundRobin (WIP)
fix - Replace RoundRobin flag with AgentSelectionStrategy.RoundRobin
Oct 26, 2023
jopemachine
changed the title
fix - Replace RoundRobin flag with AgentSelectionStrategy.RoundRobin
fix - Replace Oct 26, 2023
roundrobin
flag with AgentSelectionStrategy.RoundRobin
strategy
jopemachine
changed the title
fix - Replace
fix: Replace Oct 26, 2023
roundrobin
flag with AgentSelectionStrategy.RoundRobin
strategyroundrobin
flag with AgentSelectionStrategy.RoundRobin
strategy
jopemachine
force-pushed
the
fix/improve-rr
branch
from
March 27, 2024 03:33
f970a82
to
a2dec4f
Compare
achimnol
force-pushed
the
fix/improve-rr
branch
from
August 24, 2024 14:52
a2dec4f
to
cddfa71
Compare
jopemachine
changed the title
fix: Replace
refactor: Aug 28, 2024
roundrobin
flag with AgentSelectionStrategy.RoundRobin
strategyPendingSession
Scheduler to PendingSession
Scheduler and AgentSelector
jopemachine
changed the title
refactor:
refactor: Split Aug 28, 2024
PendingSession
Scheduler to PendingSession
Scheduler and AgentSelector
PendingSession
Scheduler into PendingSession
Scheduler and AgentSelector
jopemachine
force-pushed
the
fix/improve-rr
branch
2 times, most recently
from
August 30, 2024 04:38
005bf74
to
b49812c
Compare
… AgentSelectorStore
…lt setting in the scheduler-side instantiation
- Collect round-robin related stuffs around the location of RoundRobinAgentSelector class
- State keys and values are now perfectly specific to the caller.
achimnol
force-pushed
the
fix/improve-rr
branch
from
September 16, 2024 15:50
1e7f33b
to
cc15f8d
Compare
achimnol
added
the
require:db-migration
Automatically set when alembic migrations are added or updated
label
Sep 16, 2024
achimnol
approved these changes
Sep 16, 2024
1 task
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
comp:manager
Related to Manager component
require:db-migration
Automatically set when alembic migrations are added or updated
size:XL
500~ LoC
type:refactor
Refactor codes or add tests.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Follow up PR of #1405.
roundrobin
flag toAgentSelectionStrategy
.Why
The existing session scheduler code has made confusion as it mixed session scheduling logic with the agent selection logic. This PR removes the confusion by separating the responsibilities into two classes:
Scheduler
andAgentSelector
.And since most of the logic related to the RoundRobin flag pertains to the
AgentSelector
, the flag has been changed to a policy within theAgentSelectionStrategy
.Refactoring Details
Introduce
AgentSelector
with Generic ABCAbstractAgentSelector(Generic[T_ResourceGroupState], ABC)
where
T_ResourceGroupState = TypeVar(..., bound=ResourceGroupState)
BaseAgentSelector(AbstractAgentSelector[T_ResourceGroupState])
LegacyAgentSelector(BaseAgentSelector[NullAgentSelectorState])
ConcentratedAgentSelector(BaseAgentSelector[NullAgentSelectorState])
DispersedAgentSelector(BaseAgentSelector[NullAgentSelectorState])
RoundRobinAgentSelector(BaseAgentSelector[RRAgentSelectorState])
These are the materialization of hard-coded logic branches in prior versions. They have a resource group state store object to load/store persistent states across subsequent scheduler invocations. The type of resource group states are determined by the type argument, so that the agent selection logic could read/write them without extra type casting and conversion.
Introduce
ResourceGroupState
with ABC and type variableResourceGroupState(pydantic.BaseModel, ABC)
NullAgentSelectorState(ResourceGroupState)
RRAgentSelectorState(ResourceGroupState)
AbstractResourceGroupStateStore(Generic[T_ResourceGroupState], ABC)
declares
load()
,store()
, andreset()
methods for per-resource-group states.DefaultResourceGroupStateStore(AbstractResourceGroupStateStore[T_ResourceGroupState])
InMemoryResourceGroupStateStore(AbstractResourceGroupStateStore[T_ResourceGroupState])
It is a thin abstraction to inject an interface to load/store arbitrary states represented as a pydantic model from/to an internal state storage. Currently the default implementation uses the etcd (
shared_config
) as a storage backend with a key prefixresource-group-states
. The in-memory version is for writing test codes.Note
The prior implementation has stored the RR state in the
roundrobin_states
etcd key. This key is neither removed or migrated in this PR. Admins may delete it manually.The ABC
ResourceGroupState
mandates implementation of the classmethodcreate_empty_state()
so that the system can always fill the initial value when the administrator changes to a new agent selector.Since there may be multiple agent selectors and possibly other per-resource-group entities that want to use resource group states, the
load()
,store()
, andreset()
methods in the state store takes an explicitstate_name
argument to distinguish them within each resource group. The state name is up to the caller of the state store API; the agent selector implementation in this PR.Other
agent_selection_resource_priority
intoAbstractAgentSelector
to avoid passing it all related functions each time.KernelInfo
withKernelRow
ofassign_agent_for_kernel
.Database migration
The migration script transforms the
roundrobin
flag to a value of theagent_selection_strategy
field in thescaling_groups.scheduler_opts
column if settrue
. It also adds a new empty object as theagent_selector_config
field.How to test the RoundRobin agent selection strategy
To manually test the round-robin mode, please refer to this section.
agent_selection_strategy
, change theagent_selection_strategy
inscaling_groups.scheduler_opts
toroundrobin
using the below command../backend.ai mgr etcd put config/redis/addr <manager_addr>:8111
rpc-listen-addr
,id
of theagent
section in each agent'sagent.toml
.next_index
forround_robin
state is correctly updated in etcd.Checklist: (if applicable)