Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] [SPARK-51097] [SS] Split apart SparkPlan metrics and instance metrics #50157

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,17 @@ abstract class SparkPlan extends QueryPlan[SparkPlan] with Logging with Serializ
*/
def metrics: Map[String, SQLMetric] = Map.empty

/**
* @return All instance metrics of this SparkPlan.
*/
def instanceMetrics: Map[String, SQLMetric] = Map.empty
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we add this method to the base class? It looks specific to the StateStoreWriter operartor.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're right, it looks like that part wasn't needed. Reduced the scope, thanks!


/**
* Resets all the metrics.
*/
def resetMetrics(): Unit = {
metrics.valuesIterator.foreach(_.reset())
instanceMetrics.valuesIterator.foreach(_.reset())
children.foreach(_.resetMetrics())
}

Expand All @@ -153,6 +159,11 @@ abstract class SparkPlan extends QueryPlan[SparkPlan] with Logging with Serializ
*/
def longMetric(name: String): SQLMetric = metrics(name)

/**
* @return The instance-specific [[SQLMetric]] for the given `name`.
*/
def longInstanceMetric(name: String): SQLMetric = instanceMetrics(name)

// TODO: Move to `DistributedPlan`
/**
* Specifies how data is partitioned across different nodes in the cluster.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,9 @@ trait StateStoreWriter
"stateMemory" -> SQLMetrics.createSizeMetric(sparkContext, "memory used by state"),
"numStateStoreInstances" -> SQLMetrics.createMetric(sparkContext,
"number of state store instances")
) ++ stateStoreCustomMetrics ++ pythonMetrics ++ stateStoreInstanceMetrics
) ++ stateStoreCustomMetrics ++ pythonMetrics

override lazy val instanceMetrics = stateStoreInstanceMetrics

val stateStoreNames: Seq[String] = Seq(StateStoreId.DEFAULT_STORE_NAME)

Expand Down Expand Up @@ -332,7 +334,7 @@ trait StateStoreWriter
case (name, metricConfig) =>
// Keep instance metrics that are updated or aren't marked to be ignored,
// as their initial value could still be important.
!metricConfig.ignoreIfUnchanged || !longMetric(name).isZero
!metricConfig.ignoreIfUnchanged || !longInstanceMetric(name).isZero
}
.groupBy {
// Group all instance metrics underneath their common metric prefix
Expand All @@ -347,8 +349,8 @@ trait StateStoreWriter
metrics
.map {
case (_, metric) =>
metric.name -> (if (longMetric(metric.name).isZero) metricConf.initValue
else longMetric(metric.name).value)
metric.name -> (if (longInstanceMetric(metric.name).isZero) metricConf.initValue
else longInstanceMetric(metric.name).value)
}
.toSeq
.sortBy(_._2)(metricConf.ordering)
Expand Down Expand Up @@ -439,7 +441,8 @@ trait StateStoreWriter
case (metric, value) =>
val metricConfig = instanceMetricConfiguration(metric.name)
// Update the metric's value based on the defined combine method
longMetric(metric.name).set(metricConfig.combine(longMetric(metric.name), value))
longInstanceMetric(metric.name)
.set(metricConfig.combine(longInstanceMetric(metric.name), value))
}
}

Expand Down