Spot Fleet is a service provided by AWS that helps you manage Spot Instances in a more flexible and scalable way. A Spot Fleet allows you to launch and manage a collection of Spot Instances across multiple instance types, availability zones, and pricing models. It’s designed to ensure that you can meet the desired capacity for your workload, even if some Spot Instances are interrupted or terminated.
Key Features of Spot Fleet:
- Mix of On-Demand and Spot Instances:
- A Spot Fleet allows you to combine Spot Instances with On-Demand Instances in a single request.
- This combination gives you the ability to manage cost while still maintaining availability and stability for your applications.
- Automatic Instance Replacement:
- If a Spot Instance is interrupted, the Spot Fleet automatically launches a new instance to maintain the requested capacity.
- The fleet can continue to operate with the desired capacity by automatically adjusting to Spot Instance availability.
- Multiple Instance Types and Availability Zones:
- You can specify a mix of instance types and availability zones for your Spot Fleet to ensure higher chances of fulfilling the requested capacity.
- This flexibility helps minimize interruptions by distributing your fleet across multiple AZs and instance types.
- Flexible Pricing Models:
- You can choose to run instances with Spot pricing, On-Demand pricing, or a combination of both.
- You can set the maximum price you are willing to pay for Spot Instances, allowing you to manage costs effectively.
- Capacity Management:
- Spot Fleet uses your specified capacity (either in terms of instances or vCPUs) to determine how many Spot and On-Demand Instances to launch.
- The fleet can scale based on the target capacity you’ve set, making it easier to handle variable workloads.
How Spot Fleet Works:
- Requesting Spot Fleet:
- You create a Spot Fleet request, which defines the desired capacity, instance types, availability zones, pricing models, and target capacities.
- You can specify:
- Target capacity: Number of instances or vCPUs required.
- Instance types: A mix of instance families (e.g.,
t3
,m5
,c5
) and sizes. - Availability zones: Spread instances across multiple AZs for high availability.
- Pricing strategy: The maximum price you are willing to pay for Spot Instances.
- Spot Fleet Launches Instances:
- The Spot Fleet will attempt to fulfill the request by launching Spot Instances in the selected instance types and AZs, based on available capacity and pricing.
- If the Spot price is too high or the capacity is unavailable, the Spot Fleet will either use On-Demand Instances or wait until Spot Instances become available.
- Monitoring Spot Fleet:
- You can monitor the status of your Spot Fleet through Amazon EC2 Console, CLI, or SDKs. AWS provides detailed metrics such as running instances, requested capacity, current Spot price, and instance health.
- If any Spot Instances are interrupted, the fleet will attempt to launch new instances to meet the requested capacity.
- Capacity Maintenance:
- Spot Fleets can scale in or scale out based on your workload requirements. If the capacity needs to increase, the fleet will launch new Spot or On-Demand Instances.
- If the demand decreases, the fleet will scale down by terminating instances that are no longer needed.
Types of Spot Fleet Requests:
- Maintain:
- With a Maintain request, you set the target capacity for your fleet, and the Spot Fleet will attempt to maintain that capacity, even if Spot Instances are interrupted. If any Spot Instance is interrupted, the fleet will replace it with a new instance.
- Capacity-Optimized:
- With a Capacity-Optimized request, the Spot Fleet attempts to fulfill your request by prioritizing capacity pools with the lowest likelihood of interruption.
- This helps minimize disruptions, especially when you need reliable compute capacity.
Spot Fleet Request Example:
Let’s look at an example where you want to request a Spot Fleet with a mix of Spot and On-Demand Instances:
- Target capacity: 10 instances.
- Spot Instances: 70% of the capacity (7 instances).
- On-Demand Instances: 30% of the capacity (3 instances).
- Instance types:
m5.large
,t3.medium
. - Availability Zones:
us-west-2a
,us-west-2b
. - Max price: You’re willing to pay a maximum of $0.10 per hour for Spot Instances.
With this request, the Spot Fleet will try to launch 7 Spot Instances across the specified AZs and instance types. If the Spot price rises above your specified maximum price, the fleet will fall back on 3 On-Demand Instances to meet your target capacity.
Advantages of Using Spot Fleet:
- Cost Savings:
- You can significantly reduce costs by utilizing Spot Instances while also having the flexibility to use On-Demand Instances when Spot capacity is unavailable.
- High Availability:
- Spot Fleet distributes your workload across multiple instance types and availability zones, reducing the chances of capacity shortages.
- Automatic Scaling:
- The fleet can automatically scale to meet the desired capacity, ensuring that your application always has enough compute resources.
- Fault Tolerance:
- Spot Fleet replaces interrupted instances automatically, so your application continues running with the requested capacity even in the event of Spot Instance interruptions.
Use Cases for Spot Fleet:
- Big Data Processing:
- For large data processing tasks, you can use Spot Fleets to dynamically scale the number of instances as your processing needs grow.
- CI/CD Workflows:
- Spot Fleets can be used to run continuous integration and continuous deployment pipelines that require high computational power without the cost of On-Demand Instances.
- Web Crawling and Data Mining:
- Use Spot Fleets to scale your web crawlers or data mining tasks to scrape large volumes of data in a cost-effective manner.
- Rendering and Simulation Workloads:
- Spot Fleets can handle rendering jobs or complex simulations where the capacity needs might fluctuate, and Spot Instances can be used to handle the demand at a lower cost.
Summary:
- Spot Fleets allow you to manage a collection of Spot Instances and On-Demand Instances to meet the desired capacity.
- The fleet automatically handles instance interruptions, ensuring high availability and flexibility in terms of pricing and instance types.
- It’s ideal for dynamic workloads, big data processing, and applications where cost optimization and high availability are key.