Skip to content

Conversation

knakatasf
Copy link

Scope & Purpose

Adding memory monitoring mechanism to COLLECT method.

  1. Each CollectExecutor takes ResourceMonitor and use supervised builder. For AqlValue, it uses ResourceUsageScope to count its memory.
  2. Each Aggregator takes ResourceMonitor and use supervised builder. For AqlValue, it uses ResourceUsageScope to count its memory.
  • 💩 Bugfix
  • 🍕 New feature
  • 🔥 Performance improvement
  • 🔨 Refactoring/simplification

Checklist

  • Tests
    • Regression tests
    • C++ Unit tests
    • integration tests
    • resilience tests
  • 📖 CHANGELOG entry made
  • 📚 documentation written (release notes, API changes, ...)
  • Backports
    • Backport for 3.12.0: (Please link PR)
    • Backport for 3.11: (Please link PR)
    • Backport for 3.10: (Please link PR)

Related Information

(Please reference tickets / specification / other PRs etc)

  • Docs PR:
  • Enterprise PR:
  • GitHub issue / Jira ticket:
  • Design document:

knakatasf and others added 30 commits August 7, 2025 02:12
knakatasf and others added 27 commits August 22, 2025 19:17
…arangodb into feature/merge-resource-monitor
…s argument to helper function, format, fix wrong method call in header
…structor because of usage scope's default constructor demanding a monitor, fix order in CMakeLists
@cla-bot cla-bot bot added the cla-signed label Aug 29, 2025
Copy link
Member

@mchacki mchacki left a comment

Choose a reason for hiding this comment

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

This PR is on a very good way I like it !!

I have left some feedback comments.

Comment on lines 79 to 82

// static std::unique_ptr<Aggregator> fromTypeString(velocypack::Options
// const*,
// std::string_view type);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// static std::unique_ptr<Aggregator> fromTypeString(velocypack::Options
// const*,
// std::string_view type);

just remove this, we can always go back with git history.

Copy link
Author

Choose a reason for hiding this comment

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

Deleted.

protected:
velocypack::Options const* _vpackOptions;
ResourceMonitor& _resourceMonitor;
std::unique_ptr<ResourceUsageScope> _usageScope;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
std::unique_ptr<ResourceUsageScope> _usageScope;
ResourceUsageScope _usageScope;

This should be enough right?

We will perform counters to usage scope often, so having the pointer indirection will have some performance impact.

Copy link
Author

Choose a reason for hiding this comment

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

Got it. Changed to an object by value.

@@ -28,8 +28,10 @@
#include "Aql/RegisterId.h"
#include "Aql/RegIdFlatSet.h"
#include "Basics/Endian.h"
#include "Basics/ResourceUsage.h"
Copy link
Member

Choose a reason for hiding this comment

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

Please include those in the files where it actually is needed.

AqlValue.h is Imported into many places so we would need to recompile a lot if any of those imports change.

Copy link
Author

Choose a reason for hiding this comment

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

Deleted. AqlValue.h doesn't use this header file.

#include "IResearch/Misc.h"

#include <velocypack/Builder.h>
Copy link
Member

Choose a reason for hiding this comment

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

Please include those in the files where it actually is needed.

AqlValue.h is Imported into many places so we would need to recompile a lot if any of those imports change.

@@ -37,6 +37,7 @@
#include "Aql/WalkerWorker.h"
#include "Transaction/Methods.h"

Copy link
Member

Choose a reason for hiding this comment

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

This file looks good 👍

@@ -205,7 +212,9 @@ struct AggregatorMax final : public Aggregator {
void reduce(AqlValue const& cmpValue) override {
if (value.isEmpty() ||
AqlValue::Compare(_vpackOptions, value, cmpValue, true) < 0) {
resourceUsageScope().decrease(value.memoryUsage());
Copy link
Member

Choose a reason for hiding this comment

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

See above.

: Aggregator(opts, monitor),
allocator(1024),
seen(_vpackOptions),
builder(std::make_shared<velocypack::SupervisedBuffer>(monitor)) {}
Copy link
Member

Choose a reason for hiding this comment

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

Looks like the changes here get rather straight forward.

@@ -776,6 +809,7 @@ struct AggregatorCountDistinct : public Aggregator {
return;
}

resourceUsageScope().increase(s.byteSize());
Copy link
Member

Choose a reason for hiding this comment

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

Very good 👍

please make rue the resourceUsageScope is reverted when seen is cleared above.

Copy link
Author

Choose a reason for hiding this comment

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

Yes, I added revert() here:
image

@@ -842,6 +887,7 @@ struct AggregatorCountDistinctStep2 final : public AggregatorCountDistinct {
continue;
}

resourceUsageScope().increase(it.byteSize());
Copy link
Member

Choose a reason for hiding this comment

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

Again reset on clear()

Copy link
Author

Choose a reason for hiding this comment

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

This Aggregator uses AggregatorCountDistinct's reset(), which is final.

@@ -988,8 +1043,8 @@ struct AggregatorList : public Aggregator {
// if preceding is `unbounded`. But closing the array here breaks the
// velocypack slice.
auto builderCopy = builder;
builderCopy.close();
return AqlValue(std::move(*builderCopy.steal()));
AqlValue a{std::move(*builderCopy.steal())};
Copy link
Member

Choose a reason for hiding this comment

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

Why does the builderCopy not be closed anymore?

Copy link
Author

Choose a reason for hiding this comment

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

Reverted to the original code where builderCopy is closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants