Description
Hello.
I'm creating service like FaaS for JS scripts with limited API and found memory leak issues on prototyping different approaches while using Graal Polyglot.
Approaches that I've trying to implement:
- Pool of Context with single Engine. Source evaluated once in Context. Any JS code wrapped to unique namespace, that can be accessible as member of Context and executed.
Any other invocations just execute existing member and nothing more - Single Engine, Sources are cached. On any new invocation we just getting existing Source and evaluate them in new Context that created for every invocation.
After that getting function member from Context and execute (as in previous approach) - New Engine and New Context for every invocation, Sources are built once.
Only third approach have no memory leaks, because GC will grab them out from heap.
In first and second approaches are memory leaks. Looks like Engine have issues on executing some code and generates much data for each invocation, that will be never removed from Engine.
I have a prototype that reproduces the first approach:
https://github.com/mdsina/graaljs-executor-web-service
Also I wrote a load tests that simulate real-world invocations of JS code:
https://github.com/mdsina/graaljs-executor-web-service-load-tests/tree/master
Service was executed with VM options:
-Xmx2g -XX:+UseG1GC
Looks like links to ContextJS never be removed.