关注 spark技术分享,
撸spark源码 玩spark最佳实践

ProgressReporter Contract

ProgressReporter Contract

ProgressReporter is the contract of stream execution progress reporters that continually report statistics about the amount of data processed and the latency of a streaming query.

Note
StreamExecution is the one and only known direct extension of the ProgressReporter Contract in Spark Structured Streaming.
Table 1. ProgressReporter Contract
Method Description

currentBatchId

Id of the current batch

id

UUID of…​FIXME

lastExecution

QueryExecution of the streaming query

logicalPlan

The logical query plan of the streaming query

Used when ProgressReporter is requested for the following:

name

newData

Streaming sources with the new data as a DataFrame.

Used when:

offsetSeqMetadata

postEvent

runId

sink

sources

sparkSession

triggerClock

The clock to use to track the time

Table 2. ProgressReporter’s Internal Properties (e.g. Registries, Counters and Flags)
Name Description

currentDurationsMs

scala.collection.mutable.HashMap of action names (aka triggerDetailKey) and their cumulative times (in milliseconds).

The action names can be as follows:

  • addBatch

  • getBatch (when StreamExecution runs a streaming batch)

  • getOffset

  • queryPlanning

  • triggerExecution

  • walCommit when writing offsets to log

Starts empty when ProgressReporter sets the state for a new batch with new entries added or updated when reporting execution time (of an action).

Tip

You can see the current value of currentDurationsMs in progress reports under durationMs.

currentStatus

StreamingQueryStatus to track the status of a streaming query.

Available using status method.

currentTriggerEndTimestamp

Timestamp of when the current batch/trigger has ended

currentTriggerStartTimestamp

Timestamp of when the current batch/trigger has started

noDataProgressEventInterval

FIXME

lastNoDataProgressEventTime

FIXME

lastTriggerStartTimestamp

Timestamp of when the last batch/trigger started

progressBuffer

scala.collection.mutable.Queue of StreamingQueryProgress

Elements are added and removed when ProgressReporter updates progress.

Used when ProgressReporter does lastProgress or recentProgress.

SourceProgress

Caution
FIXME

SinkProgress

Caution
FIXME

status Method

status gives the current StreamingQueryStatus.

Note
status is used when StreamingQueryWrapper is requested for the current status of a streaming query (that is part of StreamingQuery Contract).

Reporting Streaming Query Progress — updateProgress Internal Method

updateProgress records the input newProgress and posts a QueryProgressEvent event.

ProgressReporter updateProgress.png
Figure 1. ProgressReporter’s Reporting Query Progress

updateProgress adds the input newProgress to progressBuffer.

updateProgress removes elements from progressBuffer if their number is or exceeds the value of spark.sql.streaming.numRecentProgressUpdates property.

updateProgress posts a QueryProgressEvent (with the input newProgress).

updateProgress prints out the following INFO message to the logs:

Note
updateProgress synchronizes concurrent access to progressBuffer.
Note
updateProgress is used exclusively when ProgressReporter finishes a trigger.

Setting State For New Trigger — startTrigger Method

When called, startTrigger prints out the following DEBUG message to the logs:

startTrigger sets currentTriggerStartTimestamp using triggerClock.

startTrigger enables isTriggerActive flag of StreamingQueryStatus.

startTrigger clears currentDurationsMs.

Note
startTrigger is used exclusively when StreamExecution starts running batches (as part of TriggerExecutor executing a batch runner).

Finishing Trigger (Updating Progress and Marking Current Status As Trigger Inactive) — finishTrigger Method

Internally, finishTrigger sets currentTriggerEndTimestamp to the current time (using triggerClock).

finishTrigger extractExecutionStats.

finishTrigger calculates the processing time (in seconds) as the difference between the end and start timestamps.

finishTrigger calculates the input time (in seconds) as the difference between the start time of the current and last triggers.

ProgressReporter finishTrigger timestamps.png
Figure 2. ProgressReporter’s finishTrigger and Timestamps

finishTrigger prints out the following DEBUG message to the logs:

finishTrigger creates a SourceProgress (aka source statistics) for every source used.

finishTrigger creates a SinkProgress (aka sink statistics) for the sink.

finishTrigger creates a StreamingQueryProgress.

If there was any data (using the input hasNewData flag), finishTrigger resets lastNoDataProgressEventTime (i.e. becomes the minimum possible time) and updates query progress.

Otherwise, when no data was available (using the input hasNewData flag), finishTrigger updates query progress only when lastNoDataProgressEventTime passed.

In the end, finishTrigger disables isTriggerActive flag of StreamingQueryStatus (i.e. sets it to false).

Note
finishTrigger is used exclusively when MicroBatchExecution is requested to run the activated streaming query.

Tracking and Recording Execution Time — reportTimeTaken Method

reportTimeTaken measures the time to execute body and records it in currentDurationsMs.

In the end, reportTimeTaken prints out the following DEBUG message to the logs and returns the result of executing body.

Note

reportTimeTaken is used when StreamExecution wants to record the time taken for (as triggerDetailKey in the DEBUG message above):

  • addBatch

  • getBatch

  • getOffset

  • queryPlanning

  • triggerExecution

  • walCommit when writing offsets to log

updateStatusMessage Method

updateStatusMessage updates message in StreamingQueryStatus internal registry.

extractSourceToNumInputRows Internal Method

extractSourceToNumInputRows…​FIXME

Note
extractSourceToNumInputRows is used exclusively when ProgressReporter is requested to extractExecutionStats.

Creating Execution Statistics — extractExecutionStats Internal Method

extractExecutionStats…​FIXME

Note
extractExecutionStats is used exclusively when ProgressReporter is requested to finishTrigger.

extractStateOperatorMetrics Internal Method

extractStateOperatorMetrics…​FIXME

Note
extractStateOperatorMetrics is used exclusively when ProgressReporter is requested to extractExecutionStats.
赞(0) 打赏
未经允许不得转载:spark技术分享 » ProgressReporter Contract
分享到: 更多 (0)

关注公众号:spark技术分享

联系我们联系我们

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

微信扫一扫打赏