Skip to content

Commit

Permalink
fix: Fixes to cloud benchmarks (no-changelog) (#10634)
Browse files Browse the repository at this point in the history
  • Loading branch information
tomi authored Sep 2, 2024
1 parent 5635415 commit afc4d4e
Show file tree
Hide file tree
Showing 19 changed files with 272 additions and 45 deletions.
4 changes: 2 additions & 2 deletions packages/@n8n/benchmark/infra/benchmark-env.tf
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ resource "azurerm_dedicated_host_group" "main" {
automatic_placement_enabled = false
zone = 1

tags = local.common_tags
tags = local.common_tags
}

resource "azurerm_dedicated_host" "hosts" {
Expand All @@ -35,7 +35,7 @@ resource "azurerm_dedicated_host" "hosts" {
sku_name = var.host_size_family
platform_fault_domain = 0

tags = local.common_tags
tags = local.common_tags
}

# VM
Expand Down
4 changes: 4 additions & 0 deletions packages/@n8n/benchmark/infra/modules/benchmark-vm/output.tf
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,7 @@ output "vm_name" {
output "ip" {
value = azurerm_public_ip.main.ip_address
}

output "ssh_username" {
value = azurerm_linux_virtual_machine.main.admin_username
}
6 changes: 3 additions & 3 deletions packages/@n8n/benchmark/infra/modules/benchmark-vm/vm.tf
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,9 @@ resource "azurerm_linux_virtual_machine" "main" {
version = "latest"
}

identity {
type = "SystemAssigned"
}
identity {
type = "SystemAssigned"
}

tags = var.tags
}
Expand Down
13 changes: 13 additions & 0 deletions packages/@n8n/benchmark/infra/output.tf
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
output "vm_name" {
value = module.test_vm.vm_name
}

output "ip" {
value = module.test_vm.ip
}

output "ssh_username" {
value = module.test_vm.ssh_username
}

output "ssh_private_key" {
value = tls_private_key.ssh_key.private_key_pem
sensitive = true
}
2 changes: 1 addition & 1 deletion packages/@n8n/benchmark/infra/vars.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,6 @@ locals {
Id = "N8nBenchmark"
Terraform = "true"
Owner = "Catalysts"
CreatedAt = timestamp()
CreatedAt = timestamp()
}
}
4 changes: 1 addition & 3 deletions packages/@n8n/benchmark/scripts/bootstrap.sh
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,9 @@ else
sudo mkfs.xfs /dev/sdc1
sudo partprobe /dev/sdc1
sudo mount /dev/sdc1 /n8n
sudo chown -R "$CURRENT_USER":"$CURRENT_USER" /n8n
fi

# Allow the current user to write to the data disk
sudo chmod a+rw /n8n

# Include nodejs v20 repository
curl -fsSL https://deb.nodesource.com/setup_20.x -o nodesource_setup.sh
sudo -E bash nodesource_setup.sh
Expand Down
19 changes: 14 additions & 5 deletions packages/@n8n/benchmark/scripts/clients/sshClient.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import { $ } from 'zx';
export class SshClient {
/**
*
* @param {{ vmName: string; resourceGroupName: string; verbose?: boolean }} param0
* @param {{ privateKeyPath: string; ip: string; username: string; verbose?: boolean }} param0
*/
constructor({ vmName, resourceGroupName, verbose = false }) {
this.vmName = vmName;
this.resourceGroupName = resourceGroupName;
constructor({ privateKeyPath, ip, username, verbose = false }) {
this.verbose = verbose;
this.privateKeyPath = privateKeyPath;
this.ip = ip;
this.username = username;

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

await $$`az ssh vm -n ${this.vmName} -g ${this.resourceGroupName} --yes -- -o StrictHostKeyChecking=accept-new ${command}`;
const target = `${this.username}@${this.ip}`;

await $$`ssh -i ${this.privateKeyPath} -o StrictHostKeyChecking=accept-new ${target} ${command}`;
}

async scp(source, destination) {
const target = `${this.username}@${this.ip}:${destination}`;
await this
.$$`scp -i ${this.privateKeyPath} -o StrictHostKeyChecking=accept-new ${source} ${target}`;
}
}
19 changes: 17 additions & 2 deletions packages/@n8n/benchmark/scripts/clients/terraformClient.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -20,16 +20,24 @@ export class TerraformClient {
/**
* @typedef {Object} BenchmarkEnv
* @property {string} vmName
* @property {string} ip
* @property {string} sshUsername
* @property {string} sshPrivateKeyPath
*
* @returns {Promise<BenchmarkEnv>}
*/
async provisionEnvironment() {
console.log('Provisioning cloud environment...');

await this.$$`terraform init`;
await this.$$`terraform apply -input=false -auto-approve`;
// await this.$$`terraform apply -input=false -auto-approve`;

const privateKeyName = await this.extractPrivateKey();

return {
ip: await this.getTerraformOutput('ip'),
sshUsername: await this.getTerraformOutput('ssh_username'),
sshPrivateKeyPath: path.join(paths.infraCodeDir, privateKeyName),
vmName: await this.getTerraformOutput('vm_name'),
};
}
Expand All @@ -42,11 +50,18 @@ export class TerraformClient {

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

await this.$$`terraform destroy -input=false -auto-approve`;
// await this.$$`terraform destroy -input=false -auto-approve`;
}

async getTerraformOutput(key) {
const output = await this.$$`terraform output -raw ${key}`;
return output.stdout.trim();
}

async extractPrivateKey() {
await this.$$`terraform output -raw ssh_private_key > privatekey.pem`;
await this.$$`chmod 600 privatekey.pem`;

return 'privatekey.pem';
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,23 @@ services:
postgres:
image: postgres:16
restart: always
user: ${RUN_USER_AND_GROUP}
environment:
- POSTGRES_DB=n8n
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- ${RUN_DIR}/postgres:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U postgres']
interval: 5s
timeout: 5s
retries: 5

n8n:
image: ghcr.io/n8n-io/n8n:${N8N_VERSION:-latest}
user: ${RUN_USER_AND_GROUP}
environment:
- N8N_DIAGNOSTICS_ENABLED=false
- N8N_USER_FOLDER=/n8n
Expand All @@ -17,13 +28,21 @@ services:
ports:
- 5678:5678
volumes:
- ${RUN_DIR}:/n8n
- ${RUN_DIR}/n8n:/n8n
depends_on:
- postgres
postgres:
condition: service_healthy
healthcheck:
test: ['CMD-SHELL', 'wget --spider -q http://localhost:5678/healthz || exit 1']
interval: 5s
timeout: 5s
retries: 10

benchmark:
image: ghcr.io/n8n-io/n8n-benchmark:${N8N_BENCHMARK_VERSION:-latest}
depends_on:
- n8n
n8n:
condition: service_healthy
environment:
- N8N_BASE_URL=http://n8n:5678
- K6_API_TOKEN=${K6_API_TOKEN}
16 changes: 16 additions & 0 deletions packages/@n8n/benchmark/scripts/n8nSetups/postgres/setup.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env zx

import path from 'path';
import { fs } from 'zx';

/**
* Creates the needed directories for the queue setup so their
* permissions get set correctly.
*/
export function setup({ runDir }) {
const neededDirs = ['n8n', 'postgres'];

for (const dir of neededDirs) {
fs.ensureDirSync(path.join(runDir, dir));
}
}
80 changes: 68 additions & 12 deletions packages/@n8n/benchmark/scripts/n8nSetups/queue/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,71 +3,127 @@ services:
image: redis:6-alpine
ports:
- 6379:6379
healthcheck:
test: ['CMD', 'redis-cli', 'ping']
interval: 1s
timeout: 3s

postgres:
image: postgres:16
user: ${RUN_USER_AND_GROUP}
restart: always
environment:
- POSTGRES_DB=n8n
- POSTGRES_USER=postgres
- POSTGRES_PASSWORD=password
- PGDATA=/var/lib/postgresql/data/pgdata
volumes:
- ${RUN_DIR}/postgres:/var/lib/postgresql/data
healthcheck:
test: ['CMD-SHELL', 'pg_isready -U postgres']
interval: 5s
timeout: 5s
retries: 10

n8n_worker1:
image: ghcr.io/n8n-io/n8n:${N8N_VERSION:-latest}
user: ${RUN_USER_AND_GROUP}
environment:
- N8N_DIAGNOSTICS_ENABLED=false
- N8N_USER_FOLDER=/n8n/worker1
- N8N_ENCRYPTION_KEY=very-secret-encryption-key
# Queue mode config
- EXECUTIONS_MODE=queue
- QUEUE_BULL_REDIS_HOST=redis
- QUEUE_HEALTH_CHECK_ACTIVE=true
# DB config
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PASSWORD=password
command: worker
volumes:
- ${RUN_DIR}:/n8n
- ${RUN_DIR}/n8n-worker1:/n8n
depends_on:
- postgres
- redis
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ['CMD-SHELL', 'wget --spider -q http://localhost:5678/healthz || exit 1']
interval: 5s
timeout: 5s
retries: 10

n8n_worker2:
image: ghcr.io/n8n-io/n8n:${N8N_VERSION:-latest}
user: ${RUN_USER_AND_GROUP}
environment:
- N8N_DIAGNOSTICS_ENABLED=false
- N8N_USER_FOLDER=/n8n/worker2
- N8N_ENCRYPTION_KEY=very-secret-encryption-key
# Queue mode config
- EXECUTIONS_MODE=queue
- QUEUE_BULL_REDIS_HOST=redis
- QUEUE_HEALTH_CHECK_ACTIVE=true
# DB config
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PASSWORD=password
command: worker
volumes:
- ${RUN_DIR}:/n8n
- ${RUN_DIR}/n8n-worker2:/n8n
depends_on:
- postgres
- redis
# We let the worker 1 start first so it can run the DB migrations
n8n_worker1:
condition: service_healthy
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ['CMD-SHELL', 'wget --spider -q http://localhost:5678/healthz || exit 1']
interval: 5s
timeout: 5s
retries: 10

n8n:
image: ghcr.io/n8n-io/n8n:${N8N_VERSION:-latest}
user: ${RUN_USER_AND_GROUP}
environment:
- N8N_DIAGNOSTICS_ENABLED=false
- N8N_USER_FOLDER=/n8n/main
- N8N_ENCRYPTION_KEY=very-secret-encryption-key
# Queue mode config
- EXECUTIONS_MODE=queue
- QUEUE_BULL_REDIS_HOST=redis
# DB config
- DB_TYPE=postgresdb
- DB_POSTGRESDB_HOST=postgres
- DB_POSTGRESDB_PASSWORD=password
ports:
- 5678:5678
volumes:
- ${RUN_DIR}:/n8n
- ${RUN_DIR}/n8n-main:/n8n
depends_on:
- postgres
- redis
- n8n_worker1
- n8n_worker2
n8n_worker1:
condition: service_healthy
n8n_worker2:
condition: service_healthy
postgres:
condition: service_healthy
redis:
condition: service_healthy
healthcheck:
test: ['CMD-SHELL', 'wget --spider -q http://localhost:5678/healthz || exit 1']
interval: 5s
timeout: 5s
retries: 10

benchmark:
image: ghcr.io/n8n-io/n8n-benchmark:${N8N_BENCHMARK_VERSION:-latest}
depends_on:
- n8n
n8n:
condition: service_healthy
environment:
- N8N_BASE_URL=http://n8n:5678
- K6_API_TOKEN=${K6_API_TOKEN}
16 changes: 16 additions & 0 deletions packages/@n8n/benchmark/scripts/n8nSetups/queue/setup.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
#!/usr/bin/env zx

import path from 'path';
import { fs } from 'zx';

/**
* Creates the needed directories for the queue setup so their
* permissions get set correctly.
*/
export function setup({ runDir }) {
const neededDirs = ['n8n-worker1', 'n8n-worker2', 'n8n-main', 'postgres'];

for (const dir of neededDirs) {
fs.ensureDirSync(path.join(runDir, dir));
}
}
Loading

0 comments on commit afc4d4e

Please sign in to comment.