Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refine auto spill for fine grained executor (#8045)
ref #7738
- Loading branch information
1 parent
2ae9bc0
commit 569b567
Showing
14 changed files
with
258 additions
and
25 deletions.
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <Core/FineGrainedOperatorSpillContext.h> | ||
|
||
namespace DB | ||
{ | ||
bool FineGrainedOperatorSpillContext::supportFurtherSpill() const | ||
{ | ||
for (const auto & operator_spill_context : operator_spill_contexts) | ||
{ | ||
if (operator_spill_context->supportFurtherSpill()) | ||
return true; | ||
} | ||
return false; | ||
} | ||
|
||
void FineGrainedOperatorSpillContext::addOperatorSpillContext(const OperatorSpillContextPtr & operator_spill_context) | ||
{ | ||
/// fine grained operator spill context only used in auto spill | ||
if likely (operator_spill_context->supportSpill() && operator_spill_context->supportAutoTriggerSpill()) | ||
{ | ||
operator_spill_contexts.push_back(operator_spill_context); | ||
operator_spill_context->setAutoSpillMode(); | ||
} | ||
} | ||
|
||
Int64 FineGrainedOperatorSpillContext::getTotalRevocableMemoryImpl() | ||
{ | ||
Int64 ret = 0; | ||
for (auto & operator_spill_context : operator_spill_contexts) | ||
ret += operator_spill_context->getTotalRevocableMemory(); | ||
return ret; | ||
} | ||
|
||
Int64 FineGrainedOperatorSpillContext::triggerSpillImpl(Int64 expected_released_memories) | ||
{ | ||
Int64 original_expected_released_memories = expected_released_memories; | ||
for (auto & operator_spill_context : operator_spill_contexts) | ||
{ | ||
if (expected_released_memories <= 0) | ||
operator_spill_context->triggerSpill(original_expected_released_memories); | ||
else | ||
expected_released_memories = operator_spill_context->triggerSpill(expected_released_memories); | ||
} | ||
return expected_released_memories; | ||
} | ||
} // namespace DB |
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// Copyright 2023 PingCAP, Inc. | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#pragma once | ||
|
||
#include <Core/OperatorSpillContext.h> | ||
|
||
namespace DB | ||
{ | ||
/// FineGrainedOperatorSpillContext is a wrap for all the operator spill contexts that belongs to a same executor | ||
/// with fine grained shuffle enable. When fine grained shuffle is enabled, executors like sort and aggregation | ||
/// will have n independent operators in TiFlash side, each of them have their own operator spill context. However | ||
/// these n operators are not really independent: they share the same source operator(exchange receiver), if any one | ||
/// of the operator stop consuming data from exchange receiver(for example, begin spill data), all the others will | ||
/// be stuck because the exchange receiver has a bounded queue for all the operators, any one of the operator stop | ||
/// consuming will make the queue full, and no other data can be pushed to exchange receiver. If all the n operator | ||
/// is triggered to spill serially, it will affects the overall performance seriously. | ||
/// FineGrainedOperatorSpillContext is used to make sure that all the operators belongs to the same executor | ||
/// will be triggered to spill almost at the same time | ||
class FineGrainedOperatorSpillContext final : public OperatorSpillContext | ||
{ | ||
private: | ||
std::vector<OperatorSpillContextPtr> operator_spill_contexts; | ||
|
||
protected: | ||
Int64 getTotalRevocableMemoryImpl() override; | ||
|
||
public: | ||
FineGrainedOperatorSpillContext(const String op_name, const LoggerPtr & log) | ||
: OperatorSpillContext(0, op_name, log) | ||
{ | ||
auto_spill_mode = true; | ||
} | ||
bool supportFurtherSpill() const override; | ||
bool supportAutoTriggerSpill() const override { return true; } | ||
Int64 triggerSpillImpl(Int64 expected_released_memories) override; | ||
void addOperatorSpillContext(const OperatorSpillContextPtr & operator_spill_context); | ||
/// only for test | ||
size_t getOperatorSpillCount() const { return operator_spill_contexts.size(); } | ||
}; | ||
} // namespace DB |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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
Oops, something went wrong.