-
Notifications
You must be signed in to change notification settings - Fork 91
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
Setting max mem size for v8 instance? #18
Comments
I would love to do something, but we need to do a bunch of research here... first place I would like us to look: Is all the memory V8 is allocating going through https://github.com/discourse/mini_racer/blob/master/ext/mini_racer_extension/mini_racer_extension.cc#L12-L20 ? If it is can we easily add:
If the block allocater does then we can probably simply use http://bespin.cz/~ondras/html/classv8_1_1HeapStatistics.html which is returned via http://bespin.cz/~ondras/html/classv8_1_1Isolate.html#add32e78544edaf8946ed9b328167e5e4 We need to do this first, to implement caps we would have to use: http://bespin.cz/~ondras/html/classv8_1_1Isolate.html#acff413b8633aa13f1308697c0ce8c5fa but that would be fairly tricky, what should we do when you reach the limit? burn the isolate? leave it around and shift it into error state? I would also like us to add a way dispose of V8 memory if you want to do it by hand:
|
That all looks good! For my specific purposes, (since I'm not in-control of the js code that's being executed by the context) I need to be able to completely halt execution when the memory cap is hit. So preferably, it would be the memory equivalent of the timeout that's passed in on context create. Guaranteed my players are writing code that looks like this:
I figure the best bet for implementing something like that based on what you linked above, is to use the allocation callback and call stop when the mem hits the threshold. Probably using some c-side alloc size tracking, so we're not constantly re-querying. I do like the context block-form and the dealloc stuff- luckily, memory is holding real well between runs :D |
I'll put something simple together for just the max-heap setting of this. Hopefully we can put something together that has reasonable performance. |
@seanmakesgames : FWIW, MiniRacer now supports run time flags, so you could try doing something like this:
It seems to work, albeit there still is some work to be done to turn that into a friendly Ruby exception:
Seems like we'd want to register a error handler with V8, see https://github.com/v8/v8/blob/5.1.281.59/src/api.cc#L242-L244 |
Seems pretty straightforward to do => https://v8docs.nodesource.com/io.js-1.2/d5/dda/classv8_1_1_isolate.html#af8b475bb23fabe5b7708bbc7c572276f |
Awesome! Thanks Jean @wk8 |
put this into a quick test case, but not sure where to hook up the callback or how to forward the exception safely. Also not sure how to set the space size flag just for the one test case. (as it's a platform option) |
Got back into investigation of this and unfortunately it looks like there's no way to recover from the oom exceptions through the artificially set memory constraints :/ The callback works, but there's no way to signal 'this is ok' -- this used to work, but is now removed: As far as I can tell, these platform limits are not in sync with failstate handling. My plan now is to register an alloc tracker/counter and call terminate like we do for timeouts. |
Proposal for implementation: Isolate and context are left in the same state as a timeout. Non-fatal failure & further evals will be available. I do think there might be a perf hit from the alloc callback, but the code impact will be only be applicable to those that provide the max_mem option. |
Ok made some progress on this, but hitting up some roadblocks in a few places:
In progress-PR here: Any support is much appreciated. Trying to full-launch in the next month. 🚢 |
by the way, these are a segfault when they happen. There is no way to recover from the v8 built-in OOM failures, even when an artificial max-memory amount is set with the platform variables. |
Looks like the new way to handle this is w/ an interruptrequest & checking the heapsize I'm worried about this though: |
Getting a bit more time on this, and looks like there's a tasty OOM handler in v8 5.4 - |
Sure we should always be on latest stable
…On Tue, 7 Mar 2017 at 1:58 pm, seanmakesgames ***@***.***> wrote:
Getting a bit more time on this, and looks like there's a tasty OOM
handler in v8 5.4 -
Should I open a separate issue for upgrade to 5.4? @SamSaffron
<https://github.com/SamSaffron>
Hope all is well!
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#18 (comment)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAAUXdiOlBrVr92JgU2pwnLOkeGkfS6Pks5rjai_gaJpZM4IuLyz>
.
|
Release 0.2.5.0.1.beta1
Is there a way currently to set the heap size to a specific amount? Maybe from a config, or on the context object? Found this online for v8:
--max-old-space-size
The text was updated successfully, but these errors were encountered: