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
- Types of Load Tests
- Before You Start: Permission, Goals and Environment
- 1. Install k6
- 2. Write Your First Test Script
- 3. Run the Test
- 4. Distributed Load: Multiple Hourly Servers
- 5. Interpret the Results
- 6. Build a Capacity Plan
- After the Test: Do Not Forget to Delete the Servers
- 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 type | What it does | What question it answers |
|---|---|---|
| Smoke test | A short run with 1-2 virtual users | Do the script and site work correctly? |
| Load test | Applies the expected normal and peak load | Is speed acceptable at the target traffic? |
| Stress test | Gradually pushes load beyond the limit | At what point does the system start to break down? |
| Spike test | A sudden surge of load in a very short time | Can it handle the burst from a campaign or ad? |
| Soak test | Sustains moderate load for hours | Are 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 versionFor 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.jsWhile 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.jsIf 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
waitCollect 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:
| Metric | Meaning | How to read it |
|---|---|---|
http_req_duration p(95) | The time under which 95 percent of requests completed | More reliable than the average; shows what most users experience |
http_req_failed | The rate of failed requests | The point where it starts rising as load increases is the breaking point |
http_reqs | Total requests and requests per second | If this stops increasing while VUs increase, the server is saturated |
checks | Success rate of the checks you defined | Catches non-200 responses and incorrect content |
vus | Current number of virtual users | Shows 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
- 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.
- 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.
- 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.
- 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.