wypoon commented on a change in pull request #23767: [SPARK-26329][CORE] Faster 
polling of executor memory metrics.
URL: https://github.com/apache/spark/pull/23767#discussion_r309345425
 
 

 ##########
 File path: 
core/src/main/scala/org/apache/spark/executor/ExecutorMetricsPoller.scala
 ##########
 @@ -0,0 +1,195 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.spark.executor
+
+import java.lang.Long.{MAX_VALUE => LONG_MAX_VALUE}
+import java.util.concurrent.{ConcurrentHashMap, TimeUnit}
+import java.util.concurrent.atomic.{AtomicLong, AtomicLongArray}
+
+import scala.collection.mutable.HashMap
+
+import org.apache.spark.internal.Logging
+import org.apache.spark.memory.MemoryManager
+import org.apache.spark.metrics.ExecutorMetricType
+import org.apache.spark.util.{ThreadUtils, Utils}
+
+/**
+ * A class that polls executor metrics, and tracks their peaks per task and 
per stage.
+ * Each executor keeps an instance of this class.
+ * The poll method polls the executor metrics, and is either run in its own 
thread or
+ * called by the executor's heartbeater thread, depending on configuration.
+ * The class keeps two ConcurrentHashMaps that are accessed (via its methods) 
by the
+ * executor's task runner threads concurrently with the polling thread. One 
thread may
+ * update one of these maps while another reads it, so the reading thread may 
not get
+ * the latest metrics, but this is ok.
+ * One ConcurrentHashMap tracks the number of running tasks and the executor 
metric
+ * peaks for each stage. A positive task count means the stage is active. When 
the task
+ * count reaches zero for a stage, we remove the entry from the map. That way, 
the map
+ * only contains entries for active stages and does not grow without bound. On 
every
+ * heartbeat, the executor gets the per-stage metric peaks from this class and 
sends
+ * them and the peaks are reset.
+ * The other ConcurrentHashMap tracks the executor metric peaks for each task 
(the peaks
+ * seen while each task is running). At task end, these peaks are sent with 
the task
+ * result by the task runner.
+ * The reason we track executor metric peaks per task in addition to per stage 
is:
+ * If between heartbeats, a stage completes, so there are no more running 
tasks for that
+ * stage, then in the next heartbeat, there are no metrics sent for that 
stage; however,
+ * at the end of a task that belonged to that stage, the metrics would have 
been sent
+ * in the task result, so we do not lose those peaks.
 
 Review comment:
   I replaced the last 3 paragraphs with the single paragraph you suggest, with 
some slight amplification.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to