Skip to content

Draft: Use unlogged tables to speedup tests

Michael Prilop requested to merge use-unlogged-tables-to-speedup-tests into main

Using unlogged tables should result in faster test execution as writing to unlogged tables is a lot faster.

BUT we use standard rails test mechanismen. These load fixtures before tests, execute the test in a transaction and simply revert the transaction to reset the database for the next test. The data is more less only written once to the tables. Therefor unlogged tables result in no significant speedup when used to run our test suite. A full test run takes 7:41 with unlogged tables and 7:49 with logged tables (which is well in what we see as deviation between test runs).

To tryout unlogged vs. logged performance simply set UNLOGGED_TABLES=true env variable.

➜  samarbeid git:(use-unlogged-tables-to-speedup-tests) ✗ spring stop && time PARALLEL_WORKERS=1 UNLOGGED_TABLES=true rails test
Spring stopped.
/usr/bin/docker-compose
Running via Spring preloader in process 162164
Running tests with setting: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = true
Run options: --seed 60130

# Running:

.........................................................................................................................................................................................................................................................S..............................................................S................................................................................................................................................................................................................................................................................................................................................................................................................................S............

Finished in 455.253514s, 1.6299 runs/s, 32.6741 assertions/s.
742 runs, 14875 assertions, 0 failures, 0 errors, 3 skips

You have skipped tests. Run with --verbose for details.
Coverage report generated for Minitest, Minitest-0, Minitest-1, Minitest-2, Minitest-3, Minitest-4, Minitest-5 to /home/prilop/code/samarbeid/coverage. 4266 / 4925 LOC (86.62%) covered.
PARALLEL_WORKERS=1 UNLOGGED_TABLES=true rails test  0,85s user 0,03s system 0% cpu 7:41,34 total
➜  samarbeid git:(use-unlogged-tables-to-speedup-tests) ✗ spring stop && time PARALLEL_WORKERS=1 UNLOGGED_TABLES=false rails test
Spring stopped.
/usr/bin/docker-compose
Running via Spring preloader in process 180761
Running tests with setting: ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.create_unlogged_tables = false
Run options: --seed 46692

# Running:

..............................................................................................................................................................................................................................................................................................S..........................S...............................................................................................................................................................................................................................................................................................................S............................................................................................................................

Finished in 463.070047s, 1.6023 runs/s, 32.1226 assertions/s.
742 runs, 14875 assertions, 0 failures, 0 errors, 3 skips

You have skipped tests. Run with --verbose for details.
Coverage report generated for Minitest, Minitest-0, Minitest-1, Minitest-2, Minitest-3, Minitest-4, Minitest-5 to /home/prilop/code/samarbeid/coverage. 4266 / 4925 LOC (86.62%) covered.
PARALLEL_WORKERS=1 UNLOGGED_TABLES=false rails test  0,80s user 0,07s system 0% cpu 7:49,19 total
Edited by Michael Prilop

Merge request reports