Skip to content

[TILES-V2-10]: add load testing scripts for tiles database #1011

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: tiles-v2/frontend-temp
Choose a base branch
from

Conversation

pregnantboy
Copy link
Contributor

@pregnantboy pregnantboy commented May 23, 2025

TL;DR

Added load testing scripts for Postgres database operations with k6 extensions.

What changed?

  • Added a .env-example file with Postgres connection string
  • Updated the README with instructions for building k6 with extensions (postgres, dotenv, dashboard)
  • Updated the k6 binary to support these extensions
  • Added several new load testing scripts for Postgres operations:
    • seed_table.js - Creates test tables
    • bulk_write.js - Tests bulk insert operations
    • bulk_read.js - Tests bulk read operations
    • read_action.js - Tests single read operations
    • write_action.js - Tests single write operations
    • update_action.js - Tests update operations
    • test.js - Simple connection test

How to test?

  1. Copy .env-example to .env and update with your Postgres connection details
  2. Build k6 with extensions using the Docker command in the README:
    docker run --rm -it -e GOOS=darwin -u "$(id -u):$(id -g)" -v "${PWD}:/xk6" \
      grafana/xk6 build \
      --with github.com/grafana/xk6-sql@latest \
      --with github.com/grafana/xk6-sql-driver-postgres@latest \
      --with github.com/grafana/xk6-dashboard@latest\
      --with github.com/szkiba/xk6-dotenv@latest
    
  3. Run the test scripts, for example:
    ./k6 run tiles/test.js --out dashboard
    

@datadog-opengovsg
Copy link

datadog-opengovsg bot commented May 23, 2025

Datadog Report

Branch report: tiles-v2/load-tests
Commit report: a960b53
Test service: plumber

✅ 0 Failed, 773 Passed, 0 Skipped, 2m 46.06s Total Time
⬆️ Test Sessions change in coverage: 1 increased (+0.7%)

@pregnantboy pregnantboy force-pushed the tiles-v2/frontend-temp branch from 99c1ebb to b33d2f0 Compare May 29, 2025 08:22
@pregnantboy pregnantboy force-pushed the tiles-v2/load-tests branch 3 times, most recently from 3dbe636 to fe3bddb Compare May 29, 2025 08:24
@pregnantboy pregnantboy force-pushed the tiles-v2/frontend-temp branch from e122f70 to dde79fa Compare May 29, 2025 09:01
@pregnantboy pregnantboy force-pushed the tiles-v2/load-tests branch from fe3bddb to 671f353 Compare May 29, 2025 09:01
@pregnantboy pregnantboy force-pushed the tiles-v2/frontend-temp branch from dde79fa to 7bdb006 Compare May 29, 2025 09:03
@pregnantboy pregnantboy force-pushed the tiles-v2/load-tests branch from 671f353 to cee0f04 Compare May 29, 2025 09:04
@pregnantboy pregnantboy changed the title wip [TILES-V2-10]: add load testing scripts for tiles database Jun 3, 2025
@pregnantboy pregnantboy marked this pull request as ready for review June 3, 2025 09:42
@pregnantboy pregnantboy requested a review from a team as a code owner June 3, 2025 09:42
@pregnantboy pregnantboy force-pushed the tiles-v2/frontend-temp branch from 7bdb006 to 08bb207 Compare June 3, 2025 10:37
@pregnantboy pregnantboy force-pushed the tiles-v2/load-tests branch from cee0f04 to 86f6844 Compare June 3, 2025 10:37
cursor-com[bot]

This comment was marked as outdated.

cursor-com[bot]

This comment was marked as outdated.

@pregnantboy pregnantboy force-pushed the tiles-v2/frontend-temp branch from 08bb207 to 44bdd6a Compare June 3, 2025 11:02
@pregnantboy pregnantboy force-pushed the tiles-v2/load-tests branch from 86f6844 to 8a0169b Compare June 3, 2025 11:02
cursor-com[bot]

This comment was marked as outdated.

cursor-com[bot]

This comment was marked as outdated.

@pregnantboy pregnantboy force-pushed the tiles-v2/frontend-temp branch from 44bdd6a to 445c1c6 Compare June 5, 2025 07:30
@pregnantboy pregnantboy force-pushed the tiles-v2/load-tests branch from 8a0169b to 6707e1a Compare June 5, 2025 07:31
cursor-com[bot]

