Skip to content

Add per-sled CPU and RAM capacities for instance usage - #2807

Merged
smklein merged 7 commits into
mainfrom
sled-resource
Apr 12, 2023
Merged

smklein merged 7 commits into
mainfrom
sled-resource

Conversation

@smklein

@smklein smklein commented Apr 11, 2023 •

Copy link
Copy Markdown
Collaborator
  • Adds a sled_resource table to the database, tracking CPU and RAM utilization for instances / services.
  • Provisions a row in the sled_resource table when allocating instances, avoiding over-provisioning.
  • Removes rows during instance deletion

Fixes #2805

}

#[nexus_test]
async fn test_instance_fails_to_boot_with_disk(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

FYI to @jmpesp , this was removed, but I believe we have coverage with the other idempotency tests.

Comment on lines +613 to +615
let hardware_threads = params.create_params.ncpus.0;
let rss_ram = params.create_params.memory;
let reservoir_ram = omicron_common::api::external::ByteCount::from(0);

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

right now, our policy for "how many resources are consumed by instances" is an exact 1:1 mapping of:

  • Guest CPUS -> Hardware threads
  • Guest RAM -> RSS RAM

Arguably, propolis will consume some overhead, and we will need to make considerations for the reservoir cost, in addition to the "rss ram" cost.

However, I wanted to put this PR up as-is, since it'll mechanically be very similar - just a difference of accounting.

Comment on lines +624 to +642
let resource = osagactx
.nexus()
.random_sled_id()
.reserve_on_random_sled(
instance_id,
db::model::SledResourceKind::Instance,
resources,
)
.await
.map_err(ActionError::action_failed)?
.ok_or_else(|| Error::ServiceUnavailable {
internal_message: String::from(
"no sleds available for new Instance",
),
})
.map_err(ActionError::action_failed)
.map_err(ActionError::action_failed)?;
Ok(resource.sled_id)
}

async fn sic_alloc_server_undo(
sagactx: NexusActionContext,
) -> Result<(), anyhow::Error> {
let osagactx = sagactx.user_data();
let instance_id = sagactx.lookup::<Uuid>("instance_id")?;

osagactx.nexus().delete_sled_reservation(instance_id).await?;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

FYI to @gjcolombo - "picking a sled" for an instance is now selected via reserve_on_random_sled, and removed via delete_sled_reservation.

It seems highly likely this will impact how instance migration will work -- we need to reserve on the destination, and eventually delete the reservation on the source sled.

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.

Thanks, this makes sense.

we need to reserve on the destination

Is it possible to rearrange the parts of sled_reservation_create so that it's straightforward to add constraints to the search for sleds with available resources? In the migration case, where the external API currently allows a caller to select a destination sled explicitly, this would be "the sled ID is exactly X." More generally, I think we'll eventually want to be able to say, "this VM requires a sled with at least this software version" or "this instance must be in this particular rack" or even just "pick any compatible sled except this one." In a perfect world these would be easy to compose ("add these WHERE clauses to this query") but I'm not good enough with Diesel to assess how challenging that is.

and eventually delete the reservation on the source sled

ACK. I already need to add a commit to the LM series that will deal with this sort of post-migration task, so this can be another piece of work that task has to do.

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.

@smklein and I talked this over offline and concluded that the easiest way to make progress for now is to do the following:

  • Add a parameter to sled_reservation_create (either in this PR or in the live migration series, I'm not sure it matters which) that allows the caller to specify a sled, or set of sleds, to exclude from consideration. In the migration case, this is the instance's current sled.
  • In my pending migration changes, change the migration saga to use sled_reservation_create instead of an explicitly-selected sled. (This would change the external API from "migrate this instance to sled X" to "migrate this instance to any eligible sled. cc @askfongjojo about this part--is this going to leave us with an unworkable migration API? Do we need to think about this more?)

If/when we need more constraints in the future, we can come up with a suitably elegant way to add them (e.g. a SledSelectionConstraints type with a fancy builder interface).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Is this a parameter you want me to add as a part of this PR? (I wouldn't be using it yet)

Or are you okay integrating that in the upcoming migration PRs?

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.

I can add it to the migration series.

@smklein
smklein marked this pull request as ready for review April 11, 2023 17:18
@smklein
smklein requested review from gjcolombo and jmpesp April 11, 2023 17:18
@gjcolombo gjcolombo self-assigned this Apr 11, 2023

@gjcolombo gjcolombo 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.

Thanks for putting this together! LGTM except for one small reservation (aha) about the change to the delete saga.

Comment thread sled-agent/src/bin/sled-agent-sim.rs Outdated
ip: (*args.sled_agent_addr.ip()).into(),
},
updates: ConfigUpdates { zone_artifact_path: tmp.path().to_path_buf() },
hardware: ConfigHardware { hardware_threads: 4, physical_ram: 1 << 30 },

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.

I think these should be more generous (e.g. matching what's in test-utils). With this config, a sled-agent-sim sled can have exactly one instance with 1 GiB of RAM, since we require guest memory to be specified in 1 GiB increments.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Done in ec2d3f8


osagactx
.datastore()
.sled_reservation_delete(&opctx, params.instance.id())

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.

Is this the right ID? sled_reservation_delete seems to want the resource ID, unless I'm missing something about how the tables are arranged.

@smklein smklein Apr 12, 2023 •

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I'm exploiting the fact that the instance ID and resource ID are tightly coupled! The instance is the service being provisioned, so it's using the same UUID.

I tried to document this in the schema:

-- Accounting for programs using resources on a sled
CREATE TABLE omicron.public.sled_resource (
    -- Should match the UUID of the corresponding service
    id UUID PRIMARY KEY,

But I'm happy to make this more clear, where possible?

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.

Ah, that makes sense. I just whistled past that part of the schema definition.

I might add a short comment here for the benefit of future readers who might not have read the schema first (since reading reservation_delete .. instance.id might seem as odd to them as it did to me), but I don't think we need to massively rework or reorganize the rest of the PR.

@gjcolombo

Copy link
Copy Markdown
Contributor

🚀

@smklein
smklein enabled auto-merge (squash) April 12, 2023 16:07
@smklein
smklein merged commit 2c320cc into main Apr 12, 2023
@smklein
smklein deleted the sled-resource branch April 12, 2023 16:46
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.

Track provisioned CPU and RAM usage for instances

2 participants