Module 95: Scaling

Lesson 1 of 5 · 15–25 minutes

Measuring performance

🏠The everyday picture

A doctor doesn't prescribe medicine before taking your temperature and blood pressure. Guessing at a cure wastes time and can make things worse.

📘What it really is

import http from "k6/http";
import { check, sleep } from "k6";

export const options = {
  stages: [
    { duration: "2m", target: 100 },  // ramp up to 100 virtual users
    { duration: "5m", target: 100 },  // hold
    { duration: "1m", target: 0 },
  ],
  thresholds: { http_req_duration: ["p(95)<800"], http_req_failed: ["rate<0.01"] },
};

export default function () {
  const res = http.get("https://staging.example.in/v1/tutors?subject=maths");
  check(res, { "status is 200": (r) => r.status === 200 });
  sleep(1);
}

🖱️Try it

Write a k6 test for the booking platform's three busiest operations (search tutors, view slots, create booking with test data) on staging. Run a load test at your expected peak and a stress test until errors appear. Record p95 latency, throughput and the first resource to saturate. Fix the top bottleneck and re-run.

✅Quick check

Why look at the 95th percentile rather than the average?

Show the answer

The average hides slow requests; the p95 shows what the slower users actually experience.

What does a stress test find?

Show the answer

The system's limit and its first bottleneck, by increasing load until something breaks.

← BackModule 95
ProLearners Assist