www-infrastructure-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pwendell <...@git.apache.org>
Subject [GitHub] incubator-spark pull request: Patch for SPARK-942
Date Tue, 25 Feb 2014 06:20:12 GMT
Github user pwendell commented on a diff in the pull request:

    https://github.com/apache/incubator-spark/pull/180#discussion_r10025521
  
    --- Diff: core/src/main/scala/org/apache/spark/serializer/JavaSerializer.scala ---
    @@ -25,7 +25,22 @@ import org.apache.spark.SparkConf
     
     private[spark] class JavaSerializationStream(out: OutputStream) extends SerializationStream
{
       val objOut = new ObjectOutputStream(out)
    -  def writeObject[T](t: T): SerializationStream = { objOut.writeObject(t); this }
    +  var counter = 0
    +  /* Calling reset to avoid memory leak:
    +   * http://stackoverflow.com/questions/1281549/memory-leak-traps-in-the-java-standard-api
    +   * But only call it every 1000th time to avoid bloated serialization streams (when
    +   * the stream 'resets' object class descriptions have to be re-written)  
    +   */
    +  def writeObject[T](t: T): SerializationStream = {
    +    objOut.writeObject(t)
    +    if (counter >= 1000) {
    +      objOut.reset()
    +      counter = 0
    +    } else {
    --- End diff --
    
    Ya +1. There is actually a cost of having this to small. Internally that output stream
uses datastructures that grow by doubling, so if you keep reseting it, they have to double
very often resulting in a lot of memory copies. It might be good to use 10,000 as the default.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

Mime
View raw message