पाठ 22 / 30
Validating Estimates with Load Tests
यह पाठ अभी हिंदी में अनुवादित नहीं है, इसलिए अंग्रेज़ी में दिखाया जा रहा है।
Design a load test that measures per-server throughput and finds the latency knee.
लेखक: Rahul Agarwal · 15 साल से वेब डेवलपर
Turn assumptions into measurements
An estimate is a hypothesis; a load test checks it. The goal is a number you can plug back into the formulas: the sustainable throughput per instance at an acceptable latency. Run the real service on production-like hardware and data, then increase load in steps (a ramp) while recording throughput, error rate and latency percentiles (p50, p95, p99), plus CPU, memory, connection pool usage and I/O. Plot latency against throughput: it stays flat, then bends sharply upward at the knee. Plan capacity somewhat below the knee, not at the maximum throughput reached before errors. Pitfalls include testing with tiny datasets that fit in cache, using one client machine that becomes the bottleneck itself, ignoring think time and realistic request mixes, and running too briefly to see garbage-collection pauses, connection exhaustion or memory leaks.
Ramp until the curve bends
Start with baseline load, ramp in steps, observe where latency bends sharply at the knee, then plan capacity below that point.
A stepped load test with k6
A k6 script that ramps virtual users in stages and fails the run if p95 latency or the error rate crosses a threshold. Point it at a staging environment, never production without agreement.
import http from 'k6/http';
import { sleep } from 'k6';
export const options = {
stages: [
{ duration: '2m', target: 50 },
{ duration: '5m', target: 200 },
{ duration: '5m', target: 400 },
{ duration: '2m', target: 0 },
],
thresholds: {
http_req_duration: ['p(95)<300'],
http_req_failed: ['rate<0.01'],
},
};
export default function () {
http.get('https://staging.example.com/api/menu');
sleep(1);
}Find the knee from your own results
Find the highest step where p95 stayed within your target and errors stayed near zero, then plan on maybe 60 to 70% of that. Write the result down as the new per-server assumption.
त्वरित जाँच: Why should you not plan capacity at the maximum throughput a load test reached?
- Because load tests always overestimate throughput by exactly 2x
- Because providers forbid running servers at maximum
- Because latency rises sharply near the knee, leaving no headroom for spikes, failures or deploys
- Because maximum throughput is only reached with spot instances
Answer
Because latency rises sharply near the knee, leaving no headroom for spikes, failures or deploys — Near saturation, latency and errors climb rapidly. Planning below the knee keeps latency stable and leaves room for real-world variation.