Skip to content

Commit a960b53

Browse files
committed
wip
1 parent 87878a6 commit a960b53

File tree

12 files changed

+313
-5
lines changed

12 files changed

+313
-5
lines changed

tools/load-tests/.env-example

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
POSTGRES_TILES_URL=postgres://postgres:postgres@localhost:5432/tiles

tools/load-tests/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,23 @@
66
then
77
`k6 run formsg.js`
88

9+
### Build k6 with extensions
10+
Since we are using k6 plugins, we need to use xk6 to build k6 with extensions.
11+
12+
We are using the following extensions:
13+
- postgres
14+
- dotenv
15+
- dashboard
16+
17+
```
18+
docker run --rm -it -e GOOS=darwin -u "$(id -u):$(id -g)" -v "${PWD}:/xk6" \
19+
grafana/xk6 build \
20+
--with github.com/grafana/xk6-sql@latest \
21+
--with github.com/grafana/xk6-sql-driver-postgres@latest \
22+
--with github.com/grafana/xk6-dashboard@latest\
23+
--with github.com/szkiba/xk6-dotenv@latest
24+
```
25+
926
### To run with dashboard
1027

1128
`./k6 run --out dashboard=open webhook.js`

tools/load-tests/k6

9.17 MB
Binary file not shown.

tools/load-tests/package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tools/load-tests/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
"author": "",
77
"license": "ISC",
88
"devDependencies": {
9-
"@types/k6": "^0.43.2"
9+
"@types/k6": "^1.0.2"
1010
}
1111
}

tools/load-tests/tiles/bulk_read.js

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
/* eslint-disable no-undef */
2+
import exec from 'k6/execution'
3+
import sql from 'k6/x/sql'
4+
import driver from 'k6/x/sql/driver/postgres'
5+
6+
// Test configuration
7+
export const options = {
8+
discardResponseBodies: true,
9+
scenarios: {
10+
contacts: {
11+
executor: 'constant-arrival-rate',
12+
13+
duration: '5m',
14+
15+
rate: 100,
16+
17+
// It should start `rate` iterations per second
18+
timeUnit: '10s',
19+
20+
// It should preallocate 2 VUs before starting the test
21+
preAllocatedVUs: 100,
22+
23+
// It is allowed to spin up to 50 maximum VUs to sustain the defined
24+
// constant arrival rate.
25+
},
26+
},
27+
}
28+
29+
export default function () {
30+
const db = sql.open(driver, __ENV.POSTGRES_TILES_URL)
31+
const i = Math.floor(Math.random() * 30)
32+
db.exec(`
33+
SELECT * FROM "public"."load_test_table_${
34+
exec.vu.idInInstance
35+
}" ORDER BY "rowId" LIMIT 10000 OFFSET ${i * 10000};
36+
`)
37+
console.log(
38+
`read ${i * 10000} rows in load_test_table_${exec.vu.idInInstance}`,
39+
)
40+
41+
db.close()
42+
}

tools/load-tests/tiles/bulk_write.js

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* eslint-disable no-undef */
2+
import { check } from 'k6'
3+
import exec from 'k6/execution'
4+
import sql from 'k6/x/sql'
5+
import driver from 'k6/x/sql/driver/postgres'
6+
7+
// Test configuration
8+
export const options = {
9+
discardResponseBodies: true,
10+
scenarios: {
11+
contacts: {
12+
executor: 'constant-arrival-rate',
13+
14+
duration: '5m',
15+
16+
rate: 50,
17+
18+
// It should start `rate` iterations per second
19+
timeUnit: '1s',
20+
21+
// It should preallocate 2 VUs before starting the test
22+
preAllocatedVUs: 100,
23+
24+
// It is allowed to spin up to 50 maximum VUs to sustain the defined
25+
// constant arrival rate.
26+
maxVUs: 100,
27+
},
28+
},
29+
}
30+
31+
const generatedRows = Array.from({ length: 1000 }, (_, i) => {
32+
return Array.from({ length: 10 }, (_, j) => {
33+
return `'row${i}-col${j}'`
34+
}).join(',')
35+
})
36+
37+
export default function () {
38+
const db = sql.open(driver, __ENV.POSTGRES_TILES_URL)
39+
const result = db.exec(`
40+
INSERT INTO "public"."load_test_table_${
41+
exec.vu.idInInstance
42+
}" ("rowId", "column0", "column1", "column2", "column3", "column4", "column5", "column6", "column7", "column8", "column9") VALUES ${generatedRows
43+
.map((row) => `('${crypto.randomUUID()}', ${row})`)
44+
.join(',\n')};
45+
`)
46+
// const result = db.exec(`
47+
// SELECT 1 FROM "public"."load_test_table_${exec.vu.idInInstance}";
48+
// `)
49+
check(result, 'is added', (r) => r.rowsAffected() === 1000)
50+
console.log(
51+
`added ${result.rowsAffected()} rows in load_test_table_${
52+
exec.vu.idInInstance
53+
}`,
54+
)
55+
db.close()
56+
}

tools/load-tests/tiles/read_action.js

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
/* eslint-disable no-undef */
2+
import { check } from 'k6'
3+
import exec from 'k6/execution'
4+
import sql from 'k6/x/sql'
5+
import driver from 'k6/x/sql/driver/postgres'
6+
7+
// Test configuration
8+
export const options = {
9+
discardResponseBodies: true,
10+
scenarios: {
11+
contacts: {
12+
executor: 'constant-arrival-rate',
13+
14+
duration: '10m',
15+
16+
rate: 20,
17+
18+
// It should start `rate` iterations per second
19+
timeUnit: '1s',
20+
21+
// It should preallocate 2 VUs before starting the test
22+
preAllocatedVUs: 100,
23+
24+
// It is allowed to spin up to 50 maximum VUs to sustain the defined
25+
// constant arrival rate.
26+
maxVUs: 100,
27+
},
28+
},
29+
}
30+
31+
export default function () {
32+
const db = sql.open(driver, __ENV.POSTGRES_TILES_URL)
33+
34+
const result = db.exec(`
35+
SELECT * FROM "public"."load_test_table_1" WHERE "column1" = 'row${Math.floor(
36+
Math.random() * 1000,
37+
)}-col1';;
38+
`)
39+
// const result = db.exec(`
40+
// SELECT 1 FROM "public"."load_test_table_${exec.vu.idInInstance}";
41+
// `)
42+
check(result, 'is added', (r) => r.rowsAffected() === 1)
43+
console.log(
44+
`selected ${result.rowsAffected()} row from load_test_table_${
45+
exec.vu.idInInstance
46+
}`,
47+
)
48+
db.close()
49+
}

tools/load-tests/tiles/seed_table.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/* eslint-disable no-undef */
2+
import exec from 'k6/execution'
3+
import sql from 'k6/x/sql'
4+
import driver from 'k6/x/sql/driver/postgres'
5+
6+
// Test configuration
7+
export const options = {
8+
iterations: 1000,
9+
vus: 1,
10+
}
11+
12+
export default function () {
13+
const db = sql.open(driver, __ENV.POSTGRES_TILES_URL)
14+
const tableId = exec.vu.iterationInInstance
15+
16+
db.exec(`
17+
CREATE TABLE IF NOT EXISTS "public"."load_test_table_${tableId}" (
18+
"rowId" varchar(255) NOT NULL,
19+
"createdAt" timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP,
20+
"updatedAt" timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP,
21+
${Array.from({ length: 10 }, (_, i) => `"column${i}" text`).join(',\n')},
22+
PRIMARY KEY ("rowId")
23+
);
24+
`)
25+
console.log(`table created: load_test_table_${tableId}`)
26+
db.close()
27+
}

tools/load-tests/tiles/test.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* eslint-disable no-undef */
2+
import sql from 'k6/x/sql'
3+
import driver from 'k6/x/sql/driver/postgres'
4+
5+
// Test configuration
6+
export const options = {
7+
iterations: 1,
8+
vus: 1,
9+
}
10+
11+
export default function () {
12+
const db = sql.open(driver, __ENV.POSTGRES_TILES_URL)
13+
const result = db.exec(`SELECT 1 as connection_test`)
14+
console.log(result.rowsAffected())
15+
db.close()
16+
}
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/* eslint-disable no-undef */
2+
import { check } from 'k6'
3+
import exec from 'k6/execution'
4+
import sql from 'k6/x/sql'
5+
import driver from 'k6/x/sql/driver/postgres'
6+
7+
// Test configuration
8+
export const options = {
9+
discardResponseBodies: true,
10+
scenarios: {
11+
contacts: {
12+
executor: 'constant-arrival-rate',
13+
14+
duration: '10m',
15+
16+
rate: 50,
17+
18+
// It should start `rate` iterations per second
19+
timeUnit: '1s',
20+
21+
// It should preallocate 2 VUs before starting the test
22+
preAllocatedVUs: 100,
23+
24+
// It is allowed to spin up to 50 maximum VUs to sustain the defined
25+
// constant arrival rate.
26+
maxVUs: 100,
27+
},
28+
},
29+
}
30+
31+
export default function () {
32+
const db = sql.open(driver, __ENV.POSTGRES_TILES_URL)
33+
const result = db.exec(`
34+
UPDATE "public"."load_test_table_${exec.vu.idInInstance}" SET "column2" = 'updated' WHERE "rowId" = 'to update';
35+
`)
36+
37+
check(result, 'is added', (r) => r.rowsAffected() === 1)
38+
console.log(
39+
`added ${result.rowsAffected()} rows in load_test_table_${
40+
exec.vu.idInInstance
41+
}`,
42+
)
43+
db.close()
44+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
/* eslint-disable no-undef */
2+
import { check } from 'k6'
3+
import exec from 'k6/execution'
4+
import sql from 'k6/x/sql'
5+
import driver from 'k6/x/sql/driver/postgres'
6+
7+
// Test configuration
8+
export const options = {
9+
discardResponseBodies: true,
10+
scenarios: {
11+
contacts: {
12+
executor: 'constant-arrival-rate',
13+
14+
duration: '10m',
15+
16+
rate: 50,
17+
18+
// It should start `rate` iterations per second
19+
timeUnit: '1s',
20+
21+
// It should preallocate 2 VUs before starting the test
22+
preAllocatedVUs: 100,
23+
24+
// It is allowed to spin up to 50 maximum VUs to sustain the defined
25+
// constant arrival rate.
26+
maxVUs: 100,
27+
},
28+
},
29+
}
30+
31+
const generatedRows = Array.from({ length: 1 }, (_, i) => {
32+
return Array.from({ length: 10 }, (_, j) => {
33+
return `'row${i}-col${j}'`
34+
}).join(',')
35+
})
36+
37+
export default function () {
38+
const db = sql.open(driver, __ENV.POSTGRES_TILES_URL)
39+
const result = db.exec(`
40+
INSERT INTO "public"."load_test_table_${
41+
exec.vu.idInInstance
42+
}" ("rowId", "column0", "column1", "column2", "column3", "column4", "column5", "column6", "column7", "column8", "column9") VALUES ${generatedRows
43+
.map((row) => `('${crypto.randomUUID()}', ${row})`)
44+
.join(',\n')};
45+
`)
46+
// const result = db.exec(`
47+
// SELECT 1 FROM "public"."load_test_table_${exec.vu.idInInstance}";
48+
// `)
49+
check(result, 'is added', (r) => r.rowsAffected() === 1)
50+
console.log(
51+
`added ${result.rowsAffected()} rows in load_test_table_${
52+
exec.vu.idInInstance
53+
}`,
54+
)
55+
db.close()
56+
}

0 commit comments

Comments
 (0)