Skip to content
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

Test sharding for jenkins #8150

Merged

Conversation

spalger
Copy link
Contributor

@spalger spalger commented Sep 1, 2016

The tests in master are currently failing regularly because our current browser tests are serious memory hogs. Investigation reveals that nearly every test is retaining all of the memory it causes to be allocated. We have made some progress to being able to diagnose the problems, but we expect that problem to take some serious work to fix. We need a short-term solution though, and this is it.

Rather than modify the bundling process, we will shard the top-level test suites by name. For now, we've created 4 shards, but adding new shards is trivial if we need to.

Sharding is accomplished by murmur3 hashing the top level suite names then bucketing based on the hash output. If a test suite resolves to shard2, but we are running shard1, we simply never pass the function to mocha. Rather than redefine every describe statement, we have shimmed the global window.describe() function to accomplish this.

@@ -195,6 +195,7 @@
"makelogs": "3.0.2",
"marked-text-renderer": "0.1.0",
"mocha": "2.5.3",
"murmurhash3js": "3.0.1",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are we using for the hashes in the upcoming state PR? Can we use the same dependency?

Copy link
Contributor Author

@spalger spalger Sep 1, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're using sha256 for the state pr, because sha256 provides better unique-ness. Here we're using murmur3 because the hashes it produces are numbers, making it trivial to bucket based on the hash (see get_shard_num.js).

So, we could use the same hashing function in both places, but I think the problems we're trying to solve in both places are different and these are the best algorithms for their respective job.

*
* @return {string} url
*/
export function findBundleUrl() {
Copy link
Contributor

@cjcenizal cjcenizal Sep 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to hardcode the /tests.bundle.js string here, we should rename this to findTestBundleUrl. If we want to support passing in the string here, we can keep the current name but should pass in /tests.bundle.js and update the comments.

@cjcenizal
Copy link
Contributor

Done reviewing! Left some comments and had a spirited discussion with Spencer.

@spalger spalger force-pushed the test/shardTestsToEaseMemoryPressure branch from 8385343 to 0c0fe6b Compare September 2, 2016 03:58
});

// Filter root level describe statements as they come
setupRootDescribeCallFilter(describeName => {
Copy link
Contributor Author

@spalger spalger Sep 2, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cjcenizal After we talked, I moved to this style. Putting the comments in this file made it less readable, so I pushed the walking/intercepting down to the lower module and just pulled out the filter bit. Thoughts?

@epixa
Copy link
Contributor

epixa commented Sep 2, 2016

Hmm... test failure?

@spalger
Copy link
Contributor Author

spalger commented Sep 2, 2016

Dang, I pushed the wrong master snapshot to esvm... fixing. (Thought that we had fixed sonatype...)

// murmur3 produces 32bit integers, so we devide it by the number of chunks
// to determine which chunk the suite should fall in. +1 because the current
// chunk is 1-based
const shardNum = Math.floor(hashInt / hashIntsPerShard) + 1;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be suiteShard.

@cjcenizal
Copy link
Contributor

Looks great! Left some suggestions, but they're up to you to decide if you want to implement them or not.

LG(great)TM.

@epixa
Copy link
Contributor

epixa commented Sep 2, 2016

@spalger If you update based on any feedback you want to address and make sure the tests are passing, I'll +1 this.

@spalger spalger force-pushed the test/shardTestsToEaseMemoryPressure branch from 0c0fe6b to 3999f9f Compare September 2, 2016 17:09
@spalger spalger force-pushed the test/shardTestsToEaseMemoryPressure branch 3 times, most recently from 21ead03 to 739d7ec Compare September 2, 2016 17:24

// ensure that window.describe isn't messed with by other code,
// if it becomes necessary in the future we can make this fancier
Object.defineProperty(window, 'describe', {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any chance that Mocha could choose to do this in the future and break this solution?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a chance that something will try to override window.describe, but since the describe property is now configurable: false and writable: false (the default) it will cause an error to be thrown if something tries to change it.

@spalger spalger force-pushed the test/shardTestsToEaseMemoryPressure branch from 739d7ec to 9f9ecf5 Compare September 2, 2016 17:35
The tests in master are currently failing regularly because our current browser tests are serious memory hogs. Investigation reveals that nearly every test is retaining all of the memory it causes to be allocated. We have made some progress to being able to diagnose the problems, but we expect that problem to take some serious work to fix. We need a short-term solution though, and this is it.

Rather than modify the bundling process, we will shard the top-level test suites by name. For now, we've created 4 shards, but adding new shards is trivial if we need to.

Sharding is accomplished by creating a murmur3 hash of the top level suite names, then bucketing based on the hash output. If a test suite resolves to shard2, but we are running shard1, we simply never pass the function to `mocha.describe()`. Rather than redefine every describe statement, we have shimmed the global `window.describe()` function to accomplish this.
@spalger spalger force-pushed the test/shardTestsToEaseMemoryPressure branch 2 times, most recently from ba0fa27 to 88427e9 Compare September 2, 2016 17:40
@epixa
Copy link
Contributor

epixa commented Sep 2, 2016

LGTM

@epixa epixa changed the title add test sharding Test sharding for jenkins Sep 2, 2016
@spalger spalger merged commit d94ab0b into elastic:master Sep 2, 2016
@spalger spalger deleted the test/shardTestsToEaseMemoryPressure branch September 9, 2016 23:12
airow pushed a commit to airow/kibana that referenced this pull request Feb 16, 2017
…oryPressure

add test sharding

Former-commit-id: d94ab0b
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants