Skip to content
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

BAAS-22402: add early exits when possible memusage #87

Merged
merged 6 commits into from
Aug 1, 2023

Conversation

nickpoindexter
Copy link

In this PR it seems like we have opportunity to exit large arrays early when we've exceeded the total mem allowed. This does not cause the interrupt in the function and will continue to rely on the poller within pass to check these values but should ease the CPU needed to calculate mem.

I think this also allows us to remove the estimate, but that path is a bit different so was not adjusted as part of this effort.

@@ -25,7 +25,11 @@ tasks:
export PATH=$ROOT_DIR/go/bin:$PATH

cd goja
go test -v ./...
go test -v ./... >> ${workdir}/goja.suite
- command: gotest.parse_files
Copy link
Author

Choose a reason for hiding this comment

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

[drive-by] to get tests under tests tab in EVG

memory_test.go Outdated Show resolved Hide resolved
memory_test.go Outdated Show resolved Hide resolved
memory_test.go Outdated Show resolved Hide resolved
fix tests after removing early exit from objects

fix more tests
Copy link

@Gabri3l Gabri3l left a comment

Choose a reason for hiding this comment

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

Thank you for these changes, were you able to see what impact they end up having?

array_test.go Outdated Show resolved Hide resolved
array_test.go Show resolved Hide resolved
array_sparse_test.go Outdated Show resolved Hide resolved
builtin_map_test.go Outdated Show resolved Hide resolved
compiler_test.go Outdated Show resolved Hide resolved
memory_test.go Outdated Show resolved Hide resolved
Copy link

@Gabri3l Gabri3l left a comment

Choose a reason for hiding this comment

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

nice!

Copy link

@tcannon91 tcannon91 left a comment

Choose a reason for hiding this comment

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

LGTM

mem_context.go Outdated Show resolved Hide resolved
Co-authored-by: Taylor Cannon <[email protected]>
mem_context.go Outdated
// MemUsageLimitExceeded ensures a limit function is defined and checks against the limit. If limit is breached
// it will return true, if the limit check is undefined it will return an error
func (m *MemUsageContext) MemUsageLimitExceeded(memUsage uint64) (bool, error) {
if m.MemUsageExceedsLimit == nil {

Choose a reason for hiding this comment

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

do we need to perform this check in tight loops? I would rather not if possible. Wouldn't we be able to check this in advance?

Copy link
Author

Choose a reason for hiding this comment

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

The var is an exported pointer structure so anyone could change it at any point. I think if we determined that the only ever definition of this function would be:

if memUsage > m.MemLimit {
return err
}

then we can remove these checks and clean things up a bit. Happy to do so if everyone is on board.

Copy link
Author

Choose a reason for hiding this comment

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

Chatted with @Gabri3l offline and he was fine with moving forward this approach as long as the limit field was not exported. It has been refactored.

remove limitfunction error
Copy link

@Gabri3l Gabri3l left a comment

Choose a reason for hiding this comment

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

Looking good 💪🏼

Copy link

@arahmanan arahmanan left a comment

Choose a reason for hiding this comment

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

🥳

@nickpoindexter nickpoindexter merged commit 2486364 into mongodb-forks:realm Aug 1, 2023
0 of 4 checks passed
@nickpoindexter nickpoindexter deleted the BAAS-22402 branch August 1, 2023 00:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants