aboutsummaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorAaron Davidson <aaron@databricks.com>2014-07-31 15:31:53 -0700
committerJosh Rosen <joshrosen@apache.org>2014-07-31 15:31:53 -0700
commitef4ff00f87a4e8d38866f163f01741c2673e41da (patch)
treee5674bacee57daaaca98201703197bee0c94a4b8 /core
parent492a195c5c4d68c85b8b1b48e3aa85165bbb5dc3 (diff)
downloadspark-ef4ff00f87a4e8d38866f163f01741c2673e41da.tar.gz
spark-ef4ff00f87a4e8d38866f163f01741c2673e41da.tar.bz2
spark-ef4ff00f87a4e8d38866f163f01741c2673e41da.zip
SPARK-2282: Reuse Socket for sending accumulator updates to Pyspark
Prior to this change, every PySpark task completion opened a new socket to the accumulator server, passed its updates through, and then quit. I'm not entirely sure why PySpark always sends accumulator updates, but regardless this causes a very rapid buildup of ephemeral TCP connections that remain in the TCP_WAIT state for around a minute before being cleaned up. Rather than trying to allow these sockets to be cleaned up faster, this patch simply reuses the connection between tasks completions (since they're fed updates in a single-threaded manner by the DAGScheduler anyway). The only tricky part here was making sure that the AccumulatorServer was able to shutdown in a timely manner (i.e., stop polling for new data), and this was accomplished via minor feats of magic. I have confirmed that this patch eliminates the buildup of ephemeral sockets due to the accumulator updates. However, I did note that there were still significant sockets being created against the PySpark daemon port, but my machine was not able to create enough sockets fast enough to fail. This may not be the last time we've seen this issue, though. Author: Aaron Davidson <aaron@databricks.com> Closes #1503 from aarondav/accum and squashes the following commits: b3e12f7 [Aaron Davidson] SPARK-2282: Reuse Socket for sending accumulator updates to Pyspark
Diffstat (limited to 'core')
-rw-r--r--core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala20
1 files changed, 15 insertions, 5 deletions
diff --git a/core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala b/core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala
index a9d758bf99..94d666aa92 100644
--- a/core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala
+++ b/core/src/main/scala/org/apache/spark/api/python/PythonRDD.scala
@@ -731,19 +731,30 @@ private class PythonAccumulatorParam(@transient serverHost: String, serverPort:
val bufferSize = SparkEnv.get.conf.getInt("spark.buffer.size", 65536)
+ /**
+ * We try to reuse a single Socket to transfer accumulator updates, as they are all added
+ * by the DAGScheduler's single-threaded actor anyway.
+ */
+ @transient var socket: Socket = _
+
+ def openSocket(): Socket = synchronized {
+ if (socket == null || socket.isClosed) {
+ socket = new Socket(serverHost, serverPort)
+ }
+ socket
+ }
+
override def zero(value: JList[Array[Byte]]): JList[Array[Byte]] = new JArrayList
override def addInPlace(val1: JList[Array[Byte]], val2: JList[Array[Byte]])
- : JList[Array[Byte]] = {
+ : JList[Array[Byte]] = synchronized {
if (serverHost == null) {
// This happens on the worker node, where we just want to remember all the updates
val1.addAll(val2)
val1
} else {
// This happens on the master, where we pass the updates to Python through a socket
- val socket = new Socket(serverHost, serverPort)
- // SPARK-2282: Immediately reuse closed sockets because we create one per task.
- socket.setReuseAddress(true)
+ val socket = openSocket()
val in = socket.getInputStream
val out = new DataOutputStream(new BufferedOutputStream(socket.getOutputStream, bufferSize))
out.writeInt(val2.size)
@@ -757,7 +768,6 @@ private class PythonAccumulatorParam(@transient serverHost: String, serverPort:
if (byteRead == -1) {
throw new SparkException("EOF reached before Python server acknowledged")
}
- socket.close()
null
}
}