Skip to content

[VL] Add hash table memory usage metric when enabling spark.gluten.velox.buildHashTableOncePerExecutor.enabled#12528

Open
JkSelf wants to merge 1 commit into
apache:mainfrom
JkSelf:bhj-hashtable-usage
Open

[VL] Add hash table memory usage metric when enabling spark.gluten.velox.buildHashTableOncePerExecutor.enabled#12528
JkSelf wants to merge 1 commit into
apache:mainfrom
JkSelf:bhj-hashtable-usage

Conversation

@JkSelf

@JkSelf JkSelf commented Jul 16, 2026

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Add hash table memory usage metric when enabling spark.gluten.velox.buildHashTableOncePerExecutor.enabled.

image

How was this patch tested?

local verified

Was this patch authored or co-authored using generative AI tooling?

Copilot AI review requested due to automatic review settings July 16, 2026 03:34
@github-actions github-actions Bot added the VELOX label Jul 16, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Adds a new Spark SQL metric to report retained hash table memory usage for Velox broadcast hash joins when the “build hash table once per executor” path is used, wiring the value from native Velox hash table allocation tracking through JNI into Spark metrics.

Changes:

  • Track hash table retained bytes in native (HashTableBuilder) and expose it via a new JNI/Java API (HashJoinBuilder.getHashTableMemoryUsage).
  • Populate the memory usage value during hash table build (including parallel-build subtables) and report it into a new Spark SizeMetric (hashTableMemorySize).
  • Thread the new metric through broadcast hash join context/plumbing so it’s recorded when building the executor-side cached hash table.

Reviewed changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
cpp/velox/operators/hashjoin/HashTableBuilder.h Adds storage/accessors for a cached hash table memory usage value.
cpp/velox/jni/VeloxJniWrapper.cc Captures allocated bytes during native build and adds a JNI entrypoint to query the metric.
cpp/velox/jni/JniHashTable.h Declares hashTableMemoryUsage(...) native helper.
cpp/velox/jni/JniHashTable.cc Implements hashTableMemoryUsage(...) accessor (note: needs fallback for deserialized handles).
backends-velox/src/main/scala/org/apache/gluten/execution/VeloxBroadcastBuildSideCache.scala Updates the new SQL metric when building a cached broadcast hash table.
backends-velox/src/main/scala/org/apache/gluten/execution/HashJoinExecTransformer.scala Threads the new metric through BroadcastHashJoinContext.
backends-velox/src/main/scala/org/apache/gluten/backendsapi/velox/VeloxMetricsApi.scala Registers hashTableMemorySize as a new Spark size metric.
backends-velox/src/main/java/org/apache/gluten/vectorized/HashJoinBuilder.java Adds the new native method declaration for querying hash table memory usage.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +183 to +186
int64_t hashTableMemoryUsage(std::shared_ptr<HashTableBuilder> builder) {
VELOX_CHECK_NOT_NULL(builder, "Hash table builder cannot be null");
return builder->hashTableMemoryUsage();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants