FileDummy Logo
FileDummy
Kiểm Thử & QA Với Tệp Tin

Load Test Tải Tệp Dung Lượng Lớn Với Grafana k6 & Apache JMeter

Kiểm thử tải endpoint download tệp với hàng trăm kết nối đồng thời sử dụng k6 và JMeter. Đo lường băng thông CDN và khả năng chịu tải origin.

17 tháng 9, 202611 phút đọc1,420 lượt xem
k6jmeterload-testingperformancefile-download

Stress testing file download endpoints guarantees that your CDN, edge caching rules, and origin object storage servers handle concurrent spikes without throttling or high error rates. This guide demonstrates how to build load tests using Grafana k6 and Apache JMeter.

Writing a File Download Load Test with Grafana k6

k6 is a modern, developer-friendly load testing tool written in Go with JavaScript test scripting.

JavaScript
import http from 'k6/http';
import { check, sleep } from 'k6';

export const options = {
  stages: [
    { duration: '30s', target: 20 },  // Ramp up to 20 users
    { duration: '1m', target: 50 },   // Maintain 50 concurrent downloads
    { duration: '20s', target: 0 },   // Ramp down
  ],
  thresholds: {
    http_req_duration: ['p(95)<1500'], // 95% of requests must finish under 1.5s
    http_req_failed: ['rate<0.01'],    // Error rate must remain under 1%
  },
};

export default function () {
  const url = 'https://filedummy.dev/api/download?type=pdf&size=10mb';
  const res = http.get(url, {
    responseType: 'binary',
  });

  check(res, {
    'status is 200': (r) => r.status === 200,
    'content length matches': (r) => r.body.length === 10485760,
    'cache-control is present': (r) => r.headers['Cache-Control'] !== undefined,
  });

  sleep(1);
}
Verified Test Asset.pdf

Run high-concurrency download benchmarks using our globally cached 10MB test file.

Tải File Mẫu 10MB PDF Test →

Configuring Apache JMeter for Download Load Testing

  1. Create a Thread Group with your desired number of concurrent virtual users (e.g. 100 threads, 30-second ramp-up).
  2. Add an HTTP Request sampler pointing to your download URL.
  3. Check the Save response as MD5 hash box if you do not want JMeter to retain massive multi-gigabyte payloads in test runner memory.
  4. Add a Response Assertion checking for HTTP 200 and valid headers.

Metrics to Track During File Download Tests

  • Throughput (MB/s): Aggregate network egress from your origin or CDN.
  • Time to First Byte (TTFB): Highlights whether origin lookup or presigned URL signing is creating bottlenecks.
  • Error Spikes (HTTP 429 / 503): Indicates rate limiting or upstream connection pool saturation.
NDL

Nguyễn Đại Long

Tác Giả

Backend Lead • Chuyên gia Kiến trúc Hệ thống Phân tán & Lưu trữ Đám mây

Hơn 4 năm kinh nghiệm thiết kế các hệ thống xử lý tệp tải lên thông lượng lớn, tối ưu hóa cơ sở dữ liệu và hạ tầng phân tán Cloudflare R2 / AWS S3. Người sáng lập FileDummy và Mạng lưới Hệ sinh thái NDL.

Bài viết này có hữu ích không?

Bấm Thích để ủng hộ tác giả và giúp bài viết lan tỏa tới cộng đồng lập trình viên.

Thảo Luận Kỹ Thuật & Đóng Góp Ý Kiến (0)

Chia sẻ kết quả benchmark, phản hồi các trường hợp biên hoặc đặt câu hỏi chuyên môn.

0/3000

Chưa có bình luận nào. Hãy là lập trình viên đầu tiên bắt đầu cuộc thảo luận!

Câu Hỏi Thường Gặp (FAQ)

What is the difference between k6 and JMeter for load testing?

k6 uses JavaScript test scripts, has a modern CLI, generates no GUI overhead, and integrates well with CI/CD. JMeter is a mature Java tool with a GUI, supports more protocol types (FTP, JDBC, SOAP), and has a larger plugin ecosystem. k6 is preferred for HTTP/API load testing.

How do I measure download throughput in k6?

k6 automatically tracks http_req_receiving duration and data_received bytes per request. Calculate throughput as data_received / test_duration. Use k6's Trend metric type for custom throughput measurements.

How many virtual users do I need to load test a CDN?

CDNs handle massive concurrency. To meaningfully test, bypass the CDN and test the origin directly. Typical origin servers should handle 50–500 concurrent file download requests before saturating CPU or bandwidth.

Bài Viết Liên Quan