Tuần 3 - Ngày 4: EBS Deep Dive
Mục tiêu học tập
- Hiểu sâu performance characteristics của từng EBS type
- Nắm cách tính IOPS, throughput requirements
- Biết về Fast Snapshot Restore, Snapshot Archive
- Áp dụng EBS Multi-Attach và cluster filesystem
1. Ôn lại EBS Volume Types
| Type | IOPS max | Throughput max | Size | Use case |
|---|---|---|---|---|
| gp3 (default mới) | 16,000 | 1,000 MB/s | 1 GB - 16 TB | General-purpose |
| gp2 (legacy) | 16,000 | 250 MB/s | 1 GB - 16 TB | General-purpose cũ |
| io2 Block Express | 256,000 | 4,000 MB/s | 4 GB - 64 TB | Critical, highest perf |
| io2 | 64,000 | 1,000 MB/s | 4 GB - 16 TB | Mission-critical DB |
| io1 (legacy) | 64,000 | 1,000 MB/s | 4 GB - 16 TB | Legacy |
| st1 | 500 | 500 MB/s | 125 GB - 16 TB | Big data, log throughput |
| sc1 | 250 | 250 MB/s | 125 GB - 16 TB | Cold archive HDD |
2. gp3 — Mặc định mới
Đặc điểm
- Baseline: 3,000 IOPS, 125 MB/s (cho mọi size)
- Có thể provision thêm:
- IOPS: lên đến 16,000 ($/IOPS-month)
- Throughput: lên đến 1,000 MB/s ($/MB/s-month)
- IOPS và throughput độc lập với storage size
- Rẻ hơn gp2 ~20%
Migration từ gp2 sang gp3
- Modify volume (no downtime)
- Set baseline IOPS/throughput
- Có thể adjust live mà không cần stop EC2
3. gp2 — Tied to size
Quy tắc IOPS
IOPS = 3 × Volume Size (GB), max 16,000
Examples:
- 100 GB → 300 IOPS baseline (burst 3,000)
- 1,000 GB → 3,000 IOPS
- 5,334 GB → 16,000 IOPS (cap)
Burst Bucket (cho volumes < 1,000 GB)
- Burst lên 3,000 IOPS trong thời gian giới hạn
- Initialized với 5.4M I/O credits (đủ burst 30 phút)
- Tích lũy ngược lại khi idle
Vì sao gp3 thay gp2?
- gp2 IOPS phụ thuộc size → để có nhiều IOPS phải mua dư size
- gp3: tách rời, mua đúng cái cần
- gp3 rẻ hơn
4. io2 và io2 Block Express
io2
- Designed cho mission-critical workload (database, ERP)
- IOPS:GB ratio: lên đến 500:1
- 99.999% durability (vs 99.999% Standard cho gp3/io1: thực tế io2 5 nines availability)
- Cost premium so với gp3 (~3x)
io2 Block Express
- Next-gen io2
- Max 256,000 IOPS, 4,000 MB/s, 64 TB
- Latency sub-millisecond
- Use case: SAP HANA, Oracle/SQL Server extreme workload
- Chỉ trên instance Nitro mới (R5b, X2idn...)
Provisioned IOPS pricing
- io1/io2: charge per provisioned IOPS + per GB
- Mất nhiều tiền nếu over-provision
5. st1 và sc1 (HDD)
st1 (Throughput Optimized HDD)
- Sequential workload (read/write large blocks)
- Big data, log processing, ETL
- Max 500 MB/s, 500 IOPS
- Cannot use as boot volume
sc1 (Cold HDD)
- Infrequent access sequential
- Max 250 MB/s, 250 IOPS
- Cheapest EBS
- Cannot use as boot volume
Lưu ý quan trọng
- HDD volume không hỗ trợ làm boot volume
- Random I/O workload (database) → đừng dùng HDD, quá chậm
6. EBS Resize (Elastic Volumes)
Tính năng
- Increase size (không bao giờ decrease)
- Change volume type (gp2 → gp3)
- Modify IOPS/throughput (gp3, io1, io2)
- No downtime — operation live
Workflow
# Modify volume
aws ec2 modify-volume \
--volume-id vol-xxxx \
--size 200 \
--volume-type gp3 \
--iops 6000 \
--throughput 250
# Trên EC2, extend filesystem
sudo growpart /dev/nvme0n1 1
sudo xfs_growfs / # Hoặc resize2fs cho ext4
Cooldown
- Chỉ 1 modify operation per 6 giờ per volume
- Phải đợi state "in-use" trở lại
7. EBS Performance Tuning
Throughput vs IOPS
- IOPS (Input/Output Per Second): số transactions
- Throughput (MB/s): lượng data
- Relationship: Throughput = IOPS × Block Size
Ví dụ
- 16,000 IOPS × 16 KB block = 256 MB/s
- 16,000 IOPS × 256 KB block = 4,000 MB/s
- → Block size lớn hơn → throughput cao hơn
Performance bottleneck
- EC2 instance throughput limit: kiểm tra bandwidth EBS của instance type
- Ví dụ: m5.large EBS bandwidth chỉ ~593 MB/s burst → EBS volume mạnh hơn cũng không vượt
- Sizing: chọn instance type EBS bandwidth ≥ volume throughput
Pre-warming EBS (init)
- Volume tạo từ snapshot có blocks bị "lazy load" — first access đến block sẽ slow
- 2 cách warm-up:
- fio hoặc
ddđọc toàn bộ volume - Fast Snapshot Restore (FSR)
- fio hoặc
8. Fast Snapshot Restore (FSR)
Định nghĩa
FSR = enable snapshot có full performance ngay từ đầu, không cần warm-up.
Đặc điểm
- Enable per snapshot per AZ
- Cost: $/data-service-unit-hour (~$0.75/hour per snapshot per AZ)
- Tự động disable khi snapshot bị delete
Use case
- DR drill nhanh
- Critical workload phải sẵn sàng ngay khi restore
- ASG tạo instance từ snapshot phải có perf tốt ngay
9. EBS Snapshot Archive
Định nghĩa
Snapshot Archive = tier rẻ hơn cho snapshot lưu lâu dài.
Đặc điểm
- 75% rẻ hơn standard snapshot
- Min retention: 90 ngày
- Restore time: 24-72 hours
- Restored snapshot trở thành standard (tính tiền standard từ lúc restore)
Use case
- Compliance archive
- Snapshot không truy cập trong tháng
- Backup retention dài hạn
So sánh
| Type | Cost | Restore time |
|---|---|---|
| Standard snapshot | $$ | Instant (incremental) |
| Snapshot Archive | $ | 24-72 hours |
10. Recycle Bin for EBS
Định nghĩa
Recycle Bin = "undo delete" cho EBS volumes, snapshots, AMIs.
Setup
- Tạo Retention Rule: 1-365 ngày (cho snapshot/AMI), 1-365 (cho volume — chỉ recent feature)
- Filter by tags
- Khi delete, resource vào Recycle Bin thay vì hết hẳn
- Có thể restore trong retention period
Use case
- Protect against accidental delete
- Compliance "delete protection"
- DR scenario
11. EBS Multi-Attach (io1/io2)
Đặc điểm
- 1 io1/io2 volume attach tối đa 16 EC2 instances trong cùng AZ
- All instances có full read/write access
- Filesystem phải cluster-aware (GFS2, OCFS2)
- KHÔNG dùng được với ext4, XFS (sẽ corrupt!)
Use case
- Cluster database với shared block storage
- Active-active HA application
- Failover scenarios (passive node có thể read state)
Architecture
Limitations
- Cùng AZ (không cross-AZ)
- Cùng VPC
- Nitro-based instances
- io1/io2 (KHÔNG gp3)
12. EBS Snapshot Sharing
Share snapshot cross-account
- Unencrypted snapshot: Share đơn giản, click vài button
- Encrypted snapshot:
- Phải dùng Customer-Managed KMS Key (không phải AWS-managed)
- Grant target account access đến KMS key
- Share snapshot
- Target account: copy snapshot, có thể re-encrypt với key của họ
Public snapshot (cẩn thận!)
- Có thể share snapshot publicly với mọi AWS account
- RỦI RO: data leak nếu nhầm public
- Best practice: Block public access for snapshots ở region level
13. EBS Use Case Decision Tree
Câu hỏi ôn tập
-
gp3 IOPS baseline là bao nhiêu? Phụ thuộc size không?
Xem đáp án
gp3 baseline là 3,000 IOPS và 125 MB/s throughput — không phụ thuộc size (dù volume chỉ 1 GB vẫn có 3,000 IOPS). Có thể provision thêm lên đến 16,000 IOPS và 1,000 MB/s (tính phí thêm). Đây là điểm khác biệt chính với gp2: gp2 chỉ có 3,000 IOPS với volume ≥ 1,000 GB; nhỏ hơn thì IOPS = 3 × size GB.
-
Volume type nào hỗ trợ Multi-Attach?
Xem đáp án
Chỉ io1 và io2 Block Express hỗ trợ Multi-Attach. Điều kiện: tất cả instances phải trong cùng AZ, cùng Region. Tối đa 16 instances. Không hỗ trợ gp2, gp3, st1, sc1. Multi-Attach yêu cầu cluster-aware filesystem hoặc application-level locking để tránh data corruption khi concurrent writes.
-
Snapshot Archive minimum retention bao lâu? Restore time?
Xem đáp án
Minimum 90 ngày retention trong Archive tier. Restore time: 24-72 giờ (để restore snapshot từ archive về standard tier trước khi có thể dùng). Snapshot Archive tiết kiệm tới 75% so với standard snapshot pricing — phù hợp cho compliance/audit snapshots cần giữ lâu nhưng hiếm khi access. Không phù hợp cho DR nếu cần restore nhanh.
-
Khi resize EBS volume, có cần stop EC2 không?
Xem đáp án
Không — EBS Elastic Volumes cho phép modify volume live (resize, đổi type, thay đổi IOPS/throughput) mà không cần stop EC2. Tuy nhiên sau khi AWS resize hoàn tất, cần extend filesystem từ trong OS (
resize2fscho ext4,xfs_growfscho XFS) để sử dụng space mới. Lưu ý: chỉ có thể tăng size, không thể giảm. -
HDD volume (st1, sc1) có dùng được làm boot volume không?
Xem đáp án
Không. st1 (Throughput Optimized HDD) và sc1 (Cold HDD) không thể làm boot volume — chỉ dùng được làm additional data volumes. Boot volume phải là SSD type: gp2, gp3, io1, hoặc io2. HDD volumes phù hợp cho big data, sequential workloads, log processing — không phù hợp cho OS boot vì OS cần random IOPS.
Bài tập thực hành
- Migrate 1 gp2 volume sang gp3, observe cost reduction
- Resize gp3 từ 10 GB → 30 GB live, extend filesystem
- Tạo io2 volume 100 GB với 10,000 IOPS, attach vào EC2 m5.xlarge
- Enable Fast Snapshot Restore cho 1 snapshot, restore và đo performance vs no FSR
- Setup Recycle Bin retention 7 ngày cho EBS snapshots
- Test Multi-Attach io2 volume với 2 EC2 (cẩn thận filesystem!)
Tài liệu tham khảo chính thức
- EBS Volume Types
- EBS Modify Volume
- Fast Snapshot Restore
- EBS Snapshot Archive
- EBS Multi-Attach
- Recycle Bin
Tiếp theo: EFS và FSx