Skip to content

[GLUTEN-10892][VL] Use veloxPreferredBatchBytes to control the max size of memory of batches combined#11140

Merged
jinchengchenghh merged 9 commits into
apache:mainfrom
jiangjiangtian:config_resize
Dec 2, 2025
Merged

[GLUTEN-10892][VL] Use veloxPreferredBatchBytes to control the max size of memory of batches combined#11140
jinchengchenghh merged 9 commits into
apache:mainfrom
jiangjiangtian:config_resize

Conversation

@jiangjiangtian

@jiangjiangtian jiangjiangtian commented Nov 21, 2025

Copy link
Copy Markdown
Contributor

What changes are proposed in this pull request?

Now the operator VeloxBatchResizer can use as many memory as possible, which can cause OOM. So this PR use the existing config spark.gluten.sql.columnar.backend.velox.preferredBatchBytes to control it.
Closes #10892

How was this patch tested?

Inner ETL jobs.

@wForget

wForget commented Nov 21, 2025

Copy link
Copy Markdown
Member

Could you add a new configuration for memoryThreshold and allow disabling it? I'm concerned that estimating batch size might cause performance overhead.

@jiangjiangtian

Copy link
Copy Markdown
Contributor Author

Could you add a new configuration for memoryThreshold and allow disabling it? I'm concerned that estimating batch size might cause performance overhead.

Sure. Thanks for your advice.
Actually, I have tested 300 jobs and the overall execution time decrease by about 1.1%.

@github-actions github-actions Bot added the DOCS label Nov 24, 2025
@jiangjiangtian
jiangjiangtian force-pushed the config_resize branch 3 times, most recently from 98e47b9 to 0e1128b Compare November 27, 2025 09:05
@@ -680,6 +682,15 @@ object VeloxConfig extends ConfigRegistry {
.bytesConf(ByteUnit.BYTE)
.createWithDefaultString("10MB")

val ENABLE_LIMIT_BATCH_RESIZER = {

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.

This can be a default behavior, please remove this config, all the operator should respect preferredBatchBytes

@@ -60,7 +60,7 @@ Arguments: false

(7) VeloxResizeBatches
Input [18]: [hash_partition_key#X, l_returnflag#X, l_linestatus#X, sum#X, isEmpty#X, sum#X, isEmpty#X, sum#X, isEmpty#X, sum#X, isEmpty#X, sum#X, count#X, sum#X, count#X, sum#X, count#X, count#X]
Arguments: X, X
Arguments: X, X, 10485760

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.

Please change it to X, we don't need to update it if we change the default value in the future

plan.transformUp {
case shuffle: ColumnarShuffleExchangeExec
if resizeBatchesShuffleInputEnabled &&
shuffle.shuffleWriterType.requiresResizingShuffleInput =>
val appendBatches =
VeloxResizeBatchesExec(shuffle.child, range.min, range.max)
VeloxResizeBatchesExec(shuffle.child, range.min, range.max, memoryThreshold)

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.

Please use the original config name preferredBatchBytes instead of a new name

Comment thread cpp/velox/utils/VeloxBatchResizer.cc Outdated
@@ -78,22 +80,43 @@ std::shared_ptr<ColumnarBatch> VeloxBatchResizer::next() {
if (cb->numRows() < minOutputBatchSize_) {

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.

Please use cb->numBytes() to estimate the batch size, and update the numBytes(), get the numBytes does not need to flat the vector, just load the vector

Comment thread cpp/velox/utils/VeloxBatchResizer.cc Outdated
@@ -78,22 +80,41 @@ std::shared_ptr<ColumnarBatch> VeloxBatchResizer::next() {
if (cb->numRows() < minOutputBatchSize_) {
auto vb = VeloxColumnarBatch::from(pool_, cb);
auto rv = vb->getRowVector();
auto vector = std::static_pointer_cast<facebook::velox::BaseVector>(rv);

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.

I don't see the vector usage

Comment thread cpp/velox/utils/VeloxBatchResizer.cc Outdated
auto nextRv = nextVb->getRowVector();
if (buffer->size() + nextRv->size() > maxOutputBatchSize_) {
// Call reset manully to potentially release memory
vector.reset();

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.

L114 is enough, you reuse the variables in following for loop or release in the end

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.

And also remove following rv batch.reset

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I remove the four lines of code here.

Comment thread cpp/velox/utils/VeloxBatchResizer.cc Outdated
@@ -78,22 +80,41 @@ std::shared_ptr<ColumnarBatch> VeloxBatchResizer::next() {
if (cb->numRows() < minOutputBatchSize_) {
auto vb = VeloxColumnarBatch::from(pool_, cb);
auto rv = vb->getRowVector();
auto vector = std::static_pointer_cast<facebook::velox::BaseVector>(rv);
uint64_t numBytes = cb->numBytes();

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I get it. Thanks!

@@ -73,6 +73,7 @@ abstract class VeloxTPCHSuite extends VeloxTPCHTableSupport {
// for unexpected blank
.replaceAll("Scan parquet ", "Scan parquet")
// Spark QueryStageExec will take it's id as argument, replace it with X
.replaceAll("Arguments: [0-9]+, [0-9]+, [0-9]+", "Arguments: X, X")

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.

X, X, X

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks

Comment thread cpp/velox/utils/VeloxBatchResizer.cc Outdated
auto nextRv = nextVb->getRowVector();
if (buffer->size() + nextRv->size() > maxOutputBatchSize_) {
// Call reset manully to potentially release memory
vector.reset();

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.

And also remove following rv batch.reset

Comment thread cpp/velox/utils/VeloxBatchResizer.cc Outdated
@@ -78,22 +80,34 @@ std::shared_ptr<ColumnarBatch> VeloxBatchResizer::next() {
if (cb->numRows() < minOutputBatchSize_) {
auto vb = VeloxColumnarBatch::from(pool_, cb);
auto rv = vb->getRowVector();
uint64_t numBytes = cb->numBytes();

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.

Move the check with L80 if (cb->numRows() < minOutputBatchSize_ && numBytes <= preferredBatchBytes_)

@jiangjiangtian jiangjiangtian Dec 2, 2025

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Done. Thanks

@jinchengchenghh

Copy link
Copy Markdown
Contributor

Thanks!

@jinchengchenghh
jinchengchenghh merged commit 7ac0217 into apache:main Dec 2, 2025
150 of 152 checks passed
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.

[VL] VeloxBatchResizer may cause OOM when there exists type of variable length

3 participants