Skip to content

Implement Fleets - #1415

Merged
r4victor merged 26 commits into
masterfrom
issue_1327_apply_for_instances
Jul 19, 2024
Merged

r4victor merged 26 commits into
masterfrom
issue_1327_apply_for_instances

Conversation

@r4victor

@r4victor r4victor commented Jul 17, 2024 •

Copy link
Copy Markdown
Collaborator

Closes #1327

This PR:

  • Introduces fleet configuration type to provision/delete cloud instances and add on-prem clusters using dstack apply/dstack delete.
  • Implements dstack fleet list, dstack fleet delete.
  • Updates job/run processing to reuse or auto-create fleets.
  • Implements fleet processing to auto-delete fleets no longer in use.
  • Updates docs with fleets reference and guide.
  • Fixes bugs in volumes processing, services with 0 replicas, and minor issues.

Tested:

  • dstack run works as before and creates or reuses fleets.
  • dstack pool commands work as before.
  • dstack apply creates cloud fleets.
  • dstack apply creates ssh fleets.
  • Multi-node tasks run on cloud fleets.
  • Multi-node tasks run on ssh fleets.
  • Services with autoscaling work with fleets (resize the fleets if needed).
  • Fleets created by dstack run are auto-cleaned when no longer in use.
  • Users cannot delete fleets in use.

@r4victor
r4victor marked this pull request as ready for review July 18, 2024 06:58
@r4victor
r4victor requested a review from jvstme July 18, 2024 07:34

@jvstme jvstme left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

@r4victor, thank you for this work, everything looks good so far. I am about halfway through the review and will finish tomorrow unless you prefer to merge earlier.

Comment thread docs/docs/concepts/fleets.md Outdated
Comment thread docs/docs/concepts/fleets.md Outdated
Comment thread docs/docs/concepts/fleets.md Outdated
Comment thread docs/docs/concepts/fleets.md Outdated
Comment thread docs/docs/concepts/fleets.md Outdated
The default pool is created automatically.

!!! warning "Deprecation"
Pools are deprecated in favor of fleets and will be removed in 0.19.0.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

(nit) Maybe mention it concepts/pools.md too?

Comment thread src/dstack/_internal/cli/services/configurators/fleet.py Outdated
Comment thread src/dstack/_internal/core/models/fleets.py Outdated
Comment thread src/dstack/_internal/core/models/instances.py
Comment thread src/dstack/_internal/server/services/fleets.py Outdated
@r4victor

Copy link
Copy Markdown
Collaborator Author

@jvstme, Thanks for the review. I'm going to merge so that everyone can try fleets already. If any non-trivial changes are required, they'll will probably land next week.

@r4victor
r4victor merged commit 0feac46 into master Jul 19, 2024
@r4victor
r4victor deleted the issue_1327_apply_for_instances branch July 19, 2024 06:04

async def _terminate_fleet_instances(fleet_model: FleetModel, instance_nums: Optional[List[int]]):
if is_fleet_in_use(fleet_model, ignore_instance_nums=instance_nums):
raise ServerClientError(f"Failed to delete fleet {fleet_model.name}. Fleet is in use.")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Is it expected that users cannot delete an instance if another instance in the same fleet is busy? This may waste resources, as users will have to keep the instances they no longer need.

> dstack fleet
 FLEET        INSTANCE  BACKEND          RESOURCES                         PRICE   STATUS  CREATED     
 massive-eel  0         aws (us-west-2)  2xCPU, 8GB, 100.0GB (disk), SPOT  $0.031  busy    11 mins ago 
              2         aws (us-west-2)  2xCPU, 8GB, 100.0GB (disk), SPOT  $0.031  idle    11 mins ago 

> dstack fleet delete massive-eel -i 2
Delete the fleet massive-eel instances [2]? [y/n]: y
Failed to delete fleet massive-eel. Fleet is in use.

The error message is also a bit misleading - the user was deleting an instance, not the whole fleet.

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.

That's a bug. I'll fix it.

)
if not confirmed and not args.yes:
if not confirm_ask(
f"Fleet [code]{conf.name}[/] does not exist yet. Create the fleet?"

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

> dstack apply -f fleet.dstack.yml
Fleet None does not exist yet. Create the fleet? [y/n]:

I think unnamed fleet configurations can have a better confirmation prompt, e.g. Are you sure you want to create a new fleet?

return value


class InstanceGroupParams(CoreModel):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider validating that SSH-specific and cloud-specific parameters are not specified at the same time. Currently, cloud-specific parameters would be ignored, which can be counterintuitive.

ssh_key: Optional[SSHKey] = None


class SSHParams(CoreModel):

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Consider allowing to specify region, as it is possible to specify it with dstack pool add-ssh.

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.

@jvstme region for dstack pool add-ssh can be used to group interconnected/non-interconnected instances. This doesn't seem to be necessary for fleets since instances are grouped by fleets. Why would one need to add ssh fleets and specify different regions?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If each instance has a region, it will allow to group instances across fleets or differentiate instances within a fleet based on their geographic location.

Problem 1: I have 2 fleets in Europe and 2 fleets in the US. I need to run a configuration on any of the fleets, as long as it is in the US.
Solution 1: Specify region in the run configuration and allow dstack to choose one of the US fleets automatically.

Problem 2: I need to run a service with 3 replicas: 1 in Europe, 1 in the US, 1 in Asia. I also need to have one stand-by instance in each region in case the other instance in this region fails.
Solution 2: Create the my-fleet fleet with 6 instances: 2 in Europe, 2 in the US, 2 in Asia. In the service configuration, specify fleet: my-fleet, replicas: 3, placement: geo-distributed.

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.

Introduce Fleets for cluster provisioning and management

2 participants