Check for runtime errors
As a test, we want to try to execute only 1 function at the time, once. We want to make sure we don't run into any runtime errors.
Runtime errors can occur for various reasons, here are a few:
- your bind parameter type isn't compatible with the column datatype you try to insert into.
For example, you pass an
int
but the column is of typeVARCHAR
. - The table you try to access does not exists.
Test the Read transaction
# we set read_pct to 100 to force just the read_txn
# -i stands for iterations
# PostgreSQL
dbworkload run -w bank.py --uri 'postgres://fabio:postgres@localhost:5432/bank?sslmode=disable' \
-i 1 --args '{"read_pct": 100}'
# CockroachDB - notice we set the uri to point at the `bank` database ⬇️⬇️
dbworkload run -w bank.py --uri 'postgres://cockroach:cockroach@localhost:26257/bank?sslmode=require' \
-i 1 --args '{"read_pct": 100}'
The output is the same for any driver you choose, and it looks like below, stripped of some log messages for brevity.
As in the setup()
function we execute select version();
, you will see in below output that
this is the output from running dbworkload
against PostgreSQL server.
2024-10-20 11:21:03,294 [INFO] (MainProcess MainThread) run:269: Starting workload Bank.20241020_152103
My thread ID is 0. The total count of threads is 1
PostgreSQL 16.2 (Postgres.app) on aarch64-apple-darwin21.6.0, compiled by Apple clang version 14.0.0 (clang-1400.0.29.102), 64-bit
2024-10-20 11:21:04,048 [INFO] (MainProcess MainThread) run:369: Requested iteration/duration limit reached
2024-10-20 11:21:04,050 [INFO] (MainProcess MainThread) run:176: Printing final stats
elapsed id threads tot_ops tot_ops/s period_ops period_ops/s mean(ms) p50(ms) p90(ms) p95(ms) p99(ms) max(ms)
--------- --------- --------- --------- ----------- ------------ -------------- ---------- --------- --------- --------- --------- ---------
1 __cycle__ 1 1 1 1 1 3.59 3.59 3.59 3.59 3.59 3.59
1 txn_read 1 1 1 1 1 3.58 3.58 3.58 3.58 3.58 3.58
2024-10-20 11:21:04,051 [INFO] (MainProcess MainThread) run:181: Printing summary for the full test run
[...]
Test the Order Transaction
We can repeat the exercise to test the Order Transaction functions
# now we set read_pct to zero
# PostgreSQL
dbworkload run -w bank.py --uri 'postgres://fabio:postgres@localhost:5432/bank?sslmode=disable' \
-i 1 --args '{"read_pct": 0}'
# CockroachDB
dbworkload run -w bank.py -c 4 --uri 'postgres://root@localhost:26257/bank?sslmode=disable' \
-i 1 --args '{"read_pct": 0}'
Here's the output from CockroachDB
2024-10-20 11:31:07,678 [INFO] (MainProcess MainThread) run:269: Starting workload Bank.20241020_153107
My thread ID is 0. The total count of threads is 1
CockroachDB CCL v24.2.3 (x86_64-apple-darwin19, built 2024/09/23 22:30:57, go1.22.5 X:nocoverageredesign)
2024-10-20 11:31:08,507 [INFO] (MainProcess MainThread) run:369: Requested iteration/duration limit reached
2024-10-20 11:31:08,509 [INFO] (MainProcess MainThread) run:176: Printing final stats
elapsed id threads tot_ops tot_ops/s period_ops period_ops/s mean(ms) p50(ms) p90(ms) p95(ms) p99(ms) max(ms)
--------- -------------- --------- --------- ----------- ------------ -------------- ---------- --------- --------- --------- --------- ---------
1 __cycle__ 1 1 1 1 1 89.67 89.67 89.67 89.67 89.67 89.67
1 txn_new_order 1 1 1 1 1 21.20 21.20 21.20 21.20 21.20 21.20
1 txn_order_exec 1 1 1 1 1 68.45 68.45 68.45 68.45 68.45 68.45
2024-10-20 11:31:08,511 [INFO] (MainProcess MainThread) run:181: Printing summary for the full test run
[...]
Success! The workload class runs without throwing any runtime errors 🚀
Important
You should always, as a good practice, follow these 2 instructions:
- use
print()
throughout your workload class file to make sure you are generating, retrieving and querying the correct data. For example, print out your bind parameters, the result ofcur.fetchone()
and your variables likeself.order_tuples
, to make sure they contain the items you expect. - inspect the mutated data on the SQL prompt matches with the intended workload goal.