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

call sc.stop() in accordance with spark 0.8 #5

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/main/scala/util/MLLRDemo.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ import org.apache.spark.SparkContext

object MLILRDemo {
def main(args: Array[String]) = {
val mc = new MLContext(new SparkContext("local[4]", "MLILRtest"))
val sc = new SparkContext("local[4]", "MLIRtest")
val mc = new MLContext(sc)

val data = mc.loadCsvFile(args(0))
val d2 = data.map((x: MLRow) => x.drop(0).+:(if(x(0).toString == "n07760859") MLValue(1.0) else MLValue(0.0))).cache()
Expand All @@ -16,5 +17,6 @@ object MLILRDemo {
//val model = SVMAlgorithm.train(d2)

println("Time to train: " + model.trainingTime)
sc.stop()
}
}
2 changes: 2 additions & 0 deletions src/test/scala/ml/RegressionTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ class RegressionTests extends FunSuite with BeforeAndAfter with LocalSparkContex
println("\t Learned model: ")
println(model.wOpt)
*/

sc.stop()
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class LogisticRegressionSuite extends FunSuite with LocalSparkContext {
x = model.predict(MLVector(Array(0.0,0.0))).toNumber
println("Model prediction for (-1.0,0.0): " + x)
assert(x <= 0.5)
sc.stop()
Copy link
Member

Choose a reason for hiding this comment

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

For these test suites, shouldn't the afterEach() method in the LocalSparkContext trait take care of stopping these contexts? SparkContext.stop() is idempotent and an extra call wouldn't cause problems, though.

Copy link
Author

Choose a reason for hiding this comment

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

You're right, after playing with it some more it appears to fail non-deterministically. Adding sc.stop() here falsely mitigated the problem by reducing the number of times it fails. I'm not sure the root issue (maybe sbt/sbt test run in parallel?), but will stymie this for now and check later.

}

test("Basic test of logistic regression via Parallel Gradient") {
Expand All @@ -39,6 +40,7 @@ class LogisticRegressionSuite extends FunSuite with LocalSparkContext {

println(model.explain)
assert(true)
sc.stop()
}

}