Sub topic 14
Monitoring volume performance
This chapter assumes you know the IOPS, throughput and latency model from the performance chapter, and that you can use the AWS CLI and a Linux shell. It shows which signals tell you whether an EBS volume is healthy, saturated or idle, and how to read them.
Where the numbers come from
Two layers report EBS activity, and they answer different questions.
- Volume metrics are in the
AWS/EBSCloudWatch namespace, keyed by theVolumeIddimension. They describe what the volume itself did. - Instance metrics are in the
AWS/EC2namespace.EBSReadOps,EBSWriteOps,EBSReadBytesandEBSWriteBytessum activity across all EBS volumes on an instance. Instance types with burstable EBS performance also publishEBSIOBalance%andEBSByteBalance%. - Operating system tools such as
iostatshow what the kernel sees, including queueing inside the instance.
EBS publishes volume metrics at one-minute granularity for volumes attached to current Nitro instances. Other attachments may report at five minutes, so check the current EBS documentation for your instance type. The data points are raw counters over the period, not rates. You convert them yourself.
The core volume metrics
| Metric | What it counts | Statistic to use |
|---|---|---|
| `VolumeReadOps`, `VolumeWriteOps` | I/O operations completed in the period | Sum |
| `VolumeReadBytes`, `VolumeWriteBytes` | Bytes transferred in the period | Sum |
| `VolumeTotalReadTime`, `VolumeTotalWriteTime` | Seconds spent on all completed operations | Sum |
| `VolumeQueueLength` | Operations waiting to be completed | Average |
| `VolumeIdleTime` | Seconds in the period with no pending I/O | Sum |
| `BurstBalance` | Percent of burst credits left (gp2, st1, sc1) | Average, Minimum |
| `VolumeThroughputPercentage` | Percent of provisioned IOPS delivered (io1, io2) | Average |
| `VolumeConsumedReadWriteOps` | Provisioned IOPS consumed (io1, io2) | Sum |
| `VolumeStalledIOCheck` | 1 when the volume failed its I/O status check | Maximum |
Newer volume types also publish VolumeIOPSExceededCheck and VolumeThroughputExceededCheck. Each is 1 when demand exceeded what the volume could deliver during that period. The EC2 namespace has matching instance-level checks, InstanceEBSIOPSExceededCheck and InstanceEBSThroughputExceededCheck. These flags save you from working out the limit yourself, so alarm on them where they exist.
Turning counters into rates
Because the values are totals, divide by the period length in seconds.
- IOPS = (
VolumeReadOps+VolumeWriteOps) ÷ period seconds - Throughput = (
VolumeReadBytes+VolumeWriteBytes) ÷ period seconds - Average read latency =
VolumeTotalReadTime÷VolumeReadOps - Average I/O size = bytes ÷ operations
The latency formula gives seconds per operation, so multiply by 1000 for milliseconds. Compare IOPS and throughput with the limits you set when you chose the volume type: 3,000 IOPS and 125 MiB/s for a default gp3, or the provisioned values for io2. A volume running near either limit is saturated, even if the other limit has headroom.
Average I/O size explains which limit you hit first. A gp3 volume at 125 MiB/s doing 16 KiB operations reaches about 8,000 operations per second, so its 3,000 IOPS ceiling arrives first. The same volume doing 256 KiB operations reaches its throughput ceiling at about 500 operations per second.
The following command computes IOPS and average read latency for one volume over the last hour, using CloudWatch metric math. It needs GNU date, which is standard on Linux. Save the queries first.
cat > queries.json <<'EOF'
[
{"Id": "r", "ReturnData": false,
"MetricStat": {"Metric": {"Namespace": "AWS/EBS", "MetricName": "VolumeReadOps",
"Dimensions": [{"Name": "VolumeId", "Value": "vol-0123456789abcdef0"}]},
"Period": 300, "Stat": "Sum"}},
{"Id": "w", "ReturnData": false,
"MetricStat": {"Metric": {"Namespace": "AWS/EBS", "MetricName": "VolumeWriteOps",
"Dimensions": [{"Name": "VolumeId", "Value": "vol-0123456789abcdef0"}]},
"Period": 300, "Stat": "Sum"}},
{"Id": "tr", "ReturnData": false,
"MetricStat": {"Metric": {"Namespace": "AWS/EBS", "MetricName": "VolumeTotalReadTime",
"Dimensions": [{"Name": "VolumeId", "Value": "vol-0123456789abcdef0"}]},
"Period": 300, "Stat": "Sum"}},
{"Id": "iops", "Label": "IOPS", "Expression": "(r + w) / PERIOD(r)"},
{"Id": "rlat", "Label": "Read latency (ms)", "Expression": "IF(r > 0, tr / r * 1000, 0)"}
]
EOF
aws cloudwatch get-metric-data \
--start-time "$(date -u -d '1 hour ago' +%Y-%m-%dT%H:%M:%SZ)" \
--end-time "$(date -u +%Y-%m-%dT%H:%M:%SZ)" \
--metric-data-queries file://queries.json \
--query 'MetricDataResults[].{Label:Label,Values:Values}'Reading queue length and idle time
VolumeQueueLength shows how much work is waiting. A short queue means the volume keeps up. A queue that grows while IOPS stays flat at the limit means the application is asking for more than the volume can deliver, and latency rises with the queue.
Queue length is only meaningful next to the workload. AWS gives a rule of thumb of roughly one queued operation per 1,000 IOPS for SSD volumes. A throughput-oriented HDD volume (st1 or sc1) wants a deeper queue to reach its throughput, because it works best with large sequential requests. Do not alarm on a low queue length alone. A queue near zero on a busy volume is healthy, and a queue near zero on a slow application points to the application or the instance.
VolumeIdleTime helps with cost. A volume with near-full idle time for weeks is a candidate for deletion, snapshot-and-delete, or a cheaper type. The cost chapter returns to this.
Burst credits
gp2, st1 and sc1 volumes earn credits when idle and spend them above baseline. BurstBalance is the percentage left. When it reaches 0, performance falls to the baseline. That drop looks like sudden latency in the application. gp3 and the provisioned IOPS types have no burst bucket, so they do not publish this metric.
Alarm on BurstBalance well before empty. This alarm notifies an SNS topic when the balance stays below 20 percent for 15 minutes.
aws cloudwatch put-metric-alarm \
--alarm-name data-vol-burst-low \
--namespace AWS/EBS \
--metric-name BurstBalance \
--dimensions Name=VolumeId,Value=vol-0123456789abcdef0 \
--statistic Average \
--period 300 \
--evaluation-periods 3 \
--threshold 20 \
--comparison-operator LessThanThreshold \
--treat-missing-data notBreaching \
--alarm-actions arn:aws:sns:us-east-1:123456789012:ops-alertsThe --treat-missing-data notBreaching option avoids false alarms when a volume is detached and stops reporting.
The instance can be the bottleneck
A volume can look fine while the application is slow because the instance has its own EBS limits. Every instance type has a maximum EBS bandwidth and IOPS, shared by all its volumes. Two volumes that each stay under their own limits can still hit the instance ceiling together.
To tell the two apart, compare volume metrics with instance metrics. If each volume is below its limits but EBSReadBytes plus EBSWriteBytes on the instance is near the instance maximum, the instance type is the limit. Moving to a larger instance helps. Raising volume IOPS does not.
What the operating system shows
CloudWatch cannot see inside the instance. Use iostat from the sysstat package for per-device detail.
iostat -xz 5The -x flag adds extended statistics and -z hides idle devices. Look at these columns for the NVMe device:
r/sandw/sare operations per second. They should agree with the CloudWatch IOPS figure.r_awaitandw_awaitare average latency in milliseconds, including time spent in the kernel queue. Newersysstatversions use these names. Older versions show a singleawait.aqu-sz(older versions:avgqu-sz) is the average queue depth.%utilapproaches 100 when the device is always busy. On NVMe, which handles many requests in parallel, 100% does not by itself mean the device is saturated.
If iostat shows high latency while CloudWatch shows low volume latency, the delay is queueing in the instance, often from a single-threaded application or too small a queue depth setting. For NVMe-level latency histograms on Nitro instances, the ebsnvme tooling from AWS can help, but the CloudWatch metrics above are enough for most cases.
A diagnosis flow
Common mistakes
- Reading Sum as a rate. A
VolumeReadOpssum of 90,000 over a 300-second period is 300 IOPS, not 90,000. - Using Average for counters. Average of a counter over a period is the mean of the per-minute values, which hides the total. Use Sum for ops, bytes and times.
- Looking at one limit only. Check both IOPS and throughput, because average I/O size decides which one binds.
- Ignoring initialization. A volume restored from a snapshot shows high latency on first reads of each block until it has been read once or initialized. This looks like a performance problem but is expected.
- Alarming on a single data point. Use at least three evaluation periods to avoid paging on brief spikes.
Exercise
A gp3 volume provisioned with 3,000 IOPS and 125 MiB/s shows these values for one 300-second period: VolumeReadOps Sum = 450,000, VolumeWriteOps Sum = 450,000, VolumeReadBytes Sum = 14,745,600,000, VolumeWriteBytes Sum = 14,745,600,000. What are the average IOPS and throughput in MiB/s, and which limit is the volume hitting?
Show answer
Total operations are 900,000, so IOPS = 900,000 / 300 = 3,000. Total bytes are 29,491,200,000, so throughput = 29,491,200,000 / 300 = 98,304,000 bytes/s, which is 93.75 MiB/s (dividing by 1,048,576). The volume is at its 3,000 IOPS limit and below its 125 MiB/s limit. The average I/O size is about 32 KiB, so IOPS binds first.
Exercise
Users report slow database queries. CloudWatch shows each of the instance's two gp3 volumes at about 60 percent of its provisioned IOPS and throughput, with low latency, yet the instance's combined EBSWriteBytes sits at the instance type's maximum EBS bandwidth. Where is the bottleneck and what do you change?
Show answer
The bottleneck is the instance's EBS bandwidth limit, which both volumes share. Raising volume IOPS or throughput will not help. Move to an instance type with higher EBS bandwidth, or reduce the I/O load on the instance.