Skip to content

Improve scheduler actor#63

Open
TheHeroBrine422 wants to merge 25 commits into
mainfrom
caleb/fix-scheduler-actor-cache
Open

Improve scheduler actor#63
TheHeroBrine422 wants to merge 25 commits into
mainfrom
caleb/fix-scheduler-actor-cache

Conversation

@TheHeroBrine422

Copy link
Copy Markdown
Contributor

intended changes for this PR

  • improve actor cache
    • currently the actor cache is setup in a way that doesn't really support the scheduler updating it when messages happen. this makes the cache very difficult to use because it can't be relied on for up to date information which means we can barely use it as a cache. a specific issue i hit with this was trying to implement affinity/placement groups. if we rely on the cache data for calculating affinity, we could break the affinity rules due to race conditions.
    • i am replacing the generic version I made with one that is just integrated into the scheduler directly, because otherwise I don't really feel comfortable doing direct modifications to the cache in other segments of the scheduler
    • on top of this, the vm cache arguably needs slightly different code because we basically need the ability to query by either actor id or vmid, and so it needed some sort of modification to support this either way.
    • todo: have messages sent to scheduler directly update the cache
  • Placement groups #28
  • improve scheduling algorithm
    • i realized that currently the scheduling algorithm doesnt consider the resource requirements of the new vm. so for example if an agent had 15/16 vcpus scheduled, and then a new VM was to be scheduled that needed another 16 vcpus, it could theoretically schedule it to that agent. which would be bad

All that is left is testing and review by another maintainer.

this was done for two reasons:
1) the vm and agent actor caches have slightly different requirements,
specifically around keys (actorid vs vmid)
2) the scheduler needs direct control of the cache so the cache can be
updated in response to messages it forwards. being possibly up to 1
second out of date in this data could cause problems. In theory the
scheduler could update the generic cache, but I don't think using a
generic cache if we need to modify it directly anyway really makes
sense.

Signed-off-by: Caleb Jones <caleb@calebgj.io>
Signed-off-by: Caleb Jones <caleb@calebgj.io>
Signed-off-by: Caleb Jones <caleb@calebgj.io>
Signed-off-by: Caleb Jones <caleb@calebgj.io>
Signed-off-by: Caleb Jones <caleb@calebgj.io>
Signed-off-by: Caleb Jones <caleb@calebgj.io>
Signed-off-by: Caleb Jones <caleb@calebgj.io>
Signed-off-by: Caleb Jones <caleb@calebgj.io>
Signed-off-by: Caleb Jones <caleb@calebgj.io>
scheduler affinity

Signed-off-by: Caleb Jones <caleb@calebgj.io>
…k/odorobo into caleb/fix-scheduler-actor-cache
Comment thread odorobo/src/actors/scheduler_actor.rs Dismissed
Comment thread odorobo/src/actors/scheduler_actor.rs Dismissed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Dismissed
Signed-off-by: Caleb Jones <caleb@calebgj.io>
Signed-off-by: Caleb Jones <caleb@calebgj.io>

@github-advanced-security github-advanced-security AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

clippy found more than 20 potential problems in the proposed changes. Check the Files changed tab for more details.

Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
@TheHeroBrine422 TheHeroBrine422 changed the title Caleb/fix scheduler actor cache Improve scheduler actor Jul 16, 2026
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
Comment thread odorobo/src/actors/scheduler_actor.rs Fixed
@TheHeroBrine422
TheHeroBrine422 marked this pull request as ready for review July 16, 2026 20:23
@halfcyan

Copy link
Copy Markdown
Member

i will look at this when i get back home. have you run it through clippy?

) -> Result<RemoteActorRef<AgentActor>, Report> {
let mut best_agent = None;
let mut best_agent_score = 0u32;
// someone should likely give caleb a firm talking to about code duplication due to this section, but things are just different enough that trying to make them one function requires usage of a lot of generics which feels even worse. so i dont know what to do. cappy please fix. i hate this.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i don't think that it's that big of a deal here tbh. it's functional and readable in a way that you might lose if you were to try to use generics.

// todo: i dont like the way this cache is setup. I think we may need to change it later, but it is hard to figure out what the optimal solution is without doing it at least once.
// especially when we haven't fully made decisions about some other things.
//
// todo: we should improve the cache to not have agents and vms send the full data on every update.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i'm sure there are off the shelf delta libraries. hell, git's is pretty decent. i can look into this a bit probably? not necessary for this pr but worth putting in outline or something. or opening a new pr/issue.

// I looked at kameo streams to make this better, but they aren't really intended for this kind of long term update use case.
// They use rust futures::stream which seems to be more intended for you have an iterator for example that will create data, but not like full on sending messages.
// This could likely be done pretty easily by having two get data messages.
// Option 1: One that creates a session and sends the full data and then only sends diffs after that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

this sounds more robust to me tbh

// idk. will figure it out later.
//
// new related problem: i just realized vmid, actorid pairs dont have to be unique.
// if a vm is migrating from one actor to another, there might be two actors with the same vmid.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

why was my first thought here to use a linked list

// if a vm is migrating from one actor to another, there might be two actors with the same vmid.
//
// additional context (05/05/2026): we almost may need a way to store them without a ulid, due to how CH migration works.
// the question becomes if we want to abstract CH migration away entirely from the scheduler.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

what would the scope be like on this? i don't think it needs to be through the scheduler, but i think the scheduler needs to integrate with it. we need to rebalance nodes occasionally.

// the best solution for at least some of this is almost certainly having an external reliable DB (such as etcd) to store some of these things permanently.
// we will need that specifically for what VMs are supposed to be running, because if a large percentage of the cluster goes down, including the manager, we need a way to recover.
// and i dont think leaving that on dashboard which could have high latency is a good idea.
// alternatively we could have the other manager nodes try to keep track of that data, but i think we are going to run into issues with keeping the state consistent between all nodes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

yeah honestly i think it's worth having a separate distributed db for this tbh. we don't want it to be integrated with odorobo in any way beyond like... a docker compose stack kinda thing. if odorobo fails, the database must retain data as it was when odorobo went down. i wonder if we could host a db with anyone who we peer with like cloudflare?


parent_actor_ref.link_remote(&vm_actor).await?;

let vm_actor_id = vm_actor.id();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

is there a reason you can't just pass vm_actor.id() for this since it only gets used in the keepalive_tasks.insert() function call?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

meant to leave this on line 151

if let Ok(data) = actor_ref.ask(&GetVMInfo { vmid: None }).await {
let vmid = data.vmid;

vm_actorid_ulid_map.insert(actor_ref.id(), vmid); // should we be doing this on every loop? idk. but we at least need to do it on the first iteration given we don't know the mapping before that

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

i feel like that's a good way to eat a couple cycles if it's not necessary for each loop

async fn on_update(
// this function intentionally only checks against the cache. this has some positives and negatives:
// positive: it will never trigger any network requests so its very fast, and having to do network requests for scoring whenever we want to schedule a vm is likely a bad idea
// negative: it technically has a delayed view of the cluster, meaning that some things that happened in the future, may not exist yet. so we need to be careful about how this is done so affinity rules are not accidentally broken. mostly this means, if we do anything that could affect the outcome of an affinity rule (ex: network request to an agent), we need to update the cache, before we do the action.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

assuming anything later in the cache is referencing anything that changed as a result of this, i think it's fine. so like if you have multiple VM creations get scheduled, as long as each subsequent one references the one before it.

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