New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Integrity Check performance #252
Comments
Daniel shared some work he did a while ago: ed0c516 |
daniellockyer
added a commit
that referenced
this issue
Oct 8, 2021
refs #252 - the referenced issue describes performance problems with the integrity check code in knex-migrator - this commit solves half of the problem - 1 DB call per migration minor version folder - this results in 70+ (and growing) DB calls at the time of writing, with each one going back and forth to the DB... not efficient - what the code actually needed was a count of how many migrations are currently in the DB, group by minor version - this is very easy to do in SQL and therefore knex - this commit switches the code around to group all the DB migrations first, and then compares against the folders locally - this results in a drop of SQL queries from 70+ to 1 🚀
daniellockyer
added a commit
that referenced
this issue
Oct 8, 2021
refs #252 - the referenced issue describes performance problems with the integrity check code in knex-migrator - this commit solves half of the problem - 1 DB call per migration minor version folder - this results in 70+ (and growing!) DB calls at boot, with each one going back and forth to the DB... not efficient - what the code actually needed was a count of how many migrations are currently in the DB, group by minor version - this is very easy to do in SQL and therefore knex - this commit switches the code around to group all the DB migrations first, and then compares against the folders locally - this results in a drop of SQL queries from 70+ to 1 🚀
daniellockyer
added a commit
that referenced
this issue
Oct 8, 2021
refs #252 - the referenced issue describes performance problems with the integrity check code in knex-migrator - this commit solves half of the problem - 1 DB call per migration minor version folder - this results in 70+ (and growing!) DB calls at boot, with each one going back and forth to the DB... not efficient - what the code actually needed was a count of how many migrations are currently in the DB, grouped by version - this is very easy to do in SQL and therefore knex - this commit switches the code around to group all the DB migrations first, and then compares against the folders locally - this results in a drop of SQL queries from 70+ to 1 🚀
daniellockyer
added a commit
that referenced
this issue
Oct 8, 2021
refs #252 - the referenced issue describes performance problems with the integrity check code in knex-migrator - this commit solves half of the problem - 1 DB call per migration minor version folder - this results in 70+ (and growing!) DB calls at boot, with each one going back and forth to the DB... not efficient - what the code actually needed was a count of how many migrations are currently in the DB, grouped by version - this is very easy to do in SQL and therefore knex - this commit switches the code around to group all the DB migrations first, and then compares against the folders locally - this results in a drop of SQL queries from 70+ to 1 🚀
838fe54 solves half of the problem here - the DB queries. I had the code ready from before and felt they were more important because they go across network. The file/folder lookup still needs some work but there's some refactoring needed in this area of code first because we're heavily using promise chaining and it's making it painful to work with 🙂 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
When first called, knex-migrator runs an "integrity check" to make sure migrations are in a state it can understand.
Problem
This has been implemented in a straightforward way, first reading the versions folder to get all the versions, and then looping over those twice, first to lookup what is in the DB and second to lookup what is in the folder - i.e. a DB read and a file read per version.
knex-migrator/lib/index.js
Lines 1151 to 1238 in cb97928
This code suffers from a performance issue, where the time it takes to run is in the order 0(2n) , where n is the number of versions. 2n rather than just n, as there are 2 loops both doing expensive operations and solving either would be an improvement.
Additionally, the file reads have been implemented using sync methods.
Solution
It should be possible to reduce the number of expensive and synchronous operations, and also get it down to a single loop, by:
Fixing this should reduce the time this function takes with large numbers of migrations (i.e. Ghost) significantly
The text was updated successfully, but these errors were encountered: