DEV Community

Cover image for Benchmarking Storage Performance (Latency, Throughput) Using Python
Arjun Mullick
Arjun Mullick

Posted on • Edited on

Benchmarking Storage Performance (Latency, Throughput) Using Python

**TL;DR: **A guide to use Python to benchmark AWS S3 storage performance by measuring how fast you can upload, download, and list files. This helps you find bottlenecks, compare storage classes, and optimize costs , accuracy and speed.

Abstract
Understanding the performance of your AWS S3 storage specifically, how quickly you can read and write data is essential for both cost optimization and application speed. By running Python scripts that measure latency (delay) and throughput (data transfer speed), you can compare different S3 storage classes and configurations, discover bottlenecks, and make informed decisions about where and how to store your data. This article explains the basics of storage benchmarking, provides easy-to-follow Python code, and shows how to interpret results even if you’re not a cloud expert.

Introduction
Not all cloud storage is created equal. AWS S3 offers several storage classes — like Standard, Intelligent-Tiering, and Glacier that balance cost and performance differently. If your application needs to access data quickly, or if you’re storing large files, knowing how your storage performs can save you time and money. Benchmarking is the process of measuring how fast you can upload, download, and list files in S3. By doing this, you can choose the right storage class for your needs and spot performance issues before they impact your users. AWS S3 storage class overview.

Prerequisites

  • 1. AWS account with S3 access.
  • 2. Python 3.x and the boto3 library installed.
  • 3. AWS credentials configured on your machine.
  • 4. Basic knowledge of Python scripting.

If you’re new to AWS or Python, here’s a getting started guide.

Analysis

Why Benchmark Storage Performance?

  • Latency is the time it takes to start a file operation (like uploading or downloading).
  • Throughput is how much data you can move per second.
  • Benchmarking helps you:
  • Compare S3 storage classes (Standard, IA, Glacier, etc.).
  • Identify slowdowns due to network, region, or storage class.
  • Optimize costs by matching performance to your workload.

For example, S3 Standard is fast but more expensive, while S3 Glacier is cheap but much slower for retrieval. AWS S3 storage class comparison.

Example: Benchmarking S3 Upload and Download with Python
Here’s a simple Python script to measure upload and download speeds for a file in S3:

import boto3
import time
s3 = boto3.client('s3')
bucket = 'your-bucket-name'
filename = 'testfile.bin'
object_name = 'benchmark/testfile.bin'
# Create a test file (10 MB)
with open(filename, 'wb') as f:
    f.write(b'0' * 10 * 1024 * 1024)
# Upload benchmark
start = time.time()
s3.upload_file(filename, bucket, object_name)
upload_time = time.time() - start
print(f'Upload time: {upload_time:.2f} seconds')
# Download benchmark
start = time.time()
s3.download_file(bucket, object_name, 'downloaded_testfile.bin')
download_time = time.time() - start
print(f'Download time: {download_time:.2f} seconds')
Enter fullscreen mode Exit fullscreen mode

This script will show you how long it takes to upload and download a 10MB file. You can adjust the file size or repeat the test for more data points.

Measuring Latency for Small Operations
For many applications, the time it takes to list files or check if a file exists (metadata operations) is just as important as upload/download speed. Here’s how to measure that:

import time
start = time.time()
response = s3.list_objects_v2(Bucket=bucket, Prefix='benchmark/')
latency = time.time() - start
print(f'List operation latency: {latency:.3f} seconds')
Enter fullscreen mode Exit fullscreen mode

Interpreting the Results

  • Shorter upload/download times mean better throughput.
  • Lower latency means your application will feel faster.
  • If you notice high latency or slow throughput, try:
  • Using a different AWS region closer to your users.
  • Switching to a faster storage class.
  • Compressing files before upload.
  • Uploading in larger batches instead of many small files.

Comparing Storage Classes
You can repeat your tests with objects stored in different classes (e.g., Standard, Standard-IA, Glacier) to see how performance changes. Remember, some classes like Glacier are designed for archival and can take minutes or hours to retrieve data.

Best Practices

  • Compress data before uploading to reduce transfer time and storage costs.
  • Batch small files into larger archives to improve throughput and reduce API call costs.
  • Use the right region to minimize latency.
  • Monitor performance regularly as your data grows or your access patterns change.

Conclusion
Benchmarking your AWS S3 storage with Python scripts is a straightforward way to measure and improve your cloud storage performance. By understanding latency and throughput, you can choose the best storage class for your needs, save money, and ensure your applications run smoothly.

References:

  1. Cost optimization — Amazon Simple Storage Service (AWS Documentation)
  2. Amazon S3 Cost Optimization: 12 Ways To Optimize Your Costs (CloudZero Blog)
  3. Performance guidelines for Amazon S3 (AWS Documentation)

Top comments (0)