Repository navigation
Cut a few seconds off of every test using Cockroach - #6934
Merged
Merged
Conversation
smklein
marked this pull request as ready for review
October 25, 2024 19:44
smklein
commented
Oct 25, 2024
| // receive SIGINT. | ||
| tokio::select! { | ||
| _ = db_instance.wait_for_shutdown() => { | ||
| db_instance.cleanup().await.context("clean up after shutdown")?; |
Collaborator
Author
There was a problem hiding this comment.
I removed this line because wait_for_shutdown already is calling cleanup
smklein
commented
Oct 25, 2024
|
|
||
| // It shouldn't really matter which cleanup API we use, since | ||
| // the child process is gone anyway. | ||
| self.cleanup().await |
Collaborator
Author
There was a problem hiding this comment.
(See above comment) this is where wait_for_shutdown already calls cleanup
iliana
approved these changes
Oct 26, 2024
davepacheco
approved these changes
Oct 26, 2024
davepacheco
left a comment
Collaborator
There was a problem hiding this comment.
Nice! I only wonder if db-dev ought to shut down gracefully but it seems like not a big deal either way.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This one has some history!
While working on some database-related APIs, I noticed that my tests using CockroachDB were a lot slower than other tests. To some degree, I expect this, but also, this was on the order of ~5-10 seconds per test doing very little other than CockroachDB setup and teardown.
After doing a little profiling, I noticed that tests took several seconds to perform teardown, which increases significantly if any schema changes occurred.
Why does teardown take so long? Well, it turns out we are sending
SIGTERMto the CockroachDB process to gracefully terminate it, instead ofSIGKILL, which would terminate it much more abruptly.This is where the history comes in: Gracefully terminating CockroachDB was a choice we made a few years ago to avoid a test flake: #540. Basically, when creating the "seed database" -- a database where we apply schema changes that are shared between many tests -- we want to gracefully terminate to avoid leaving the database in a "dirty state", where it might need to flush work and cleanup intermediate state. In the case of #540, that "dirty intermediate state" was an absolute path, which meant copies of that seed database trampled on each other if graceful shutdown did not complete.
Our approach was to apply graceful termination to all CockroachDB teardown invocations, but this was overkill.
Only the seed database expects to have storage be in-use after the call to
cleanup-- all other test-only invocations expect to immediately remove their storage. They don't need to terminate gracefully, and arguably, should just exit as quickly as they can.This PR changes the disposition:
cleanup_gracefullyusesSIGTERM, and waits for graceful cleanup. This is still used when constructing the seed db.cleanupusesSIGKILL, and kills the database immediately. This is now used for all other use-cases.As an example in the performance difference, here's a comparison for some datastore tests:
Before
After