Score:1

Why does `hdparm -t` take so long to produce accurate results on my EC2 instance?

ni flag

I'm profiling a data-processing program that I wrote and I want to understand the theoretical throughput of the machine I'm on. Specifically, I want to measure what disk read speed my g4dn EC2 instance is providing my application. This particular instance has an ephemeral NVMe drive, which is what I want to benchmark.

I notice that it takes quite a few runs of hdparm until the throughput it reports stops increasing. My question is, why does hdparm take multiple runs to get full read throughput? What is it in the Linux kernel / disk driver / drive controller / actual hardware that requires multiple runs of hdparm to get accurate results?

I know the man pages say to run it a few times, but in my experience it takes much more than the 3 times recommended for the throughput to max out.

-t     Perform timings of device reads for benchmark and
       comparison purposes.  For meaningful results, this
       operation should be repeated 2-3 times on an otherwise
       inactive system (no other active processes) with at least
       a couple of megabytes of free memory.  This displays the
       speed of reading through the buffer cache to the disk
       without any prior caching of data.  This measurement is an
       indication of how fast the drive can sustain sequential
       data reads under Linux, without any filesystem overhead.
       To ensure accurate measurements, the buffer cache is
       flushed during the processing of -t using the BLKFLSBUF
       ioctl.

I run the following to collect the read speed:

#!/usr/bin/env bash
while true; do
   sudo hdparm -t /dev/nvme0n1p1;
   sleep 1;
done

and get the following output:

$ while true; do sudo hdparm -t /dev/nvme0n1p1; sleep 1; done

/dev/nvme0n1p1:
 Timing buffered disk reads: 470 MB in  3.09 seconds = 152.30 MB/sec

/dev/nvme0n1p1:
 Timing buffered disk reads: 490 MB in  3.10 seconds = 158.21 MB/sec

/dev/nvme0n1p1:
 Timing buffered disk reads: 526 MB in  3.02 seconds = 174.43 MB/sec

It takes maybe 20 runs before it settles around 330MB/sec.

Note that I am using an AMI that has the correct NVMe drivers.

Score:1
ni flag

It turns out that the local nvme drives available on some EC2 instances by default aren't ready for use, and the "ready-for-use" nvme device is actually an EBS volume mounted as an nvme drive. This explains the low throughput (300MB/s) and slow warmup time (20 runs).

For future reference, I got 1.7GB/s sequential read speeds from the first run of hdparm when I formatted and mounted my real nvme drives. They will be visible from lsblk.

Cade Daniel avatar
ni flag
Thanks to @Peter Cordes for the help https://stackoverflow.com/questions/74465445/why-does-hdparm-t-take-so-long-to-produce-accurate-results-on-my-ec2-instance
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.