spark-reviews mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cloud-fan <...@git.apache.org>
Subject [GitHub] spark pull request #18083: [SPARK-20863] Add metrics/instrumentation to Live...
Date Thu, 08 Jun 2017 19:07:40 GMT
Github user cloud-fan commented on a diff in the pull request:

    https://github.com/apache/spark/pull/18083#discussion_r120973638
  
    --- Diff: core/src/main/scala/org/apache/spark/util/ListenerBus.scala ---
    @@ -23,29 +23,41 @@ import scala.collection.JavaConverters._
     import scala.reflect.ClassTag
     import scala.util.control.NonFatal
     
    +import com.codahale.metrics.Timer
    +
     import org.apache.spark.internal.Logging
     
     /**
      * An event bus which posts events to its listeners.
      */
     private[spark] trait ListenerBus[L <: AnyRef, E] extends Logging {
     
    +  private[this] val listenersPlusTimers = new CopyOnWriteArrayList[(L, Timer)]
    +
       // Marked `private[spark]` for access in tests.
    -  private[spark] val listeners = new CopyOnWriteArrayList[L]
    +  private[spark] def listeners = listenersPlusTimers.asScala.map(_._1).asJava
    +
    +  /**
    +   * Returns a CodaHale metrics Timer for measuring the listener's event processing time.
    +   * This method is intended to be overridden by subclasses.
    +   */
    +  protected def getTimer(listener: L): Option[Timer] = None
     
       /**
        * Add a listener to listen events. This method is thread-safe and can be called in
any thread.
        */
       final def addListener(listener: L): Unit = {
    -    listeners.add(listener)
    +    listenersPlusTimers.add((listener, getTimer(listener).orNull))
       }
     
       /**
        * Remove a listener and it won't receive any events. This method is thread-safe and
can be called
        * in any thread.
        */
       final def removeListener(listener: L): Unit = {
    -    listeners.remove(listener)
    +    listenersPlusTimers.asScala.find(_._1 eq listener).foreach { listenerAndTimer =>
    +      listenersPlusTimers.remove(listenerAndTimer)
    --- End diff --
    
    since this is a `CopyOnWriteArrayList`, shall we just do a filter and create a new array?


---
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.
---

---------------------------------------------------------------------
To unsubscribe, e-mail: reviews-unsubscribe@spark.apache.org
For additional commands, e-mail: reviews-help@spark.apache.org


Mime
View raw message