feat(benchmark): Add filter flag (#11355)

This commit is contained in:
Tomi Turtiainen 2024-10-23 15:09:30 +03:00 committed by GitHub
parent f414e90993
commit 0e7eccd238
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 43 additions and 3 deletions

View file

@ -1,6 +1,6 @@
# n8n benchmarking tool
Tool for executing benchmarks against an n8n instance. The tool consists of these components:
Tool for executing benchmarks against an n8n instance.
## Directory structure
@ -12,6 +12,39 @@ packages/@n8n/benchmark
├── scripts Orchestration scripts
```
## Benchmarking an existing n8n instance
The easiest way to run the existing benchmark scenarios is to use the benchmark docker image:
```sh
docker pull ghcr.io/n8n-io/n8n-benchmark:latest
# Print the help to list all available flags
docker run ghcr.io/n8n-io/n8n-benchmark:latest run --help
# Run all available benchmark scenarios for 1 minute with 5 concurrent requests
docker run ghcr.io/n8n-io/n8n-benchmark:latest run \
--n8nBaseUrl=https://instance.url \
--n8nUserEmail=InstanceOwner@email.com \
--n8nUserPassword=InstanceOwnerPassword \
--vus=5 \
--duration=1m \
--scenarioFilter SingleWebhook
```
### Using custom scenarios with the Docker image
It is also possible to create your own [benchmark scenarios](#benchmark-scenarios) and load them using the `--testScenariosPath` flag:
```sh
# Assuming your scenarios are located in `./scenarios`, mount them into `/scenarios` in the container
docker run -v ./scenarios:/scenarios ghcr.io/n8n-io/n8n-benchmark:latest run \
--n8nBaseUrl=https://instance.url \
--n8nUserEmail=InstanceOwner@email.com \
--n8nUserPassword=InstanceOwnerPassword \
--vus=5 \
--duration=1m \
--testScenariosPath=/scenarios
```
## Running the entire benchmark suite
The benchmark suite consists of [benchmark scenarios](#benchmark-scenarios) and different [n8n setups](#n8n-setups).

View file

@ -13,6 +13,10 @@ export default class RunCommand extends Command {
static flags = {
testScenariosPath,
scenarioFilter: Flags.string({
char: 'f',
description: 'Filter scenarios by name',
}),
scenarioNamePrefix: Flags.string({
description: 'Prefix for the scenario name',
default: 'Unnamed',
@ -95,7 +99,7 @@ export default class RunCommand extends Command {
flags.scenarioNamePrefix,
);
const allScenarios = scenarioLoader.loadAll(flags.testScenariosPath);
const allScenarios = scenarioLoader.loadAll(flags.testScenariosPath, flags.scenarioFilter);
await scenarioRunner.runManyScenarios(allScenarios);
}

View file

@ -8,7 +8,7 @@ export class ScenarioLoader {
/**
* Loads all scenarios from the given path
*/
loadAll(pathToScenarios: string): Scenario[] {
loadAll(pathToScenarios: string, filter?: string): Scenario[] {
pathToScenarios = path.resolve(pathToScenarios);
const scenarioFolders = fs
.readdirSync(pathToScenarios, { withFileTypes: true })
@ -18,6 +18,9 @@ export class ScenarioLoader {
const scenarios: Scenario[] = [];
for (const folder of scenarioFolders) {
if (filter && !folder.toLowerCase().includes(filter.toLowerCase())) {
continue;
}
const scenarioPath = path.join(pathToScenarios, folder);
const manifestFileName = `${folder}.manifest.json`;
const scenarioManifestPath = path.join(pathToScenarios, folder, manifestFileName);