Tuỳ chọn mua EC2: tối ưu chi phí mà vẫn đảm bảo tính sẵn sàng
Cùng một EC2 instance có thể được mua theo nhiều tuỳ chọn mua (purchasing option) với mức giá khác nhau; tuỳ chọn phù hợp phụ thuộc vào việc instance chạy liên tục hay chỉ chạy lúc cần, và có chịu được gián đoạn hay không.
MFTECH cần 80 instance chạy liên tục 24/7; vào ban ngày cần bổ sung worker xử lý ảnh từ một queue (chịu được gián đoạn). Chọn chiến lược mua:
Không yêu cầu cam kết nên linh hoạt nhất, nhưng chịu mức giá cao nhất cho cả phần tải nền chạy 24/7.
Mức giá dùng để so sánh là giả định (RI thấp hơn 40%, Spot thấp hơn 70% so với On-Demand). Theo tài liệu AWS, Reserved Instances và Savings Plans giảm tới 72%, Spot giảm tới 90% so với giá On-Demand.
Biểu đồ trên thể hiện bức tranh tổng thể. Thực tế còn nhiều tình huống cụ thể hơn: Spot Instance bị gián đoạn (interruption) lúc nửa đêm, đối tác yêu cầu phần cứng riêng, license tính theo socket, hoá đơn bao gồm cả Fargate và Lambda. Chọn từng tình huống, thay đổi cấu hình, sau đó nhấn Chạy:
Worker xử lý ảnh sản phẩm chạy trên Spot Instance và nhận tác vụ từ một SQS queue. Lúc nửa đêm, AWS cần thu hồi capacity. Nhấn Chạy để quan sát kết quả. Thay đổi cấu hình và chạy lại để so sánh.
Trước đợt khuyến mãi 11/11, MFTECH cần chắc chắn có đủ capacity cho 40 instance c-family trong AZ ap-southeast-1a. Savings Plans và regional Reserved Instances chỉ giảm giá, không giữ capacity. On-Demand Capacity Reservation giữ capacity trong một AZ cụ thể; loại dùng ngay có thể tạo, sửa và huỷ bất kỳ lúc nào, không cam kết thời hạn. Capacity Reservation không có chiết khấu riêng: được tính theo giá On-Demand dù có instance chạy trong capacity đã giữ hay không. Để vừa giữ capacity vừa được giảm giá, kết hợp Capacity Reservation với Savings Plans hoặc regional Reserved Instances. Capacity Reservation không làm thay đổi hiệu năng của instance.
Hai tuỳ chọn mua cũ đã ngừng: Scheduled Reserved Instances (đặt trước capacity theo lịch ngày, tuần, tháng) không còn mua được, AWS không có capacity và không có kế hoạch cung cấp lại; Spot block (Spot Instance với defined duration 1 đến 6 giờ) đã ngừng cung cấp cho khách hàng mới từ 1/7/2021. Thay thế: cần giữ capacity thì dùng On-Demand Capacity Reservation, cần giá thấp hơn thì dùng Savings Plans; tác vụ chịu được gián đoạn dùng Spot Instance không đặt duration.
- Tải nền chạy 24/7: Reserved Instances hoặc Savings Plans.
- Tác vụ chịu được gián đoạn: Spot (persistent request hoặc Spot Fleet để tiếp tục xử lý).
- Persistent request mở lại sau khi Spot Instance bị gián đoạn; nếu bạn stop instance, request ở trạng thái disabled và chỉ mở lại sau khi start; huỷ request không terminate instance.
- Tải biến động không chịu được gián đoạn: On-Demand.
- Phần cứng single-tenant, không cần kiểm soát host và không có license theo socket, core: Dedicated Instances (tính phí theo instance); license theo socket, core: Dedicated Hosts (tính phí theo host).
- Chiết khấu áp dụng cho cả EC2, Fargate và Lambda: Compute Savings Plan.
- Bảo đảm có capacity trong một AZ: On-Demand Capacity Reservation (giá On-Demand, không tăng hiệu năng).
- Scheduled Reserved Instances và Spot block đã ngừng.
EC2 purchasing options: optimizing cost while keeping availability
The same EC2 instance can be bought through several purchasing options at different prices; the right option depends on whether it runs all the time or only when needed, and whether it can tolerate interruptions.
MFTECH needs 80 instances running continuously 24/7; during the day it also needs extra workers that process images from a queue (interruption-tolerant). Choose a purchasing strategy:
Không yêu cầu cam kết nên linh hoạt nhất, nhưng chịu mức giá cao nhất cho cả phần tải nền chạy 24/7.
Mức giá dùng để so sánh là giả định (RI thấp hơn 40%, Spot thấp hơn 70% so với On-Demand). Theo tài liệu AWS, Reserved Instances và Savings Plans giảm tới 72%, Spot giảm tới 90% so với giá On-Demand.
The chart above shows the big picture. In practice there are more specific situations: a Spot Instance interrupted at midnight, a partner that requires dedicated hardware, licenses priced per socket, a bill that includes Fargate and Lambda as well. Pick each scenario, change the configuration, then press Run:
Worker xử lý ảnh sản phẩm chạy trên Spot Instance và nhận tác vụ từ một SQS queue. Lúc nửa đêm, AWS cần thu hồi capacity. Nhấn Chạy để quan sát kết quả. Thay đổi cấu hình và chạy lại để so sánh.
Before the 11.11 sale, MFTECH must be certain to have capacity for 40 C-family instances in the ap-southeast-1a AZ. Savings Plans and regional Reserved Instances only lower the price; they do not reserve capacity. An On-Demand Capacity Reservation reserves capacity in a specific AZ; an immediate-use reservation can be created, modified and canceled at any time with no term commitment. A Capacity Reservation has no discount of its own: it is charged at the On-Demand rate whether or not instances run in the reserved capacity. To reserve capacity and also get a discount, combine the Capacity Reservation with Savings Plans or regional Reserved Instances. A Capacity Reservation does not change instance performance.
Two older purchasing options are retired: Scheduled Reserved Instances (capacity reserved on a daily, weekly or monthly schedule) can no longer be purchased, and AWS has no capacity or plans to offer them again; Spot blocks (Spot Instances with a defined duration of 1 to 6 hours) have not been available to new customers since July 1, 2021. Instead: to reserve capacity, use On-Demand Capacity Reservations; for lower prices, use Savings Plans; interruption-tolerant work uses Spot Instances without a defined duration.
- Baseline load running 24/7: Reserved Instances or Savings Plans.
- Interruption-tolerant tasks: Spot (a persistent request or Spot Fleet to keep processing).
- A persistent request opens again after the Spot Instance is interrupted; if you stop the instance, the request is disabled and opens only after you start it; canceling a request does not terminate the instance.
- Variable load that cannot tolerate interruption: On-Demand.
- Single-tenant hardware, with no need to control the host and no per-socket or per-core licenses: Dedicated Instances (billed per instance); per-socket or per-core licenses: Dedicated Hosts (billed per host).
- A discount that covers EC2, Fargate and Lambda: Compute Savings Plan.
- Guaranteed capacity in one AZ: On-Demand Capacity Reservation (On-Demand rate, no performance gain).
- Scheduled Reserved Instances and Spot blocks are retired.