QA AND TEST AUTOMATION · PART 9 · NON-FUNCTIONAL TESTING · PERFORMANCE · 80 OF 112

Performance Testing: Load, Stress, Soak and Spike

What performance testing answers and how to plan it: load, stress, spike, soak, scalability and capacity tests, a workload model built from real traffic, think time, test environments and load generators, and the measured shape of a stress test on ShopRung with Locust, where throughput levels off while response times keep rising.

  1. 1
  2. 2
  3. 3
  4. 4
  5. 5
  6. 6
  7. 7
  8. 8
  9. 9
  10. 10
  11. 11
  12. 12
  13. 13
  14. 14
  15. 15
  16. 16
  17. 17
  18. 18
  19. 19
  20. 20
  21. 21
  22. 22
  23. 23
  24. 24
  25. 25
  26. 26
  27. 27
  28. 28
  29. 29
  30. 30
  31. 31
  32. 32
  33. 33
  34. 34
  35. 35
  36. 36
  37. 37
  38. 38
  39. 39
  40. 40
  41. 41
  42. 42
  43. 43
  44. 44
  45. 45
  46. 46
  47. 47
  48. 48
  49. 49
  50. 50
  51. 51
  52. 52
  53. 53
  54. 54
  55. 55
  56. 56
  57. 57
  58. 58
  59. 59
  60. 60
  61. 61
  62. 67
  63. 68
  64. 69
  65. 70
  66. 71
  67. 72
  68. 73
  69. 74
  70. 75
  71. 76
  72. 77
  73. 78
  74. 79
  75. 80
  76. 81
  77. 82
  78. 83
  79. 84
  80. 85
  81. 86
  82. 87
  83. 88
  84. 89
  85. 90
  86. 91
  87. 92
  88. 93
  89. 94
  90. 95
  91. 96
  92. 97
  93. 98
  94. 99
  95. 100
  96. 101
  97. 102
  98. 103
  99. 104
  100. 105
  101. 106
  102. 107
  103. 108
  104. 109
  105. 110
  106. 111
  107. 112
1 / 11

Press play to hear the narration, or step through at your own pace.

Key takeaways

  • Load, stress, spike, soak, scalability
  • workload model
  • think time
  • saturation
  • separate generators

Notes

The setup

A performance test has three parts. A script describes what one user does: browse, search, add to cart, pay. A load generator, such as k6, JMeter or Locust, runs that script for many virtual users at once and measures every response: how long it took, its status, and whether it failed. At the same time, monitoring watches the servers' CPU, memory and database, so you can explain what you see.

How it works
  • a script describes what one user does (browse, search, add to cart, pay)
  • the load generator runs many virtual users at once
  • it measures every response: time, status, errors
  • monitoring watches the servers at the same time

Types of test

The main types. A load test runs the expected peak traffic and asks: is it fast enough? A stress test goes beyond the peak to find where and how it breaks, and whether it recovers. A spike test jumps suddenly, like a sale starting at nine. A soak test, also called endurance, runs normal load for hours to find memory leaks and slow growth. A scalability test adds servers and checks capacity grows with them.

Types
  • load: expected peak traffic. Fast enough?
  • stress: beyond the peak. Where and how does it break?
  • spike: sudden jump. Survives?
  • soak: normal load for hours. Leaks, slow growth?
  • scalability: add servers, does capacity grow?

Workload model

A test is only as good as its workload model. Take it from analytics or server logs: which journeys, in what mix, at what peak rate. For our ShopRung script, half the requests browse products, a third search, and the rest open a product page; a full model would add checkout as a smaller share. Add think time, the pauses a real person makes between steps. Without it, a hundred virtual users behave like thousands of real ones.

ShopRung workload
  • from analytics or logs: 50% browse products 33% search 17% open a product (real model: + checkout)
  • peak: users and requests per second at the busiest hour
  • think time: pauses between steps, like a real person

A Locust script

Here is the script we ran, in Locust, a Python load tool. A shopper class is one virtual user. Wait time between one and three seconds is the think time. Tasks are weighted three, two and one, which gives the browse, search and product mix. With fifty users for thirty seconds, ShopRung answered about twenty four requests per second, with a median of two milliseconds and no errors.

locustfile.py
class Shopper(HttpUser):
  wait_time = between(1, 3)

  @task(3)
  def browse(self):
    self.client.get("/api/products")
  @task(2)
  def search(self):
    self.client.get(
      "/api/products?q=mug")
  @task(1)  # open one product

Stress, measured

Then a stress run: no think time, so every user fires requests as fast as possible. With ten users, ShopRung served about seventeen hundred requests per second, ninety fifth percentile six milliseconds. With fifty, about nineteen hundred, at twenty seven milliseconds. With two hundred, still about two thousand, but fifty seven milliseconds. Throughput levelled off while response times kept rising: the system was saturated.

Locust, 20 s each, no waits
users   req/s    p95     errors
   10  ~1,700    6 ms   0
   50  ~1,900   27 ms   0
  200  ~1,900-2,000
               57 ms   0

throughput levels off,
response time keeps rising

Be honest

Now the honest part. Locust itself warned that its CPU was above ninety percent, because the load generator and ShopRung shared one small two CPU machine. So the shape is real, but these numbers are not ShopRung's true capacity. In real tests, generators run on separate machines, sometimes many of them, and you monitor the generators too. An overloaded generator reports slow responses that the server never caused.

What the run warned
  • Locust: "CPU usage above 90%"
  • generator and ShopRung shared one 2-CPU machine → the SHAPE is real; the numbers are not ShopRung's true capacity
  • real tests: generators on separate machines, monitored like the app

Environment

Environment matters. Test on something production like: the same server sizes, configuration and data volume, because a query that is fast on a hundred rows can be slow on ten million. Keep it isolated, so other testing does not distort results. Warm up before measuring. Keep test and environment the same between runs, so you can compare them. And never load test production without a plan, approval and a quiet time.

Environment rules
  • production-like: same sizes, config, data volume
  • isolated: nobody else testing
  • warm up first, then measure
  • same test, same environment → comparable runs
  • production only with a plan, approval, off-peak

Common mistakes

Mistakes. No think time, so the load is unrealistic. Hitting one URL instead of real journeys. A tiny data set that fits in memory. The generator on the same machine as the app. Looking only at averages, which the next episode explains. Testing once, just before release. And no goal: make it fast is not a requirement, while ninety fifth percentile under five hundred milliseconds at two hundred requests per second is.

Avoid these
  • no think time
  • one URL instead of journeys
  • tiny test data set
  • generator on the same box
  • averages only (see next ep)
  • testing once, at the end
  • no goal: "make it fast"

Say it like this

In the interview: start from goals, like a ninety fifth percentile and error rate at a target request rate. Build the workload model from real traffic, with think time. Run a load test at peak, a stress test beyond it, a spike test and a soak test. Use a production like environment, separate load generators, and monitor the servers. Compare every run against a baseline, so changes show up.

In the interview
  • "Start from goals: p95 and error rate at a target rate.
  • Build the workload model from real traffic with think time, then run load at peak, stress
  • past it, spike, and a soak.
  • Production-like environment, separate generators, servers
  • monitored, and compare runs
  • against a baseline."

Interview questions

Q1What is the difference between load and stress testing?

Load testing checks behaviour at expected peak traffic; stress testing goes beyond it to find the breaking point and how the system fails and recovers.

Q2What is a soak test?

Running normal load for a long period, often hours, to find memory leaks, resource exhaustion and gradual slowdowns.

Q3What is a spike test?

A sudden large jump in load, such as a sale starting, to see whether the system survives and recovers.

Q4What is a workload model?

The mix of user journeys, their proportions, peak rates and think times, taken from real traffic data.

Q5Why add think time?

Real users pause between actions; without think time, a few virtual users generate far more load than the same number of real users.

Q6What does saturation look like in results?

Throughput stops increasing as users are added while response times keep rising.

Q7Why run load generators on separate machines?

An overloaded generator adds its own delay and reports slow responses the server never caused.

Q8What makes a good performance goal?

A measurable target such as p95 under 500 ms and errors under 1% at 200 requests per second, not "make it fast".