EN · $ USD
VDS and Linux Server Management

How to Load Test a Website: A Step-by-Step Guide with k6

8 min read Updated: Sunucu Atlas technical team

In short

Load testing a website means sending controlled virtual user traffic to it to measure response times and error rates. With k6, you write a test script in JavaScript, define a gradual ramp-up and thresholds, and run the test from a machine separate from your web server. You then watch p95 response time and the http_req_failed rate; the user count at which performance degrades shows your capacity limit.

In this guide
  1. Types of Load Tests
  2. Before You Start: Permission, Goals and Environment
  3. 1. Install k6
  4. 2. Write Your First Test Script
  5. 3. Run the Test
  6. 4. Distributed Load: Multiple Hourly Servers
  7. 5. Interpret the Results
  8. 6. Build a Capacity Plan
  9. After the Test: Do Not Forget to Delete the Servers
  10. Spin Up a Server Ready for Load Testing

Load testing is the process of sending controlled virtual user traffic to your website or API to measure how response times and error rates change as load increases. The goal is to find out how many concurrent users your site can handle at an acceptable speed before real visitors arrive. This guide walks you step by step through writing a test script with the open source k6 tool, running the test from hourly servers separate from your web server, and interpreting the results to build a capacity plan.

Types of Load Tests

"Load testing" is often used as an umbrella term for several different tests. Knowing which one you are running is the first step to interpreting the results correctly.

Test typeWhat it doesWhat question it answers
Smoke testA short run with 1-2 virtual usersDo the script and site work correctly?
Load testApplies the expected normal and peak loadIs speed acceptable at the target traffic?
Stress testGradually pushes load beyond the limitAt what point does the system start to break down?
Spike testA sudden surge of load in a very short timeCan it handle the burst from a campaign or ad?
Soak testSustains moderate load for hoursAre there memory leaks or resource exhaustion?

Before You Start: Permission, Goals and Environment

  • Test only your own systems. Sending load to a site you do not own can be considered a denial-of-service attack. If your site runs at a hosting provider, notify them before testing; otherwise the traffic may be flagged as an attack and blocked.
  • Write your goal as a number. Instead of "it should be fast," set a measurable goal such as "p95 response time under 800 ms and error rate under 1 percent at 200 concurrent users."
  • Run the test from a separate machine. If you install the load generator on the web server, the two jobs share the same CPU and the results are misleading. For tests run from a home or office connection, the bottleneck is often your own connection.

That is why the most reliable approach is to use a well-connected server, independent of the web server, as the load generator. Since the test lasts only a few hours, an hourly Ryzen VDS is ideal: its Istanbul location lets you measure from a network position close to a visitor base in Türkiye, and you delete the server when the test is over.

1. Install k6

k6 is an open source load testing tool developed by Grafana Labs, with test scripts written in JavaScript. The quickest way to install it is the Docker image; if your server does not have Docker, follow the how to install Docker on Ubuntu guide:

docker pull grafana/k6
docker run --rm grafana/k6 version

For installing directly with a package manager (apt, Homebrew, winget), see the official k6 installation docs. The commands in this guide work with either installation method.

2. Write Your First Test Script

The test.js file below is a load test with a gradual ramp-up and defined thresholds. stages sets how the number of virtual users (VUs) changes over time, and thresholds sets the conditions the test must meet to pass:

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

export const options = {
  stages: [
    { duration: '2m', target: 50 },   // ramp up to 50 users
    { duration: '5m', target: 50 },   // hold steady
    { duration: '2m', target: 200 },  // ramp up to peak
    { duration: '5m', target: 200 },  // hold at peak
    { duration: '2m', target: 0 },    // ramp down
  ],
  thresholds: {
    http_req_failed: ['rate<0.01'],    // error rate under 1%
    http_req_duration: ['p(95)<800'],  // p95 under 800 ms
  },
};

const BASE = __ENV.BASE_URL || 'https://www.ornek-siteniz.com';

export default function () {
  const ana = http.get(`${BASE}/`);
  check(ana, { 'ana sayfa 200': (r) => r.status === 200 });
  sleep(Math.random() * 3 + 1);

  const kategori = http.get(`${BASE}/kategori/ornek`);
  check(kategori, { 'kategori 200': (r) => r.status === 200 });
  sleep(Math.random() * 3 + 1);

  const arama = http.get(`${BASE}/?s=sunucu`);
  check(arama, { 'arama 200': (r) => r.status === 200 });
  sleep(Math.random() * 3 + 1);
}

A few important details:

  • sleep: Real users pause to think between pages. Without waits, each VU sends dozens of requests per second, creating load that does not represent real traffic.
  • Realistic paths: Testing only the home page just hits the cache. Be sure to include requests that cannot be cached and go to the database, such as search, add to cart or login.
  • Static files: k6 is not a browser; it does not automatically download CSS, JS and images. This is usually what you want when measuring your server's page generation capacity.

3. Run the Test

First confirm the script works with a short single-user smoke test, then start the full test:

# Smoke test: 1 user, 30 seconds
docker run --rm -i -e BASE_URL=https://www.ornek-siteniz.com grafana/k6 run --vus 1 --duration 30s - < test.js

# Full test, summary saved as JSON
docker run --rm -i -v "$PWD:/out" -e BASE_URL=https://www.ornek-siteniz.com \
  grafana/k6 run --summary-export=/out/sonuc.json - < test.js

While the test runs, monitor CPU and RAM usage on your web server with htop, along with the web server error log and database load, in a separate terminal. k6 tells you "how slow" it is; server metrics tell you "why it is slow."

4. Distributed Load: Multiple Hourly Servers

