-
Notifications
You must be signed in to change notification settings - Fork 859
Adding resource monitors to MERGE and COLLECT methods #21899
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: devel
Are you sure you want to change the base?
Conversation
8cc0119
to
64c2c45
Compare
64c2c45
to
4f64c8e
Compare
4f64c8e
to
64c2c45
Compare
… double counting, add test (must format)
…ge-resource-monitor
…ge-resource-monitor
…ge-resource-monitor
…ge-resource-monitor
…ally in the supervised buffer
…ge-resource-monitor
…ge-resource-monitor
…feature/merge-resource-monitor
…ge-resource-monitor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some comments and changes, but the review is not yet 100% complete, I will do another one.
arangod/Aql/Aggregator.cpp
Outdated
@@ -32,6 +32,8 @@ | |||
#include "Transaction/Helpers.h" | |||
#include "Transaction/Methods.h" | |||
|
|||
#include "Logger/LogMacros.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#include "Logger/LogMacros.h" |
arangod/Aql/AqlValue.h
Outdated
@@ -28,6 +28,7 @@ | |||
#include "Aql/RegisterId.h" | |||
#include "Aql/RegIdFlatSet.h" | |||
#include "Basics/Endian.h" | |||
#include "Basics/ResourceUsage.h" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed here?
I would prefer to do the import in files that actually require it directly, this way we can save on recompile costs.
@@ -356,7 +360,7 @@ std::unique_ptr<ExecutionBlock> CollectNode::createBlock( | |||
std::move(groupRegisters), collectRegister, expressionRegister, | |||
_expressionVariable, std::move(aggregateTypes), | |||
std::move(inputVariables), std::move(aggregateRegisters), | |||
&_plan->getAst()->query().vpackOptions()); | |||
&_plan->getAst()->query().vpackOptions(), std::move(usageScope)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Puh, we need to make sure that destruction ordering here is correct.
We reference the usageScope in the aggregators above.
We hand over responsibility into the Infos here.
Now on destructor we need to make sure aggregator vector is always destroyed before the usageScope, otherwise we get into undefined behavior here.
I am thinking:
Instead of handing in one Global scope,
should we instead give a reference to the ResourceMonitor& and then let each struct internally build it's own local scope? The ResourceMonitor is guaranteed to outlive this class.
@@ -101,6 +101,8 @@ std::unique_ptr<ExecutionBlock> IndexCollectNode::createBlockAggregationScan( | |||
infos.groups.reserve(_groups.size()); | |||
infos.index = _index; | |||
infos.query = &engine.getQuery(); | |||
infos.usageScope = std::make_unique<ResourceUsageScope>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why unique_ptr?
We could probably get away with a ResourceUsageScope directly right?
@@ -394,10 +394,11 @@ void WindowNode::calcAggregateRegisters( | |||
} | |||
|
|||
void WindowNode::calcAggregateTypes( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Am i blind or is there no one calling this function that would have to be adjusted?
@@ -137,6 +138,7 @@ class HashedCollectExecutorInfos { | |||
|
|||
/// @brief resource manager | |||
arangodb::ResourceMonitor& _resourceMonitor; | |||
std::unique_ptr<ResourceUsageScope> _usageScope; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
puh, i am getting afraid of destruction ordering here again.
I think moving the Scope as member of the aggregator is way safer.
input.getValue(infos.getExpressionRegister()) | ||
.toVelocyPack(infos.getVPackOptions(), _builder, | ||
/*allowUnindexed*/ false); | ||
auto val = input.getValue(infos.getExpressionRegister()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this can be replaced with the Supervised Builder now
@@ -266,16 +281,27 @@ void SortedCollectExecutor::CollectGroup::writeToOutput( | |||
// set the group values | |||
if (infos.getCollectRegister().value() != RegisterId::maxRegisterId) { | |||
TRI_ASSERT(_builder.isOpenArray()); | |||
size_t before = _buffer.size(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here let us make this _buffer a SupervisedBuffer
@@ -92,7 +94,8 @@ BaseWindowExecutor::AggregatorList BaseWindowExecutor::createAggregators( | |||
// initialize aggregators | |||
for (auto const& r : infos.getAggregateTypes()) { | |||
auto& factory = Aggregator::factoryFromTypeString(r); | |||
aggregators.emplace_back(factory(infos.getVPackOptions())); | |||
aggregators.emplace_back( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, destruction ordering
…ge-resource-monitor
Scope & Purpose
Adding resource monitors (specifically ResourceUsageScope) to MERGE and COLLECT methods to throw the exception when their performance exceeds a memory usage limit.
MERGE
ResourceUsageScope
toExecutorExpressionContext
.increaseMemoryUsage()
logic tomergeParameters()
method ofObjectFunctions.cpp
.aql-memory-limit.js
AqlItemBlock
.COLLECT
Added
ResourceUsageScope
toSortedCollectExecutor
.Added
ResourceUsageScope
to one of theAggregator
s.Need to add the scope to other aggregators.
Need to add testing functions of this functionality.
💩 Bugfix
🍕 New feature
🔥 Performance improvement
🔨 Refactoring/simplification
Checklist
Related Information