Why monitoring matters in AWS - Performance Analysis
Monitoring in AWS helps us keep track of how systems perform over time.
We want to understand how the cost of monitoring changes as the amount of data grows.
Analyze the time complexity of the following AWS CloudWatch metric retrieval code.
const AWS = require('aws-sdk');
const cloudwatch = new AWS.CloudWatch();
async function getMetrics(metricNames) {
const results = [];
for (const name of metricNames) {
const data = await cloudwatch.getMetricData({
MetricDataQueries: [{ Id: 'm1', MetricStat: { Metric: { MetricName: name, Namespace: 'AWS/EC2' }, Period: 60, Stat: 'Average' }, ReturnData: true }]
}).promise();
results.push(data);
}
return results;
}
This code fetches metric data for each metric name from AWS CloudWatch one by one.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Loop over each metric name to fetch data.
- How many times: Once per metric name in the input list.
As the number of metric names increases, the number of fetch calls grows the same way.
| Input Size (n) | Approx. Operations |
|---|---|
| 10 | 10 metric fetch calls |
| 100 | 100 metric fetch calls |
| 1000 | 1000 metric fetch calls |
Pattern observation: The work grows directly with the number of metrics to fetch.
Time Complexity: O(n)
This means the time to get all metrics grows in a straight line as you add more metrics.
[X] Wrong: "Fetching multiple metrics at once is always faster regardless of how many there are."
[OK] Correct: Sometimes fetching many metrics individually can slow things down because each call waits for the last one to finish.
Understanding how monitoring scales helps you design systems that stay reliable as they grow.
"What if we fetched all metrics in a single batch call instead of one by one? How would the time complexity change?"