-
We have about 100 engines with shared js code running cyclically in a production environment. Warmup is finished a couple of hours after startup. Problem: About 5 days after initial startup most of the engines are reentering the warmup state (compilation trace prints mostly "opt done"), which endangers production. We can't find any external trigger (same processed and patterns are running all the time). Compilation trace logs showing the same messages like at initial startup.
|
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 7 replies
-
I have two possible explanations for this behavior.
The polyglot API uses the Source reference to determine the lifetime of the code cache if no context is alive that uses that code. For example[1]: try (Engine engine = Engine.create()) {
Source source = Source.create("js", "21 + 21");
try (Context context = Context.newBuilder()
.engine(engine)
.build()) {
int v = context.eval(source).asInt();
assert v == 42;
}
// code cache cannot get collected here since source is on stack
try (Context context = Context.newBuilder()
.engine(engine)
.build()) {
int v = context.eval(source).asInt();
assert v == 42;
}
} Here as long as the If we slightly change that example to: try (Engine engine = Engine.create()) {
try (Context context = Context.newBuilder()
.engine(engine)
.build()) {
Source source = Source.create("js", "21 + 21");
int v = context.eval(source).asInt();
assert v == 42;
}
// code cache may get collected by the GC here
try (Context context = Context.newBuilder()
.engine(engine)
.build()) {
Source source = Source.create("js", "21 + 21");
int v = context.eval(source).asInt();
assert v == 42;
}
} Here the GC may decide to collect the code cache and ASTs between created contexts. Luckily the solution to such a problem is pretty simple. You just need to keep a strong reference to the Since you run a long-running application, the code associated with your sources probably gets collected during an idle time where no context using the code is alive.
Whether this is the case, you can find out with: (1) is very likely explaining your problem. We currently lack a diagnostic option to detect (1). But having a trace option for this would be a good idea. We will add that. Lastly, out of curiosity, why do you spawn 100 engines and not just one? |
Beta Was this translation helpful? Give feedback.
I have two possible explanations for this behavior.
The polyglot API uses the Source reference to determine the lifetime of the code cache if no context is alive that uses that code.
For example[1]: