-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Implement teardown for gh-ost library #526
Conversation
Implement teardown for gh-ost library
@nikhilmat what I'm seeing so far is a significant increase in memory consumption. From around On the larger migrations I see memory increase linearly in time. On smaller migrations it may not rise linearly. See this graph for before/after deployment (black vertical line marks deployment time) of this branch: |
I've reverted the deployment to verify |
I suspect the reason is GetDB() ; by overriding caching of @nikhilmat I'd like you to consider how to re-cache the DB object. |
@shlomi-noach thanks for pointing this out! I'll get this fixed up. I had originally implemented the cache on a per-migration basis by adding it to the migration context, but I understand that's not the best place for it given the future plans to serialize that object. I'm happy to implement a per-migration connection cache and test out that it fixes this memory leak - do you have any suggestions about where would be a good place? If we don't want to put the cache on the migration context itself, my instincts point me towards accepting a migration identifier as a part of the |
@nikhilmat is a possible solution. Another idea: how about we cache until |
I had tried that approach originally in the first PR, but ran into an issue with concurrent migrations when:
For this reason, I believe we'll need a migration specific database connection cache to prevent these kinds of failures. I'll give the first approach a shot and push it up to get some feedback! |
Implement Teardown (added back DB cache)
sent to testing in production. I'll report back in a few days. |
thank you @shlomi-noach! happy new year 😄 |
@shlomi-noach really sorry about this, i realized there was a commit missing from my branch that actually calls Sorry again about missing that with the last push, was working with a few branches locally and got mixed up. I hope that doesn't throw too much of a wrench in the testing. |
@nikhilmat sorry, which commit is that? Please link. |
Currently the HEAD of |
Thank you! Applied, sent to testing. |
OK, this looks good in testing! Merging |
Re-PR for #479 by @nikhilmat , required for testing.
Reiterating original PR text:
This PR adds explicit cleanup to gh-ost for when the library is consumed by another application and might be executed multiple times (for example, by a webserver). This stops any infinite goroutines that have started once the migration has finished, closes any DB connections it has opened, and ensures that the migration context that is passed around is not being globally accessed - instead it instantiates a new one for each migration run and passes it around.