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-34801: add forced mem checks on new arrays and obj props #127

Merged
merged 12 commits into from
Dec 9, 2024

Conversation

Gabri3l
Copy link

@Gabri3l Gabri3l commented Nov 27, 2024

This PR attempts to add a forced mem check on paths that have been historically causing OOMs. The poller is unable to catch these OOMs so we attempt to force a mem check ad-hoc where we usually risk very high memory usage.

For what it's worth I tried a small benchmark with this change

BenchmarkPutStr-10                	99246348	        12.62 ns/op	       0 B/op	       0 allocs/op
BenchmarkPutStrWithMemCheck-10    	93969940	        12.82 ns/op	       0 B/op	       0 allocs/op

@Gabri3l Gabri3l marked this pull request as draft November 27, 2024 18:50
builtin_array.go Outdated
panic(err)
}
if memCtx.MemUsageLimitExceeded(memUsage) {
panic("memory limit exceeded")

Choose a reason for hiding this comment

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

[q] would the panic know the func name when it happens? We can use the runtime's vm's func name if the stack trace doesn't help us here. I guess we would flag certain apps, so in theory we know which functions are causing the issue. This may help if there are multiple triggers and functions for flagged apps or if we have multiple apps flagged running at the same time.

Copy link
Author

Choose a reason for hiding this comment

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

I need to see how I can bubble this up to baas, I still haven't ironed out how this comes through in baas so that we can parse it and potentially log more details.

Choose a reason for hiding this comment

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

yea, i agree reporting to baas could be a problem, e.g. how do we report if recursive array objects, where another array embedded into an array, do we only report max memUsage?

Copy link
Author

Choose a reason for hiding this comment

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

Will delegate to the baas PR to figure this out. But in this case the panic will stop execution and for recursive data structures the poller eventually will catch it. Either way I'll have to test this out and report back. I'll leave this thread open until I have done more tests locally.

Copy link
Author

Choose a reason for hiding this comment

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

I was able to think about this a little more, we technically use the regular poller to assess mem usage of a function and bill accordingly and I think we should continue to do so. This is just to allow us to save our pods from OOMing with scenario we can't catch in time.

object.go Outdated
panic(err)
}
if memCtx.MemUsageLimitExceeded(memUsage) {
panic("memory limit exceeded")

Choose a reason for hiding this comment

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

same q here about panicking with the func name.

Copy link
Author

Choose a reason for hiding this comment

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

We don't have access to the function name here where we panic. I could try and see if we can pass it down from baas otherwise it might be cleaner to pick this up from baas when we catch this panic. Will leave this open until I have a definitive answer.

Copy link
Author

Choose a reason for hiding this comment

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

In goja I def don't have access to the function name, I think we could potentially figure out the currently executing function within the App Services function but I'd rather investigate that later.

mem_context.go Show resolved Hide resolved
@Gabri3l Gabri3l marked this pull request as ready for review December 2, 2024 21:30
Copy link

@jwongmongodb jwongmongodb 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 Show resolved Hide resolved
mem_context.go Outdated Show resolved Hide resolved
object.go Outdated Show resolved Hide resolved
@Gabri3l Gabri3l requested a review from jwongmongodb December 4, 2024 22:02
@Gabri3l
Copy link
Author

Gabri3l commented Dec 4, 2024

This https://github.com/10gen/baas/pull/15863 is what the corresponding PR looks like.

Copy link

@jwongmongodb jwongmongodb left a comment

Choose a reason for hiding this comment

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

lgtm

@@ -548,6 +548,17 @@ func (o *baseObject) setOwnStr(name unistring.String, val Value, throw bool) boo
o.val.runtime.typeErrorResult(throw, "Cannot add property %s, object is not extensible", name)

Choose a reason for hiding this comment

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

[qq] I see that you added a nil check below for o.val, do we need it here as well?

Copy link
Author

Choose a reason for hiding this comment

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

I was being overly cautious, I won't make changes here since this is from original goja. Thanks for checking though!

@Gabri3l Gabri3l merged commit 8b50f5b into mongodb-forks:realm Dec 9, 2024
2 of 6 checks passed
@Gabri3l Gabri3l deleted the BAAS-34801 branch December 9, 2024 15:13
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.

3 participants