Skip to content

Commit da39529

Browse files
Merge pull request apache#140 from sun-rui/SPARKR-183
[SPARKR-183] Fix the issue that parallelize collect tests are slow.
2 parents 52356b6 + 2814caa commit da39529

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

pkg/R/sparkRBackend.R

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,22 @@ invokeJava <- function(isStatic, objId, methodName, ...) {
7373
writeInt(rc, length(args))
7474
writeArgs(rc, args)
7575

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

7887
conn <- get(".sparkRCon", .sparkREnv)
79-
writeInt(conn, length(bytesToSend))
80-
writeBin(bytesToSend, conn)
81-
82-
close(rc) # TODO: Can we close this before ?
88+
writeBin(requestMessage, conn)
8389

8490
# TODO: check the status code to output error information
8591
returnStatus <- readInt(conn)
8692
stopifnot(returnStatus == 0)
87-
ret <- readObject(conn)
88-
89-
ret
93+
readObject(conn)
9094
}

0 commit comments

Comments
 (0)