Bencher Self-Hosted with Docker Quick Start
What is Bencher?
Bencher is a suite of continuous benchmarking tools. Have you ever had a performance regression impact your users? Bencher could have prevented that from happening. Bencher allows you to detect and prevent performance regressions before they make it to production.
- Run: Run your benchmarks locally or in CI using your favorite benchmarking tools. The
bencher
CLI simply wraps your existing benchmark harness and stores its results. - Track: Track the results of your benchmarks over time. Monitor, query, and graph the results using the Bencher web console based on the source branch, testbed, benchmark, and measure.
- Catch: Catch performance regressions in CI. Bencher uses state of the art, customizable analytics to detect performance regressions before they make it to production.
For the same reasons that unit tests are run in CI to prevent feature regressions, benchmarks should be run in CI with Bencher to prevent performance regressions. Performance bugs are bugs!
Bencher Self-Hosted
Bencher is open source and self-hostable. If you are interested in using Bencher Cloud, check out the Bencher Cloud Quick Start tutorial. This tutorial will get you setup using Bencher Self-Hosted with Docker.
🐰 Once you feel comfortable using Bencher Self-Hosted, consider checking out the following resources:
Install Docker
In order to run the UI and API servers in this tutorial you will need to have docker
installed.
Check to see if you have docker
installed.
Run: docker --version
You should see something like:
It is okay if your version number is different. It’s just important that this command works.
If not follow the instructions for installing docker
.
Install bencher
CLI
Linux, Mac, & Unix
For Linux, Mac, and other Unix-like systems run the following in your terminal,
with BENCHER_VERSION
set to a recent version like 0.4.30
:
Windows
For Windows systems run the following in a PowerShell terminal,
with BENCHER_VERSION
set to a recent version like 0.4.30
:
🐰 If you get an error that says
running scripts is disabled on this system
:
Open Powershell
withRun as Administrator
- Run:
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
- Enter:
Y
- Rerun this script
For additional installation options, see how to install the bencher
CLI.
Now, lets test that we have the bencher
CLI installed.
Run: bencher --version
You should see:
Run Bencher UI & API Servers
With docker
installed, we can now run the UI and API servers.
Run: bencher up
You should see something like:
Again, it is okay if your output is different. It’s just important that this command works.
🐰 If you get an error from
ghcr.io
saying:"authentication required"
Try running:docker logout ghcr.io
🐰 On Windows, if you get an error saying:
image operating system "linux" cannot be used on this platform: operating system is not supported
Try running:& 'C:\Program Files\Docker\Docker\DockerCli.exe' -SwitchLinuxEngine
Bencher API Server Logs
Because we haven’t set up email/SMTP on the API server yet,
the confirmation codes you will receive later in the tutorial are going to be in the server logs, as shown above.
That is, the authentication credentials are going to be shown in the output of bencher up
.
Set Bencher Host
The bencher
CLI default host is Bencher Cloud (ie https://api.bencher.dev).
So we need to set your hostname. The easiest way to do this is the with BENCHER_HOST
environment variable.
Open a new terminal window.
On Linux, Mac, and other Unix-like systems run: export BENCHER_HOST=http://localhost:61016
On Windows run: $env:BENCHER_HOST = "http://localhost:61016"
If you then run echo $BENCHER_HOST
or Write-Output $env:BENCHER_HOST
respectively.
You should see:
Create a Bencher Self-Hosted Account
Signup for Bencher Self-Hosted
Create an account on your local Bencher Self-Hosted instance by navigating to: http://localhost:3000/auth/signup
Once you have created an account, navigate back to the terminal window where you ran bencher up
.
You should see something like:
Navigate to the Confirm Email
link in your browser or copy the Confirmation Token
into the Confirm Token
field at: http://localhost:3000/auth/confirm
After that, you should be logged into your Bencher Self-Hosted account!
Create an API Token
In order to use the Bencher API, you will need to create an API token.
Navigate to the Bencher Console.
Hover over your name in top right corner.
A dropdown menu should appear. Select Tokens
.
Once on the API Tokens page, click the ➕ Add
button.
Add an API Token
Once you have created your new API token, you will need to copy it to your clipboard. In the terminal you plan to work in, export the API token as an environment variable.
On Linux, Mac, and other Unix-like systems run: export BENCHER_API_TOKEN=YOUR_TOKEN
On Windows run: $env:BENCHER_API_TOKEN = "YOUR_TOKEN"
If you then run echo $BENCHER_API_TOKEN
or Write-Output $env:BENCHER_API_TOKEN
respectively.
You should see:
🐰 Note: If you move to a different terminal, you will need to export the API token again.
Create a Project
Now that we have a user account and API token, we can create a Project. First, we need to know which Organization our new Project will belong to.
Run: bencher org list
You should see something like:
Your output should be slightly different than the above:
- The
uuid
is pseudorandom - The
name
andslug
will be based on your username - The
created
andmodified
timestamps will be from when you just signed up
We can now create a new Project inside of your Organization.
Substitute your Organization slug
for the organization
argument (ie YOUR_ORG_SLUG
) in the command below.
Run: bencher project create YOUR_ORG_SLUG --name "Save Walter White" --url http://www.savewalterwhite.com
You should see something like:
Again, your output should be slightly different than the above.
It’s just important that this command works.
Take note of the Project slug
field (ie save-walter-white-1234abcd
).
Run a Report
We are finally ready to collect some benchmark metrics! For simplicity’s sake, we will be using mock data in this tutorial.
Run: bencher mock
You should see something like:
Your output should be slightly different than the above, as the data are pseudorandom. It’s just important that this command works.
Now lets run a report using mock benchmark metric data.
Substitute your Project slug
for the --project
argument (ie YOUR_PROJECT_SLUG
) in the command below.
Run: bencher run --project YOUR_PROJECT_SLUG "bencher mock"
You should see something like:
You can now view the results from each of the benchmarks in the browser.
Click or copy and paste the links from View results
.
There should only be a single data point for each benchmark, so lets add some more data!
First, lets set our Project slug as an environment variable, so we don’t have to provide it with the --project
on every single run.
Run: export BENCHER_PROJECT=save-walter-white-1234abcd
If you then run: echo $BENCHER_PROJECT
You should see:
Lets rerun the same command again without --project
to generate more data.
Run: bencher run "bencher mock"
Now, lets generate more data, but this time we will pipe our results into bencher run
.
Run: bencher mock | bencher run
Sometimes you may want to save your results to a file and have bencher run
pick them up.
Run: bencher run --file results.json "bencher mock > results.json"
Likewise, you may have a separate process run your benchmarks and save your results to a file. Then bencher run
will just pick them up.
Run: bencher mock > results.json && bencher run --file results.json
Finally, lets seed a lot of data using the bencher run
--iter
argument.
Run: bencher run --iter 16 "bencher mock"
🐰 Tip: Checkout the
bencher run
CLI Subcommand docs for a full overview of all thatbencher run
can do!
Generate an Alert
Now that we have some historical data for our benchmarks, lets generate an Alert! Alerts are generated when a benchmark result is determined to be a performance regression. So lets simulate a performance regression!
Run: bencher run "bencher mock --pow 8"
There should be a new section at the end of the output called View alerts
:
You can now view the Alerts for each benchmark in the browser.
Click or copy and paste the links from View alerts
.
🐰 Tip: Checkout the Threshold & Alerts docs for a full overview of how performance regressions are detected!
🐰 Congrats! You caught your first perform regression with Bencher Self-Hosted! 🎉