Skip to content

Commit

Permalink
Use SPARKR_BACKEND_PORT in sparkR.R as default
Browse files Browse the repository at this point in the history
Change SparkRRunner to use EXISTING_SPARKR_BACKEND_PORT to
differentiate between the two
  • Loading branch information
shivaram committed Feb 19, 2015
1 parent 22a19ac commit bc04cf4
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 7 deletions.
5 changes: 3 additions & 2 deletions pkg/R/sparkR.R
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ sparkR.init <- function(
sparkExecutorEnv = list(),
sparkJars = "",
sparkRLibDir = "",
sparkRBackendPort = 12345) {
sparkRBackendPort = as.integer(Sys.getenv("SPARKR_BACKEND_PORT", "12345"))) {

if (exists(".sparkRjsc", envir = .sparkREnv)) {
cat("Re-using existing Spark Context. Please stop SparkR with sparkR.stop() or restart R to create a new Spark Context\n")
Expand All @@ -106,7 +106,8 @@ sparkR.init <- function(
if (yarn_conf_dir != "") {
cp <- paste(cp, yarn_conf_dir, sep = ":")
}
sparkRExistingPort <- Sys.getenv("SPARKR_BACKEND_PORT", "")

sparkRExistingPort <- Sys.getenv("EXISTING_SPARKR_BACKEND_PORT", "")
if (sparkRExistingPort != "") {
sparkRBackendPort <- sparkRExistingPort
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,8 @@ object SparkRRunner {

val otherArgs = args.slice(1, args.length)

// Pick a non-privileged port
val randomPort = scala.util.Random.nextInt(65536 - 1024) + 1024

// TODO: Can we get this from SparkConf ?
val sparkRBackendPort = sys.env.getOrElse("SPARKR_BACKEND_PORT", randomPort.toString).toInt
val sparkRBackendPort = sys.env.getOrElse("SPARKR_BACKEND_PORT", "12345").toInt
val rCommand = "Rscript"

// Check if the file path exists.
Expand Down Expand Up @@ -61,7 +58,7 @@ object SparkRRunner {
// Launch R
val builder = new ProcessBuilder(Seq(rCommand, rFileNormalized) ++ otherArgs)
val env = builder.environment()
env.put("SPARKR_BACKEND_PORT", "" + sparkRBackendPort)
env.put("EXISTING_SPARKR_BACKEND_PORT", "" + sparkRBackendPort)
builder.redirectErrorStream(true) // Ugly but needed for stdout and stderr to synchronize
val process = builder.start()

Expand Down

0 comments on commit bc04cf4

Please sign in to comment.