If a single load generator's CPU or network connection is saturated, what you are measuring is the test machine's limit, not your site's. If CPU usage on the load generator stays above 80 percent, it is time to split the load.

In the open source version of k6, the execution segment feature lets you split the same script across multiple machines. For example, to split the load in two with two hourly Intel VDS or Ryzen servers:

# Server 1
k6 run --execution-segment "0:1/2" --execution-segment-sequence "0,1/2,1" test.js

# Server 2
k6 run --execution-segment "1/2:1" --execution-segment-sequence "0,1/2,1" test.js

If you run k6 with Docker, add the same flags to the docker run ... grafana/k6 run command. After preparing a calistir.sh script on each server containing its own segment command, you can trigger them over SSH from your local computer to start the tests at the same time:

for h in YUK1_IP YUK2_IP; do
  ssh root@$h "cd /root && ./calistir.sh" &
done
wait

Collect the summary JSON files from each machine and combine the request counts. Percentiles (p95) cannot be added up directly across machines; evaluate each machine's p95 separately and use the worst one as your reference. If you will run a large number of VUs, raise the open file limit on the server with ulimit -n 65535.

5. Interpret the Results

When the test finishes, k6 prints a summary to the terminal. These are the metrics that matter for capacity planning:

MetricMeaningHow to read it
http_req_duration p(95)The time under which 95 percent of requests completedMore reliable than the average; shows what most users experience
http_req_failedThe rate of failed requestsThe point where it starts rising as load increases is the breaking point
http_reqsTotal requests and requests per secondIf this stops increasing while VUs increase, the server is saturated
checksSuccess rate of the checks you definedCatches non-200 responses and incorrect content
vusCurrent number of virtual usersShows the load at which you measured the other metrics

Why p95 instead of the average? The average response time may look like 300 ms while some users are waiting several seconds. p95 makes that tail visible. For stricter goals, also look at p99.

If any threshold is exceeded, k6 exits with a nonzero exit code. That means you can add the same test to your CI pipeline and keep a release that degrades performance from shipping.

6. Build a Capacity Plan

  1. Find the breaking point. In the stress test, note the VU count at which p95 exceeds your goal or the error rate starts to climb.
  2. Match it to the bottleneck. At that moment, was it CPU, RAM, disk or database connections that saturated on the web server? You can use the commands in the server slowed down: finding CPU, RAM and disk bottlenecks article for this.
  3. Leave headroom. As a guideline, aim for your highest expected traffic to stay well below the breaking point; common practice is a safety margin of at least 30-50 percent.
  4. Improve and measure again. After every change, such as caching, query optimization or a more powerful server, run the same script again. Using the same script is the only reliable way to compare the impact of changes.

For specific preparation for traffic spikes, our site crashing during a campaign: preparing for sudden traffic surges guide complements these steps.

After the Test: Do Not Forget to Delete the Servers

Load generator servers are only needed for the duration of the test. After downloading the sonuc.json files to your computer with scp, delete the hourly servers from the panel; with most hourly models, just powering them off does not stop billing.

Spin Up a Server Ready for Load Testing

For single-machine tests, the FLEX-R9-4 with 2 CPUs and 8 GB of RAM is usually enough to generate a few hundred virtual users in scripts with realistic wait times; for larger tests, you can use several hourly Ryzen or Intel servers together with execution segments. All hourly servers come with NVMe storage, a 1G port and automatic setup. For questions about your test plan, open a support ticket with Sunucu Atlas to get help (support is provided in Turkish).

Frequently asked questions

Will a load test harm my site?

Your site may slow down or return temporary errors during the test; no permanent damage is expected. If you are testing a live site, pick low-traffic hours and notify your hosting provider in advance.

Is k6 free?

Yes, k6 is open source and free. Grafana Labs also offers a paid cloud service, but every step in this guide can be done with the free open source version.

What does p95 response time mean?

It means 95 percent of requests completed in less than this time. Because it reveals slow requests that the average hides, it is a more reliable measure for performance goals.

Can I run a load test from my own computer?

You can for small tests, but your home or office internet connection and your computer's CPU quickly become the bottleneck. For more realistic results, test from a separate, well-connected server.

How many virtual users should I test with?

Start with the number of concurrent users at the busiest moment in your analytics data, then run a stress test that goes up to two to three times that. This is a guideline; raise the target based on what you expect from a campaign.

What server size should I choose for testing?

For a few hundred virtual users, a server with 2 CPUs and 4-8 GB of RAM is usually enough. If the load generator's CPU stays above 80 percent, split the load onto a second server.

For this guide

Recommended plans

Hourly Ryzen and Intel VDS plans let you run load tests from a machine independent of your web server, generate distributed load from several servers when needed, and delete them when the test ends so you pay only for the testing hours.

FLEX-R9-1

RYZEN
Recommended

2 GB RAM

$0.01/hr

+VAT

  • Processor2 CPU
  • Disk30 GB NVMe
  • LocationIstanbul
  • 1G Port
  • Hourly Billing

FLEX-R9-2

RYZEN

4 GB RAM

$0.01/hr

+VAT

  • Processor2 CPU
  • Disk40 GB NVMe
  • LocationIstanbul
  • 1G Port
  • Hourly Billing

FLEX-R9-3

RYZEN

6 GB RAM

$0.01/hr

+VAT

  • Processor2 CPU
  • Disk50 GB NVMe
  • LocationIstanbul
  • 1G Port
  • Hourly Billing

Hourly Ryzen VDS — tüm paketler Hourly Intel VDS — tüm paketler

Need help with setup?

Send questions about your service in a support ticket, and our technical team will walk you through it step by step.