Skip to content

Conversation

@hvanhovell
Copy link
Contributor

What changes were proposed in this pull request?

Tests in Spark Streaming currently create a SparkContext for each test, and sometimes do not clean-up afterwards. This is resource intensive and it can lead to unneeded test failures (flakyness) when park.driver.allowMultipleContexts is disabled (this happens when the order of tests changes).

This PR makes most test re-use a SparkContext. For tests that have to create a new context (for instance CheckpointSuite) we make sure that no active SparkContext exists before the test, and that the created SparkContext is cleaned up afterwards. I have refactored the TestSuiteBase into two classes TestSuiteBase and a parent class ReusableSparkContext; this to make SparkContext management relatively straightforward for most tests.

I have done a simple very unscientific benchmark (n=1), and streaming tests with this patch took 212 seconds and streaming tests without this patch took 252 seconds.

How was this patch tested?

The patch only covers test code.

@hvanhovell
Copy link
Contributor Author

cc @tdas @zsxwing

@zsxwing
Copy link
Member

zsxwing commented Dec 6, 2016

This is resource intensive and it can lead to unneeded test failures (flakyness) when park.driver.allowMultipleContexts is disabled (this happens when the order of tests changes).

Do you mean the recent failures? It was fixed by #16105.


@Before
public void setUp() {
SparkContext$.MODULE$.stopActiveContext();
Copy link
Contributor

Choose a reason for hiding this comment

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

Can't you just call SparkContext.stopActiveContext() from Java? I see static methods in the bytecode for things like jarOfObject.

The line is also indented incorrectly.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Intellij and SBT were both complaining. So I did this.

I'll try to rebuild and see what happens.

}
}

private[spark] def stopActiveContext(): Unit = {
Copy link
Contributor

Choose a reason for hiding this comment

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

I don't know. I'm not a big fan of the approach you're taking here: calling this method before running tests. That feels like a sledgehammer to fix flaky tests. I think it would be better for test code to be more careful about cleaning after itself. Kinda like most tests in spark-core use LocalSparkContext to more or less automatically do that without the need for these methods.

The ReuseableSparkContext trait you have is a step in that direction. If you make sure all needed streaming tests are using it, and keep this state within that class, I think it would be a better change.

Copy link
Member

Choose a reason for hiding this comment

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

+1. I don't like stopping SparkContext before running tests, either. It will hide the mistakes in other tests.

Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this be unnecessary with more carefully written tests? that always close the context etc when done?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I have to admit that the approach is far from subtle.

It seems that #16105 fixes this (also on my branch). I am closing this for now. Thanks for the feedback.

@SparkQA
Copy link

SparkQA commented Dec 6, 2016

Test build #69736 has finished for PR 16174 at commit 04ce488.

  • This patch passes all tests.
  • This patch merges cleanly.
  • This patch adds no public classes.

@hvanhovell hvanhovell closed this Dec 6, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants