From 61226309980ae1ab488930b2c73024c3ca7eb6a6 Mon Sep 17 00:00:00 2001 From: Masha Basmanova Date: Tue, 12 Dec 2023 12:45:03 -0800 Subject: [PATCH] Fix OutputBuffer::isOverutilized (#7985) Summary: OutputBuffer::isOverutilized() should return true if it is half-full. It used to return true only when full preventing effective scaling of consumers. The buffer maintains is-full state only for a short duration of time. Since producers are blocked, one fetch from one consumer resets the state to not-null. Thus the coordinator that's monitoring output buffers may never see buffer getting over-utilized and mitigate by scaling the number of consumers. This caused some queries to be very slow as they used only 4 threads for TableWrite. Pull Request resolved: https://github.com/facebookincubator/velox/pull/7985 Reviewed By: Yuhta Differential Revision: D52073744 Pulled By: mbasmanova fbshipit-source-id: 246e065d885ce52601acd4cdcba5e708c5628da5 --- velox/exec/OutputBuffer.cpp | 2 +- velox/exec/OutputBuffer.h | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/velox/exec/OutputBuffer.cpp b/velox/exec/OutputBuffer.cpp index a14fd6313031..7b9bdec21e8a 100644 --- a/velox/exec/OutputBuffer.cpp +++ b/velox/exec/OutputBuffer.cpp @@ -637,7 +637,7 @@ double OutputBuffer::getUtilization() const { } bool OutputBuffer::isOverutilized() const { - return (totalSize_ > maxSize_) && !atEnd_; + return (totalSize_ > (0.5 * maxSize_)) && !atEnd_; } } // namespace facebook::velox::exec diff --git a/velox/exec/OutputBuffer.h b/velox/exec/OutputBuffer.h index c7a1eaedeaed..0b6cb5b66198 100644 --- a/velox/exec/OutputBuffer.h +++ b/velox/exec/OutputBuffer.h @@ -187,8 +187,9 @@ class OutputBuffer { // Gets the memory utilization ratio in this output buffer. double getUtilization() const; - // Indicates if this output buffer is over-utilized and thus blocks its - // producers. + // Indicates if this output buffer is over-utilized, i.e. at least half full, + // and will start blocking producers soon. This is used to dynamically scale + // the number of consumers, for example, increase number of TableWriter tasks. bool isOverutilized() const; private: