18

Stress testing

The Performance view: load-test any site or API, find how many users it handles and where it breaks

10 min read9 sections

CleanLens ships a load and stress tester in the Performance view of its sidebar. Point it at any website, page or API and it tells you how many concurrent users it handles, where and why it breaks, and how many requests per second it sustains, in a report you can open in the browser.

It talks to the server over HTTP only, the way a browser does. Nothing has to be installed in the project you test, and it works on a local server, staging or production alike.

Requirements

WhatWhy
macOS or LinuxThe tester runs with bash. On Windows, use VS Code with WSL.
Python 3.9+ (python3 on the PATH)The test engine is written in Python.
Internet on the first runThe first run creates a private Python environment and installs its packages (about a minute).
Google Chrome (optional)Only for the page after login test, which opens the page in a hidden browser.
Docker Desktop (optional)Only to run your project with server specs you choose.

The Python environment, the reports and the run state live in the extension's own storage folder, so they survive extension updates and never touch your project.

Run your first test

  1. Open the CleanLens icon in the Activity Bar, then the Performance view.
  2. Click Run a stress test. The first time, a notification shows while the Python packages install.
  3. The test page opens inside VS Code. Pick what to test, fill in the details, choose how many users, and press Start the test.
  4. Follow the progress live: every load level, its success rate, its response time and a verdict. When it finishes, press Open the report.

The same page also runs in your browser: the Open in browser button at the top of the Performance view.

What you can test

ChoiceWhen to use it
A website or linkA public page or an API endpoint. The fastest: paste one or more links and start. Supports GET, POST and a JSON body, and a Bearer token.
A page after loginA dashboard or any page that needs a session. It opens the page in a hidden browser, records every request the page makes, then replays them as if many users opened it together. Log in with a token, a session cookie, or a username and password: a hidden browser fills in the site's login form, then every virtual user reuses that session (use a test account; ordinary login forms only, not 2-step verification, CAPTCHA or Google / Microsoft sign-in; the password is never saved or logged).
A scenario: several steps in a rowWhat one visitor does, like a real visit: steps written in a .yaml or .json file (log in → browse → submit a form with files…), each step using what the previous one returned. The page lists the flow files it finds in the project open in VS Code; Choose a file from the project opens VS Code's file dialog there. Bundled examples are listed too, and Create an example in my project writes a commented stress-tests/example-scenario.yaml into the project and opens it.

How many users

OptionWhat it does
Levels I chooseRuns fixed user counts, e.g. 10,50,100. Safe for real sites.
Find the limit automaticallyDoubles the users until the site stops, then narrows down the exact limit.
Spread arrivals over N secondsUsers arrive gradually instead of all in the same instant.

Server specs

Card 3 of the test page (Server specs) decides which server takes the load:

ChoiceWhat happens
The server as it isThe links you wrote are tested directly, on whatever machine runs them now.
Run my project with specs I chooseYour project starts in Docker, limited to the CPU, memory and workers you pick. The test runs against it, and the server and its data are deleted at the end, even when you stop the test.

With chosen specs the numbers match a server the size of your real one, not the size of your laptop, so you can answer "is the small plan enough, or do we need the medium one?" by running the same test on both.

  • Specs: a ready size (small, medium, large, production) or Specs I choose: CPU cores, memory in GB, workers and threads per worker. The database can be SQLite (a copy of your local one), an empty PostgreSQL, or PostgreSQL (a copy of my local database): your local database as it is, copied read only (the original never changes) and deleted with the test server. Enter its address on the page (postgresql://user:password@localhost:5432/mydb), or set postgres.source once in the project's server.yaml. The address is never written to the log.
  • Project: described once in a server.yaml (how to build it, the command that starts it, its port, its database). Press Add a project on the page, or run CleanLens: Add Stress Test Project: CleanLens creates the file from a template and opens it. Set context to your project's folder and adjust the start command. Your projects live in the extension's storage and survive updates.
  • What to test: in a website or link, write only the path, such as /api/items/; it goes to the started server. A user journey is sent to the project's API automatically.
  • The first run builds the project's image, which takes a few minutes. The report records the specs and the server's peak CPU and memory.

When the site refuses the token

  • Token format: choose what the site writes before the token: Bearer (the default), JWT, Token, or the token alone. To check, open the site, press F12, Network, click a data request and look at Authorization under Request Headers.
  • Also put the token in the browser's Local Storage (page after login): for sites whose page reads the token from Local Storage itself. Give the key you copied it from (usually accessToken). Without it such a page goes straight to its login screen, and the test now stops and says so.
  • The server's own message is shown when it refuses the login, for example "Given token not valid for any token type" (expired or wrong token) or "Authentication credentials were not provided." (wrong format, or the site expects a cookie).
  • The token is passed to the test through the environment: it no longer appears in the technical log.
  • When a token keeps expiring, use Username and password: a hidden browser signs in for every test and takes the session the site gives it.

Before the load: the check visit

Every test starts with one small visit, before any load is sent.

  • If the server refuses the login (401 / 403: an expired, incomplete or wrong token or cookie), the test stops right away and says so. A test that only gets refusals measures nothing: refusing a request is cheap for the server, so the site would look untouched.
  • If the site does not answer at all, the test stops too.
  • When a level fails, the higher levels are skipped (the site has already given way). Add --keep-going on the command line to run them anyway.
  • If the login starts being refused in the middle of a test (a token that expires), the verdict is Not measured: the login was refused, never "Not ready".

Deciding whether to publish

Step 05 on the test page (Ready to publish?) turns the result into a go / no-go decision.

  • Expected visitors at the same moment (peak): this number is always tested, even if your levels skip it.
  • Keep the load for 1, 2 or 5 minutes: every virtual user repeats its visit for that long, on every level, instead of visiting once. A server can survive a short burst and still sink after a minute (memory, database connections, a growing queue), and only sustained load shows it. The tool compares the first third of each level with the last third and marks a level that gets worse over time.
VerdictMeaning
Ready to publishHealthy at 1.5 times the expected peak or more
Ready, with little headroomHealthy at the expected peak, but not shown healthy at 1.5 times it
RiskyAt the expected peak it works, but slowly, with errors, or it gets worse while the load lasts
Not ready to publishIt failed at the expected peak, or before reaching it
Not tested at the expected loadNo level reached the expected peak

The verdict also has a confidence: high when the load was kept for a minute or more, medium for shorter sustained load, low for bursts only. Decide on a high-confidence verdict, and test a staging copy with the same specs as production rather than the live site.

Reading the results

Every level gets a verdict:

VerdictConditionMeaning
Passsuccess ≥ 99% and p95 < 2 sUsers notice nothing
Slowsuccess ≥ 95% and p95 < 5 sIt works, but users wait
Failanything elseMany errors or very long waits

p95 is the time within which 95% of users finished. It matters more than the average, which hides the slow tail.

The summary at the top of the report gives the four numbers that matter: the safe limit (highest level that passed), the level it still worked at, the level where it broke, and the peak requests per second. When the site breaks, the report names the cause in plain words, for example "the server refused new connections" or "requests timed out".

Past reports

The Reports list in the Performance view shows every past test, newest first, with its safe limit, the level it broke at and its peak req/s. Click one to open the full report in your browser (in Arabic when VS Code is in Arabic, otherwise in English). Open Reports Folder in the view's … menu shows the files: each test writes an HTML report, the same report in Arabic, and the raw .json.

Testing safely

  • The test page listens on 127.0.0.1 only, and every action needs a secret key that changes on each start, so other sites open in your browser cannot start a test.
  • Only test servers you own or have permission to test. A load test against someone else's site can look like an attack.
  • Testing a server that is not on your machine shows a red warning and does not start until you confirm you own it. Find the limit or more than 1,000 users on a remote server needs a second confirmation that you accept the site may go down.
  • Prefer staging over production. On production, start with small levels and run outside peak hours.
  • One test runs at a time. Stop the test stops it safely.

Commands

CommandWhat it does
CleanLens: Open Performance (Stress Test)Starts the test service if needed and opens the test page in VS Code
CleanLens: Open Stress Test in BrowserOpens the same page in your browser
CleanLens: Add Stress Test ProjectCreates a project's server.yaml from the template, for testing with chosen specs
CleanLens: Stop Stress Test ServiceStops the service and any running test (also the stop icon on the status row)
CleanLens: Show Stress Test LogThe service's output, useful when something fails
CleanLens: Refresh Performance ReportsReloads the reports list
CleanLens: Open Stress Test Reports FolderOpens the folder that holds the reports

Troubleshooting

ProblemFix
"Stress testing needs bash and Python 3"You are on Windows: open the folder in VS Code with WSL.
"stress-service exited" right after startingpython3 is missing or too old. Install Python 3.9+ and try again. Show Stress Test Log has the details.
The first start takes longIt is installing the Python packages. Later starts take a second.
"No Chromium found" (page after login)Install Google Chrome.
"Docker is not running" under server specsStart Docker Desktop, then press Refresh the list.
"The server did not come up"The project's container stopped while starting: the log in the page shows why (often the start command or context in server.yaml).
Every level fails at once with connection errorsThe address is wrong or the server is down: open the link in your browser first.
A remote site fails at low levels with 429Its rate limit blocks repeated requests from one address. Test a staging copy with higher limits.