Skip to content

Commit

Permalink
Merge pull request apache#140 from sun-rui/SPARKR-183
Browse files Browse the repository at this point in the history
[SPARKR-183] Fix the issue that parallelize collect tests are slow.
  • Loading branch information
concretevitamin committed Jan 30, 2015
2 parents 52356b6 + 2814caa commit da39529
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/R/sparkRBackend.R
Original file line number Diff line number Diff line change
Expand Up @@ -73,18 +73,22 @@ invokeJava <- function(isStatic, objId, methodName, ...) {
writeInt(rc, length(args))
writeArgs(rc, args)

# Construct the whole request message to send it once,
# avoiding write-write-read pattern in case of Nagle's algorithm.
# Refer to http://en.wikipedia.org/wiki/Nagle%27s_algorithm for the details.
bytesToSend <- rawConnectionValue(rc)
close(rc)
rc <- rawConnection(raw(0), "r+")
writeInt(rc, length(bytesToSend))
writeBin(bytesToSend, rc)
requestMessage <- rawConnectionValue(rc)
close(rc)

conn <- get(".sparkRCon", .sparkREnv)
writeInt(conn, length(bytesToSend))
writeBin(bytesToSend, conn)

close(rc) # TODO: Can we close this before ?
writeBin(requestMessage, conn)

# TODO: check the status code to output error information
returnStatus <- readInt(conn)
stopifnot(returnStatus == 0)
ret <- readObject(conn)

ret
readObject(conn)
}

0 comments on commit da39529

Please sign in to comment.