Back to changelog
New
•4 minute read

Workloads: Test Migrations Under Application Traffic

Migrate tests can now run application traffic against the dev database during a migration. A workload block defines the transactions and their rate, and expect blocks fail the test on errors, latency, stalls, or lock waits.

A migration can pass every check and still hold a lock the application waits on for as long as it runs. Define the traffic once at the top level with a workload block, and run it during the migrate commands under test, from a warmup before the command to a cooldown after it. Bound the traffic with expect "profile" blocks:

migrate.test.hcl
workload "app" {
connections = 2
rate = "100/s"
query "lookup" {
sql = "SELECT status FROM orders WHERE id = $1"
args = [random::int(1, 1000)]
}
}
test "migrate" "locked" {
migrate {
to = "4"
}
migrate {
to = "5"
workload {
use = workload.app
warmup = "500ms"
cooldown = "500ms"
}
expect "profile" {
metric "db.workload.errors" {
eq = 0
}
metric "db.workload.stall" {
le = "200ms"
}
metric "db.workload.latency" {
transaction = "lookup"
quantile = MAX
le = "200ms"
}
metric "db.workload.blocked" {
le = "100ms"
}
metric "db.workload.latency" {
quantile = MAX
le = "3x"
}
}
}
}

With this migration, which locks the table for one second:

5_lock.sql
LOCK TABLE orders IN ACCESS EXCLUSIVE MODE;
SELECT pg_sleep(1);

No read fails, but the reads wait for the lock. The test compares the latency of each transaction before the command with its latency after the command started, and names the lock the runs waited behind with the statement that took it. Every bound but db.workload.errors fails. The output is abridged to the latency and the wait:

atlas migrate test --dev-url "docker://postgres/18/dev" .
-- FAIL: locked (2.05s)
migrate.test.hcl:16: workload "app", 100/s on 2 connections: 52 transactions ended before the command, 153 from its start to the end of the 500ms cooldown (the command ran 1.025s)
transaction runs errors p50 before p50 after p99 before p99 after max after blocked
lookup 153 0 1ms 243ms 2ms 988ms 997ms 995ms
lookup waited 909ms to 995ms on public.orders, behind the AccessExclusiveLock 5_lock.sql:1 held

Waits at Production Size

Where a dataset loads a sample of a table, Atlas projects the waits and the stall of the workload to the full table, as it projects the locks of the migration. This backfill updates a 200,000-row sample of a 20,000,000-row table while the application updates orders:

migrate.test.hcl
dataset "synthetic" "orders" {
table "orders" {
rows = 200000
total = 20000000
column "id" {
value = row.index + 1000
}
column "user_id" {
value = row.index
}
column "status" {
value = "new"
}
}
}
workload "pay" {
connections = 2
rate = "100/s"
exec "pay" {
sql = "UPDATE orders SET status = 'done' WHERE id = $1"
args = [random::int(1, 100)]
}
}
test "migrate" "backfill" {
migrate {
to = "2"
}
dataset {
use = dataset.synthetic.orders
}
migrate {
to = "3"
workload {
use = workload.pay
warmup = "500ms"
cooldown = "500ms"
}
expect "profile" {
metric "db.workload.blocked" {
le = "100ms"
}
metric "db.lock.rows" {
table = "orders"
le = "1s"
}
}
}
}
-- 1_orders.sql
CREATE TABLE orders (id int GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, user_id int NOT NULL, status text NOT NULL);
-- 2_rows.sql
INSERT INTO orders (user_id, status) SELECT g, 'new' FROM generate_series(1, 100) g;
-- 3_backfill.sql
UPDATE orders SET status = 'paid';

At 20,000,000 rows, the rows the backfill updates stay locked until it commits, for 33.9s to ~2m16s, and the runs that update them wait as long. The output is abridged to the errors:

atlas migrate test --dev-url "docker://postgres/18/dev" .
-- FAIL: backfill (2.89s)
migrate.test.hcl:33:
Error: db.workload.blocked: pay (on a row of public.orders, behind the rows 3_backfill.sql:1 locked until its transaction ended): 33.8s to ~2m16s at 20,000,000 rows, expected less than or equal to 100ms (migrate.test.hcl:20)
db.lock.rows: public.orders: 33.9s to ~2m16s at 20,000,000 rows, expected less than or equal to 1s (3_backfill.sql:1)

A projected value is a range, and a bound inside the range fails the test as not verified.

Metrics

MetricMeasures
db.workload.errorsRuns that failed, from the start of the command to the end of the cooldown.
db.workload.latencyLatency of the runs, by transaction and quantile.
db.workload.stallLongest time no run ended without an error.
db.workload.blockedLongest single wait of a run behind the migration.
db.lock.rowsTime the rows a transaction wrote or locked stay locked.

A bound of db.workload.latency or db.workload.stall can be a multiple of the same value before the command, such as le = "3x".

Notes

  • Workloads run on PostgreSQL, MySQL, TiDB, CockroachDB, YugabyteDB, and Aurora DSQL, and not on SQL Server or MariaDB. Blocked time is measured on PostgreSQL, and on MySQL 8.0.28 and later with performance_schema on.
  • db.lock.rows can bound any migrate, exec, catch, or script command, and is measured on PostgreSQL.
  • Profiling is in preview and open to a subset of Teams and Enterprise customers. To get access, reach out through your Atlas support channel or message us on Intercom.

Next Steps

Read the Workloads section of the Profiling guide to define transactions and roles, bound the latency and waits of the traffic, and see what each database measures.

featuretestingprofilingworkloadsmigrate testlocksdatasetsatlas pro