This comment was marked as outdated.

@pregnantboy pregnantboy force-pushed the tiles-v2/frontend-temp branch from 445c1c6 to 87878a6 Compare June 6, 2025 07:20
@pregnantboy pregnantboy force-pushed the tiles-v2/load-tests branch from 6707e1a to a960b53 Compare June 6, 2025 07:20
Copy link

@cursor-com cursor-com bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Bug: SQL Syntax Error and Incorrect Result Validation

The script contains two bugs: The SQL query ends with a double semicolon (;;), which is a syntax error. Additionally, it incorrectly uses rowsAffected() to validate the result of a SELECT query. rowsAffected() is intended for DML operations (INSERT, UPDATE, DELETE) and typically returns 0 for SELECT queries, causing the check rowsAffected() === 1 to always fail.

tools/load-tests/tiles/read_action.js#L34-L42

const result = db.exec(`
SELECT * FROM "public"."load_test_table_1" WHERE "column1" = 'row${Math.floor(
Math.random() * 1000,
)}-col1';;
`)
// const result = db.exec(`
// SELECT 1 FROM "public"."load_test_table_${exec.vu.idInInstance}";
// `)
check(result, 'is added', (r) => r.rowsAffected() === 1)

tools/load-tests/tiles/test.js#L13-L14

const result = db.exec(`SELECT 1 as connection_test`)
console.log(result.rowsAffected())

Fix in Cursor


Bug: Table Name Mismatch Causes Load Test Failures

The load test scripts (bulk_write.js, write_action.js, bulk_read.js) use exec.vu.idInInstance for table names, which conflicts with the seed script's use of exec.vu.iterationInInstance. This mismatch causes read, insert, and bulk insert operations to fail due to non-existent tables. The bulk_read.js script also lacks the maxVUs scenario option and has a misleading console.log message about the number of rows read.

tools/load-tests/tiles/bulk_read.js#L9-L38

scenarios: {
contacts: {
executor: 'constant-arrival-rate',
duration: '5m',
rate: 100,
// It should start `rate` iterations per second
timeUnit: '10s',
// It should preallocate 2 VUs before starting the test
preAllocatedVUs: 100,
// It is allowed to spin up to 50 maximum VUs to sustain the defined
// constant arrival rate.
},
},
}
export default function () {
const db = sql.open(driver, __ENV.POSTGRES_TILES_URL)
const i = Math.floor(Math.random() * 30)
db.exec(`
SELECT * FROM "public"."load_test_table_${
exec.vu.idInInstance
}" ORDER BY "rowId" LIMIT 10000 OFFSET ${i * 10000};
`)
console.log(
`read ${i * 10000} rows in load_test_table_${exec.vu.idInInstance}`,

tools/load-tests/tiles/write_action.js#L39-L42

const result = db.exec(`
INSERT INTO "public"."load_test_table_${
exec.vu.idInInstance
}" ("rowId", "column0", "column1", "column2", "column3", "column4", "column5", "column6", "column7", "column8", "column9") VALUES ${generatedRows

tools/load-tests/tiles/bulk_write.js#L39-L42

const result = db.exec(`
INSERT INTO "public"."load_test_table_${
exec.vu.idInInstance
}" ("rowId", "column0", "column1", "column2", "column3", "column4", "column5", "column6", "column7", "column8", "column9") VALUES ${generatedRows

Fix in Cursor


Bug: Update Fails Due to Missing ID and Table Name Mismatch

The UPDATE query fails because the hardcoded rowId 'to update' does not exist (other scripts use generated UUIDs), resulting in 0 rows updated. A potential table name mismatch (idInInstance vs iterationInInstance) could also cause the table not to be found. Both issues lead to the check on line 37 failing.

tools/load-tests/tiles/update_action.js#L33-L34

const result = db.exec(`
UPDATE "public"."load_test_table_${exec.vu.idInInstance}" SET "column2" = 'updated' WHERE "rowId" = 'to update';

Fix in Cursor


BugBot free trial expires on June 10, 2025
You have used $0.00 of your $1.00 spend limit so far. Manage your spend limit in the Cursor dashboard.

Was this report helpful? Give feedback by reacting with 👍 or 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant