Skip to content

Instantly share code, notes, and snippets.

@thearthur
Last active April 12, 2017 19:27
Show Gist options
  • Save thearthur/2170d48cc169662dc516414905bbca1b to your computer and use it in GitHub Desktop.
Save thearthur/2170d48cc169662dc516414905bbca1b to your computer and use it in GitHub Desktop.

badness:

starting metabase is slower than it has any good reason to be.

goodness:

Speed up access to liquibase changelog

stuff we know:

possbile solutions

Don’t have this problem

Stop having this problem by just maintaining one file

  • This is the most basic solution. We use git to manage the contents of a single file rather than a directory.
  • Operationally this seems mostly like a matter of opinion.
  • Requires translating json to yaml, which would then need testing.
  • the combined migration file would be ~4000 lines long

limit the number of migration scripts we keep

  • This option seems orthoginal to solving this problem. We can choose to do this now, delay it, or not do it independently of the rest of this problem. I don’t think this is, as such, a solution to this problem.

define “save point” major releases

  • A long delayed upgrade would have to hop through these designated releases, which can be frusterating.
  • The advantage of this is it greatly constrains the combinatorial explosion of possible upgrade paths to test.
  • This also requires work to guide people through the upgrade process.

pre-check if their are any upgrades before letting liquibase run.

This is also orthogonal to solving this problem, and it’s a good idea on it’s own. (Arthur’s opinion)

  • store the last-run git-hash in the DB on startup only run migrations if this value has changed.
  • This is replicating a tiny part of what liquibase does
  • metabase/metabase#4094

Solve this problem

Hack Around the problem

  • Hook Liquibase at runtime to turn the caching back on.
  • This is fragile and almost certainly bad.

Fix the problem in Liquibase

  • They had a problem with cach invalidation (which is the #2 problem in Computer Science after naming things, after naming things ;-) They fixed it by turning off the cache.

Remove their Hack and turn the cache back on

  • They are unlikely to want to merge this patch.
  • leads to perma-fork and more work for us.

Find a better method for Liquibase to clear the cache at the start of import

  • I could be misinterpreting the problem they where trying to solve, though this may help other people that use Liquibase
  • If this works then they are more likely to take the patch because it makes their library faster

add one more layer of abstraction

  • Adding just one more layer of abstraction solves all computer problems after all!

Compile time preprocessing

  • preprocess the migration blobs from one blob per file to many blobs in a single file
  • We need to determine the application order here.

runtime preprocessing

  • move the migration scrips to a secure temp folder before each migration
  • No need to figure out any ordering questions
  • there needs to be a usable and properly functioning temp directory.

consolidate migrations at runtime

  • This combines the same process as the compile time prepossessing option with making a temp-file at runtime
  • Only a temp-file is required, and it may be possible to do it with an in-memory buffer.

How we have decided to solve this problem:

We decided to consolidate the db migrations into a single file.

  • all the json formatted migrations where converted to yaml
  • all the migrations where combined into a single DB change log with many change sets. this was required to preserve the order on new installs
  • This required a pre-migration script to change the filenames in the liquibase DB
  • There is a pre-install check to only run the pre-migration if it’s not a fresh install

is it faster?

unsigned:
04-12 11:53:40 INFO metabase.db :: Checking if Database has unrun migrations...     <---- 1 second
04-12 11:53:41 INFO metabase.db :: Database has unrun migrations. Waiting for migration lock to be cleared...
04-12 11:53:41 INFO metabase.db :: Migration lock is cleared. Running migrations... <---- 1 second
04-12 11:53:42 INFO metabase.db :: Database Migrations Current ...  ✅

signed:
04-12 11:55:27 INFO metabase.db :: Checking if Database has unrun migrations...     <---- 14 seconds
04-12 11:55:41 INFO metabase.db :: Database has unrun migrations. Waiting for migration lock to be cleared...
04-12 11:55:41 INFO metabase.db :: Migration lock is cleared. Running migrations... <---- 14 seconds
04-12 11:55:55 INFO metabase.db :: Database Migrations Current ...  ✅

unsigned with consolidated migrations:
04-12 11:48:22 INFO metabase.db :: Checking if Database has unrun migrations...     <---- 1 second
04-12 11:48:23 INFO metabase.db :: Database has unrun migrations. Waiting for migration lock to be cleared...
04-12 11:48:23 INFO metabase.db :: Migration lock is cleared. Running migrations... <---- 1 second
04-12 11:48:24 INFO metabase.db :: Database Migrations Current ...  ✅

signed with consolidated migrations:
04-12 11:50:31 INFO metabase.db :: Checking if Database has unrun migrations...     <---- 2 seconds (saved 12 seconds here)
04-12 11:50:33 INFO metabase.db :: Database has unrun migrations. Waiting for migration lock to be cleared...
04-12 11:50:33 INFO metabase.db :: Migration lock is cleared. Running migrations... <---- 15 seconds
04-12 11:50:48 INFO metabase.db :: Database Migrations Current ...  ✅
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment