mridulm commented on a change in pull request #35856:
URL: https://github.com/apache/spark/pull/35856#discussion_r839119481
##########
File path: docs/monitoring.md
##########
@@ -611,6 +611,15 @@ can be identified by their `[attempt-id]`. In the API
listed below, when running
<code>?planDescription=[true (default) | false]</code> enables/disables
Physical <code>planDescription</code> on demand for the given query when
Physical Plan size is high.
</td>
</tr>
+ <tr>
+ <td><code>/applications/[app-id]/diagnostics/[execution-id]</code></td>
Review comment:
Move this under sql ?
##########
File path: core/src/main/scala/org/apache/spark/status/AppStatusStore.scala
##########
@@ -754,18 +760,33 @@ private[spark] class AppStatusStore(
}
}
-private[spark] object AppStatusStore {
+private[spark] object AppStatusStore extends Logging {
val CURRENT_VERSION = 2L
/**
- * Create an in-memory store for a live application.
+ * Create an in-memory store for a live application. also create a disk
store if
+ * the `spark.appStatusStore.diskStore.dir` is set
*/
def createLiveStore(
conf: SparkConf,
appStatusSource: Option[AppStatusSource] = None): AppStatusStore = {
val store = new ElementTrackingStore(new InMemoryStore(), conf)
val listener = new AppStatusListener(store, conf, true, appStatusSource)
- new AppStatusStore(store, listener = Some(listener))
+ // create a disk-based kv store if the directory is set
+ val diskStore = conf.get(DISK_STORE_DIR_FOR_STATUS).flatMap { storeDir =>
+ val storePath = Files.createDirectories(
+ new File(storeDir, System.currentTimeMillis().toString).toPath
+ ).toFile
+ try {
+ Some(KVUtils.open(storePath, AppStatusStoreMetadata(CURRENT_VERSION),
conf))
+ .map(new ElementTrackingStore(_, conf))
+ } catch {
+ case NonFatal(e) =>
+ logWarning("Failed to create disk-based app status store: ", e)
+ None
+ }
+ }
+ new AppStatusStore(store, diskStore = diskStore, listener = Some(listener))
Review comment:
If we have enabled diskstore, thoughts on using it for everything at
driver ?
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/diagnostic/DiagnosticListener.scala
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.sql.diagnostic
+
+import org.apache.spark.SparkConf
+import org.apache.spark.scheduler.{SparkListener, SparkListenerEvent}
+import org.apache.spark.sql.execution.ExplainMode
+import
org.apache.spark.sql.execution.ui.{SparkListenerSQLAdaptiveExecutionUpdate,
SparkListenerSQLExecutionEnd, SparkListenerSQLExecutionStart}
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.internal.StaticSQLConf.UI_RETAINED_EXECUTIONS
+import org.apache.spark.status.{ElementTrackingStore, KVUtils}
+
+class DiagnosticListener(
+ conf: SparkConf,
+ kvStore: ElementTrackingStore) extends SparkListener {
+
+ kvStore.addTrigger(
+ classOf[ExecutionDiagnosticData],
+ conf.get(UI_RETAINED_EXECUTIONS)) { count =>
+ cleanupExecutions(count)
+ }
+
+ override def onOtherEvent(event: SparkListenerEvent): Unit = event match {
+ case e: SparkListenerSQLExecutionStart => onExecutionStart(e)
+ case e: SparkListenerSQLExecutionEnd => onExecutionEnd(e)
+ case e: SparkListenerSQLAdaptiveExecutionUpdate =>
onAdaptiveExecutionUpdate(e)
+ case _ => // Ignore
+ }
+
+ private def onAdaptiveExecutionUpdate(event:
SparkListenerSQLAdaptiveExecutionUpdate): Unit = {
+ val data = new AdaptiveExecutionUpdate(
+ event.executionId,
+ System.currentTimeMillis(),
+ event.physicalPlanDescription
+ )
+ kvStore.write(data)
+ }
+
+ private def onExecutionStart(event: SparkListenerSQLExecutionStart): Unit = {
+ val planDescriptionMode = ExplainMode.fromString(SQLConf.get.uiExplainMode)
+ val physicalPlan = event.qe.explainString(planDescriptionMode,
Int.MaxValue)
+ val data = new ExecutionDiagnosticData(
+ event.executionId,
+ physicalPlan,
+ event.time,
+ None,
+ None
+ )
+ // Check triggers since it's adding new netries
+ kvStore.write(data, checkTriggers = true)
+ }
+
+ private def onExecutionEnd(event: SparkListenerSQLExecutionEnd): Unit = {
+ try {
+ val existing = kvStore.read(classOf[ExecutionDiagnosticData],
event.executionId)
+ val planDescriptionMode =
ExplainMode.fromString(SQLConf.get.uiExplainMode)
+ val physicalPlan = event.qe.explainString(planDescriptionMode,
Int.MaxValue)
+ val data = new ExecutionDiagnosticData(
+ event.executionId,
+ physicalPlan,
+ existing.submissionTime,
+ Some(event.time),
+ event.executionFailure.map(
+ e => s"${e.getClass.getCanonicalName}:
${e.getMessage}").orElse(Some(""))
+ )
+ kvStore.write(data)
+ } catch {
+ case _: NoSuchElementException =>
+ // this is possibly caused by the query failed before execution.
+ }
+ }
+
+ private def cleanupExecutions(count: Long): Unit = {
+ val countToDelete = count - conf.get(UI_RETAINED_EXECUTIONS)
+ if (countToDelete <= 0) {
+ return
+ }
+ val view =
kvStore.view(classOf[ExecutionDiagnosticData]).index("completionTime").first(0L)
+ val toDelete = KVUtils.viewToSeq(view,
countToDelete.toInt)(_.completionTime.isDefined)
+ toDelete.foreach(e => kvStore.delete(classOf[ExecutionDiagnosticData],
e.executionId))
+ kvStore.removeAllByIndexValues(
+ classOf[AdaptiveExecutionUpdate], "id", toDelete.map(_.executionId))
+ }
+}
+
+object DiagnosticListener {
+ val QUEUE_NAME = "diagnostics"
Review comment:
rename to `sqlDiagnostics`
##########
File path:
sql/core/src/main/scala/org/apache/spark/sql/diagnostic/DiagnosticListener.scala
##########
@@ -0,0 +1,103 @@
+/*
+ * 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.sql.diagnostic
+
+import org.apache.spark.SparkConf
+import org.apache.spark.scheduler.{SparkListener, SparkListenerEvent}
+import org.apache.spark.sql.execution.ExplainMode
+import
org.apache.spark.sql.execution.ui.{SparkListenerSQLAdaptiveExecutionUpdate,
SparkListenerSQLExecutionEnd, SparkListenerSQLExecutionStart}
+import org.apache.spark.sql.internal.SQLConf
+import org.apache.spark.sql.internal.StaticSQLConf.UI_RETAINED_EXECUTIONS
+import org.apache.spark.status.{ElementTrackingStore, KVUtils}
+
+class DiagnosticListener(
+ conf: SparkConf,
+ kvStore: ElementTrackingStore) extends SparkListener {
+
+ kvStore.addTrigger(
+ classOf[ExecutionDiagnosticData],
+ conf.get(UI_RETAINED_EXECUTIONS)) { count =>
+ cleanupExecutions(count)
+ }
+
+ override def onOtherEvent(event: SparkListenerEvent): Unit = event match {
+ case e: SparkListenerSQLExecutionStart => onExecutionStart(e)
+ case e: SparkListenerSQLExecutionEnd => onExecutionEnd(e)
+ case e: SparkListenerSQLAdaptiveExecutionUpdate =>
onAdaptiveExecutionUpdate(e)
+ case _ => // Ignore
+ }
+
+ private def onAdaptiveExecutionUpdate(event:
SparkListenerSQLAdaptiveExecutionUpdate): Unit = {
+ val data = new AdaptiveExecutionUpdate(
+ event.executionId,
+ System.currentTimeMillis(),
+ event.physicalPlanDescription
+ )
+ kvStore.write(data)
+ }
+
+ private def onExecutionStart(event: SparkListenerSQLExecutionStart): Unit = {
+ val planDescriptionMode = ExplainMode.fromString(SQLConf.get.uiExplainMode)
+ val physicalPlan = event.qe.explainString(planDescriptionMode,
Int.MaxValue)
+ val data = new ExecutionDiagnosticData(
+ event.executionId,
+ physicalPlan,
+ event.time,
+ None,
+ None
+ )
+ // Check triggers since it's adding new netries
+ kvStore.write(data, checkTriggers = true)
+ }
+
+ private def onExecutionEnd(event: SparkListenerSQLExecutionEnd): Unit = {
+ try {
+ val existing = kvStore.read(classOf[ExecutionDiagnosticData],
event.executionId)
+ val planDescriptionMode =
ExplainMode.fromString(SQLConf.get.uiExplainMode)
+ val physicalPlan = event.qe.explainString(planDescriptionMode,
Int.MaxValue)
Review comment:
Agree with @dongjoon-hyun , we should impose a limit here.
@shardulm94 can comment more on his observations with something similar in
terms of increase in cost - he had done a streaming serialization
implementation to get around the issue (he was writing to hdfs, so the solution
directly wont apply here).
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]