graaljs: GraalJS memory leak in Engine

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:

  1. 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
  2. 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)
  3. 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

default

Looks like links to ContextJS never be removed.

About this issue

  • Original URL
  • State: open
  • Created 5 years ago
  • Comments: 39 (9 by maintainers)

Commits related to this issue

Most upvoted comments

Hi,

I observed similar symptoms to the ones described by @horschi. Also his solution worked in my case (btw thanks Christian!).

I prepared a reproducer project for this memory leak https://github.com/xardasos/GraalVMMemoryLeak. @wirthi could you please take a look at it? On my PC after around 23000 iterations I get OOM error (VM options: ‘-Xmx512m’).

Regards, Tomasz