feat: add custom Lance metrics to trace read-path scan performance#460
Open
summaryzb wants to merge 1 commit intolance-format:mainfrom
Open
feat: add custom Lance metrics to trace read-path scan performance#460summaryzb wants to merge 1 commit intolance-format:mainfrom
summaryzb wants to merge 1 commit intolance-format:mainfrom
Conversation
Change-Id: I63dd17d7e8469c27a73251d7eca3ac373d279d7f
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds custom metrics to the Lance Spark read path using Spark's DataSource V2
CustomMetricAPI, enabling per-task timing and counter instrumentation that surfaces on the Spark UI Scan node. Six metrics are tracked: fragments scanned, batches read, dataset open time, scanner creation time, batch load time, and a derived total scan time.Motivation
Implement #459
before this pr
after this pr
Approach
The implementation uses Spark's
CustomMetric/CustomTaskMetricAPI, which is the standard DataSource V2 mechanism for surfacing connector-specific metrics in the Spark UI.Metric definitions (
LanceCustomMetrics): SixCustomSumMetricinner classes define the metrics. Each has a public no-arg constructor (required by Spark's reflection-based instantiation). A staticallMetrics()method returns all definitions forLanceScan.supportedCustomMetrics(). TheCustomSumMetricbase class handles aggregation across tasks automatically.Executor-side tracking (
LanceReadMetricsTracker): A thread-confined accumulator that lives inside eachPartitionReader. It collects per-phase nanosecond timings and counters via simpleadd*()methods. ThecurrentMetricsValues()method returns a snapshot array ofCustomTaskMetricinstances -- Spark calls this after eachnext()invocation. The derivedscanTimeNsmetric is computed asdatasetOpenTimeNs + scannerCreateTimeNs + batchLoadTimeNs.Instrumentation points: Timing is captured at three boundaries in the scan lifecycle:
LanceFragmentScanner.create()wrapsDataset.open()andfragment.newScan()withSystem.nanoTime()measurements, storing the durations as instance fields.LanceFragmentColumnarBatchScanner.loadNextBatch()measures eachArrowReader.loadNextBatch()call.LanceColumnarPartitionReaderreads these timings from the scanner and feeds them into itsLanceReadMetricsTracker.The same pattern is applied to
LanceCountStarPartitionReader(pushed-downCOUNT(*)) andLanceRowPartitionReader(delegates to the columnar reader). All three reader types overridecurrentMetricsValues()to report metrics to Spark.Test Coverage
allMetrics()returns exactly 6 metrics.LanceCustomMetrics.CustomSumMetric.aggregateTaskMetrics()correctly sums values (including empty array).add*()calls accumulate correctly; derivedscanTimeNsequals sum of three sub-timings.addFragmentsScanned()supports multi-fragment increments.SELECT x, yquery produces non-zero values for all six metrics, andscanTimeNs == datasetOpenTimeNs + scannerCreateTimeNs + batchLoadTimeNsafter Spark aggregation.LanceCountStarPartitionReaderpath also produces non-zero values for all metrics.