Skip to content

Commit afc4d4e

Browse files
authored
fix: Fixes to cloud benchmarks (no-changelog) (#10634)
1 parent 5635415 commit afc4d4e

File tree

19 files changed

+272
-45
lines changed

19 files changed

+272
-45
lines changed

packages/@n8n/benchmark/infra/benchmark-env.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ resource "azurerm_dedicated_host_group" "main" {
2525
automatic_placement_enabled = false
2626
zone = 1
2727

28-
tags = local.common_tags
28+
tags = local.common_tags
2929
}
3030

3131
resource "azurerm_dedicated_host" "hosts" {
@@ -35,7 +35,7 @@ resource "azurerm_dedicated_host" "hosts" {
3535
sku_name = var.host_size_family
3636
platform_fault_domain = 0
3737

38-
tags = local.common_tags
38+
tags = local.common_tags
3939
}
4040

4141
# VM

packages/@n8n/benchmark/infra/modules/benchmark-vm/output.tf

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ output "vm_name" {
55
output "ip" {
66
value = azurerm_public_ip.main.ip_address
77
}
8+
9+
output "ssh_username" {
10+
value = azurerm_linux_virtual_machine.main.admin_username
11+
}

packages/@n8n/benchmark/infra/modules/benchmark-vm/vm.tf

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,9 +118,9 @@ resource "azurerm_linux_virtual_machine" "main" {
118118
version = "latest"
119119
}
120120

121-
identity {
122-
type = "SystemAssigned"
123-
}
121+
identity {
122+
type = "SystemAssigned"
123+
}
124124

125125
tags = var.tags
126126
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,16 @@
11
output "vm_name" {
22
value = module.test_vm.vm_name
33
}
4+
5+
output "ip" {
6+
value = module.test_vm.ip
7+
}
8+
9+
output "ssh_username" {
10+
value = module.test_vm.ssh_username
11+
}
12+
13+
output "ssh_private_key" {
14+
value = tls_private_key.ssh_key.private_key_pem
15+
sensitive = true
16+
}

packages/@n8n/benchmark/infra/vars.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,6 @@ locals {
2929
Id = "N8nBenchmark"
3030
Terraform = "true"
3131
Owner = "Catalysts"
32-
CreatedAt = timestamp()
32+
CreatedAt = timestamp()
3333
}
3434
}

packages/@n8n/benchmark/scripts/bootstrap.sh

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,9 @@ else
3434
sudo mkfs.xfs /dev/sdc1
3535
sudo partprobe /dev/sdc1
3636
sudo mount /dev/sdc1 /n8n
37+
sudo chown -R "$CURRENT_USER":"$CURRENT_USER" /n8n
3738
fi
3839

39-
# Allow the current user to write to the data disk
40-
sudo chmod a+rw /n8n
41-
4240
# Include nodejs v20 repository
4341
curl -fsSL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh
4442
sudo -E bash nodesource_setup.sh

packages/@n8n/benchmark/scripts/clients/sshClient.mjs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import { $ } from 'zx';
44
export class SshClient {
55
/**
66
*
7-
* @param {{ vmName: string; resourceGroupName: string; verbose?: boolean }} param0
7+
* @param {{ privateKeyPath: string; ip: string; username: string; verbose?: boolean }} param0
88
*/
9-
constructor({ vmName, resourceGroupName, verbose = false }) {
10-
this.vmName = vmName;
11-
this.resourceGroupName = resourceGroupName;
9+
constructor({ privateKeyPath, ip, username, verbose = false }) {
1210
this.verbose = verbose;
11+
this.privateKeyPath = privateKeyPath;
12+
this.ip = ip;
13+
this.username = username;
1314

1415
this.$$ = $({
1516
verbose,
@@ -23,6 +24,14 @@ export class SshClient {
2324
async ssh(command, options = {}) {
2425
const $$ = options?.verbose ? $({ verbose: true }) : this.$$;
2526

26-
await $$`az ssh vm -n ${this.vmName} -g ${this.resourceGroupName} --yes -- -o StrictHostKeyChecking=accept-new ${command}`;
27+
const target = `${this.username}@${this.ip}`;
28+
29+
await $$`ssh -i ${this.privateKeyPath} -o StrictHostKeyChecking=accept-new ${target} ${command}`;
30+
}
31+
32+
async scp(source, destination) {
33+
const target = `${this.username}@${this.ip}:${destination}`;
34+
await this
35+
.$$`scp -i ${this.privateKeyPath} -o StrictHostKeyChecking=accept-new ${source} ${target}`;
2736
}
2837
}

packages/@n8n/benchmark/scripts/clients/terraformClient.mjs

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,16 +20,24 @@ export class TerraformClient {
2020
/**
2121
* @typedef {Object} BenchmarkEnv
2222
* @property {string} vmName
23+
* @property {string} ip
24+
* @property {string} sshUsername
25+
* @property {string} sshPrivateKeyPath
2326
*
2427
* @returns {Promise<BenchmarkEnv>}
2528
*/
2629
async provisionEnvironment() {
2730
console.log('Provisioning cloud environment...');
2831

2932
await this.$$`terraform init`;
30-
await this.$$`terraform apply -input=false -auto-approve`;
33+
// await this.$$`terraform apply -input=false -auto-approve`;
34+
35+
const privateKeyName = await this.extractPrivateKey();
3136

3237
return {
38+
ip: await this.getTerraformOutput('ip'),
39+
sshUsername: await this.getTerraformOutput('ssh_username'),
40+
sshPrivateKeyPath: path.join(paths.infraCodeDir, privateKeyName),
3341
vmName: await this.getTerraformOutput('vm_name'),
3442
};
3543
}
@@ -42,11 +50,18 @@ export class TerraformClient {
4250

4351
console.log('Destroying cloud environment...');
4452

45-
await this.$$`terraform destroy -input=false -auto-approve`;
53+
// await this.$$`terraform destroy -input=false -auto-approve`;
4654
}
4755

4856
async getTerraformOutput(key) {
4957
const output = await this.$$`terraform output -raw ${key}`;
5058
return output.stdout.trim();
5159
}
60+
61+
async extractPrivateKey() {
62+
await this.$$`terraform output -raw ssh_private_key > privatekey.pem`;
63+
await this.$$`chmod 600 privatekey.pem`;
64+
65+
return 'privatekey.pem';
66+
}
5267
}

packages/@n8n/benchmark/scripts/n8nSetups/postgres/docker-compose.yml

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,23 @@ services:
22
postgres:
33
image: postgres:16
44
restart: always
5+
user: ${RUN_USER_AND_GROUP}
56
environment:
67
- POSTGRES_DB=n8n
78
- POSTGRES_USER=postgres
89
- POSTGRES_PASSWORD=password
10+
- PGDATA=/var/lib/postgresql/data/pgdata
11+
volumes:
12+
- ${RUN_DIR}/postgres:/var/lib/postgresql/data
13+
healthcheck:
14+
test: ['CMD-SHELL', 'pg_isready -U postgres']
15+
interval: 5s
16+
timeout: 5s
17+
retries: 5
18+
919
n8n:
1020
image: ghcr.io/n8n-io/n8n:${N8N_VERSION:-latest}
21+
user: ${RUN_USER_AND_GROUP}
1122
environment:
1223
- N8N_DIAGNOSTICS_ENABLED=false
1324
- N8N_USER_FOLDER=/n8n
@@ -17,13 +28,21 @@ services:
1728
ports:
1829
- 5678:5678
1930
volumes:
20-
- ${RUN_DIR}:/n8n
31+
- ${RUN_DIR}/n8n:/n8n
2132
depends_on:
22-
- postgres
33+
postgres:
34+
condition: service_healthy
35+
healthcheck:
36+
test: ['CMD-SHELL', 'wget --spider -q http://localhost:5678/healthz || exit 1']
37+
interval: 5s
38+
timeout: 5s
39+
retries: 10
40+
2341
benchmark:
2442
image: ghcr.io/n8n-io/n8n-benchmark:${N8N_BENCHMARK_VERSION:-latest}
2543
depends_on:
26-
- n8n
44+
n8n:
45+
condition: service_healthy
2746
environment:
2847
- N8N_BASE_URL=http://n8n:5678
2948
- K6_API_TOKEN=${K6_API_TOKEN}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env zx
2+
3+
import path from 'path';
4+
import { fs } from 'zx';
5+
6+
/**
7+
* Creates the needed directories for the queue setup so their
8+
* permissions get set correctly.
9+
*/
10+
export function setup({ runDir }) {
11+
const neededDirs = ['n8n', 'postgres'];
12+
13+
for (const dir of neededDirs) {
14+
fs.ensureDirSync(path.join(runDir, dir));
15+
}
16+
}

packages/@n8n/benchmark/scripts/n8nSetups/queue/docker-compose.yml

Lines changed: 68 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3,71 +3,127 @@ services:
33
image: redis:6-alpine
44
ports:
55
- 6379:6379
6+
healthcheck:
7+
test: ['CMD', 'redis-cli', 'ping']
8+
interval: 1s
9+
timeout: 3s
10+
611
postgres:
712
image: postgres:16
13+
user: ${RUN_USER_AND_GROUP}
814
restart: always
915
environment:
1016
- POSTGRES_DB=n8n
1117
- POSTGRES_USER=postgres
1218
- POSTGRES_PASSWORD=password
19+
- PGDATA=/var/lib/postgresql/data/pgdata
20+
volumes:
21+
- ${RUN_DIR}/postgres:/var/lib/postgresql/data
22+
healthcheck:
23+
test: ['CMD-SHELL', 'pg_isready -U postgres']
24+
interval: 5s
25+
timeout: 5s
26+
retries: 10
27+
1328
n8n_worker1:
1429
image: ghcr.io/n8n-io/n8n:${N8N_VERSION:-latest}
30+
user: ${RUN_USER_AND_GROUP}
1531
environment:
1632
- N8N_DIAGNOSTICS_ENABLED=false
1733
- N8N_USER_FOLDER=/n8n/worker1
1834
- N8N_ENCRYPTION_KEY=very-secret-encryption-key
35+
# Queue mode config
1936
- EXECUTIONS_MODE=queue
2037
- QUEUE_BULL_REDIS_HOST=redis
38+
- QUEUE_HEALTH_CHECK_ACTIVE=true
39+
# DB config
2140
- DB_TYPE=postgresdb
2241
- DB_POSTGRESDB_HOST=postgres
2342
- DB_POSTGRESDB_PASSWORD=password
2443
command: worker
2544
volumes:
26-
- ${RUN_DIR}:/n8n
45+
- ${RUN_DIR}/n8n-worker1:/n8n
2746
depends_on:
28-
- postgres
29-
- redis
47+
postgres:
48+
condition: service_healthy
49+
redis:
50+
condition: service_healthy
51+
healthcheck:
52+
test: ['CMD-SHELL', 'wget --spider -q http://localhost:5678/healthz || exit 1']
53+
interval: 5s
54+
timeout: 5s
55+
retries: 10
56+
3057
n8n_worker2:
3158
image: ghcr.io/n8n-io/n8n:${N8N_VERSION:-latest}
59+
user: ${RUN_USER_AND_GROUP}
3260
environment:
3361
- N8N_DIAGNOSTICS_ENABLED=false
3462
- N8N_USER_FOLDER=/n8n/worker2
3563
- N8N_ENCRYPTION_KEY=very-secret-encryption-key
64+
# Queue mode config
3665
- EXECUTIONS_MODE=queue
3766
- QUEUE_BULL_REDIS_HOST=redis
67+
- QUEUE_HEALTH_CHECK_ACTIVE=true
68+
# DB config
3869
- DB_TYPE=postgresdb
3970
- DB_POSTGRESDB_HOST=postgres
4071
- DB_POSTGRESDB_PASSWORD=password
4172
command: worker
4273
volumes:
43-
- ${RUN_DIR}:/n8n
74+
- ${RUN_DIR}/n8n-worker2:/n8n
4475
depends_on:
45-
- postgres
46-
- redis
76+
# We let the worker 1 start first so it can run the DB migrations
77+
n8n_worker1:
78+
condition: service_healthy
79+
postgres:
80+
condition: service_healthy
81+
redis:
82+
condition: service_healthy
83+
healthcheck:
84+
test: ['CMD-SHELL', 'wget --spider -q http://localhost:5678/healthz || exit 1']
85+
interval: 5s
86+
timeout: 5s
87+
retries: 10
88+
4789
n8n:
4890
image: ghcr.io/n8n-io/n8n:${N8N_VERSION:-latest}
91+
user: ${RUN_USER_AND_GROUP}
4992
environment:
5093
- N8N_DIAGNOSTICS_ENABLED=false
5194
- N8N_USER_FOLDER=/n8n/main
5295
- N8N_ENCRYPTION_KEY=very-secret-encryption-key
96+
# Queue mode config
5397
- EXECUTIONS_MODE=queue
5498
- QUEUE_BULL_REDIS_HOST=redis
99+
# DB config
55100
- DB_TYPE=postgresdb
56101
- DB_POSTGRESDB_HOST=postgres
57102
- DB_POSTGRESDB_PASSWORD=password
58103
ports:
59104
- 5678:5678
60105
volumes:
61-
- ${RUN_DIR}:/n8n
106+
- ${RUN_DIR}/n8n-main:/n8n
62107
depends_on:
63-
- postgres
64-
- redis
65-
- n8n_worker1
66-
- n8n_worker2
108+
n8n_worker1:
109+
condition: service_healthy
110+
n8n_worker2:
111+
condition: service_healthy
112+
postgres:
113+
condition: service_healthy
114+
redis:
115+
condition: service_healthy
116+
healthcheck:
117+
test: ['CMD-SHELL', 'wget --spider -q http://localhost:5678/healthz || exit 1']
118+
interval: 5s
119+
timeout: 5s
120+
retries: 10
121+
67122
benchmark:
68123
image: ghcr.io/n8n-io/n8n-benchmark:${N8N_BENCHMARK_VERSION:-latest}
69124
depends_on:
70-
- n8n
125+
n8n:
126+
condition: service_healthy
71127
environment:
72128
- N8N_BASE_URL=http://n8n:5678
73129
- K6_API_TOKEN=${K6_API_TOKEN}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
#!/usr/bin/env zx
2+
3+
import path from 'path';
4+
import { fs } from 'zx';
5+
6+
/**
7+
* Creates the needed directories for the queue setup so their
8+
* permissions get set correctly.
9+
*/
10+
export function setup({ runDir }) {
11+
const neededDirs = ['n8n-worker1', 'n8n-worker2', 'n8n-main', 'postgres'];
12+
13+
for (const dir of neededDirs) {
14+
fs.ensureDirSync(path.join(runDir, dir));
15+
}
16+
}

0 commit comments

Comments
 (0)