Commit 75c0c02
committed
Ensure PG gives consistent benchmark results
When we added the 10k users to the database, even though the transaction
would never be committed, the query planner would still account for
them. This would mean that the max cost would continuously rise,
thinking there might be 100s of thousands of rows.
This led to `SELECT * FROM users` when the table was empty to take 70ms
to run (when even with 10k users it should be sub millisecond).
I'm not sure exactly what it was doing that was so slow, but if I had to
guess I'd say that it was probably allocating a lot more memory than it
needed to.
By truncating the table at the beginning of each transaction, we ensure
the query planner operates on 10k rows max, giving us consistent
results.
It should be noted that this isn't indicitive of any deeper flaw in the
framework. This gets cleaned up by the periodic vacuum that PG runs,
and in reality creating 10k rows in a transaction and then rolling back
multiple times per second is not realistic.1 parent 604b154 commit 75c0c02
1 file changed
Lines changed: 13 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
13 | 25 | | |
14 | 26 | | |
15 | 27 | | |
| |||
0 commit comments