How to improve nashorn memory footprint with large amount of compiled scripts?

Houtman, Roland Roland.Houtman at nl.yokogawa.com
Wed Feb 24 15:32:39 UTC 2016


Dear Devs,

We're running Nashorn on Java 1.8u45, and we're facing issues because we require considerable scripts to run side by side.

We load about 2000 different javascripts and compile them.
Before starting the scripts the used JVM heap memory is 177 MB and after compilation 468 MB.
This is an average of 145 KB/script.
-       Why is the memory consumption for a compiled script so large?
-       Are there settings which could reduce/optimize the memory footprint?

The "io" variable is an java-object stored in the memory context.
Every script is executed every 100 msec. Each script keeps its own memory context across executions.
An average script looks like this:

------------------------------------------------------------

var iPVar0 = io.input(1) == 1 ? Number(io.input(0)) : io.input(0);
var iPVar1 = Number(io.input(2));
var iPVar2 = io.input(4) == 1 ? Number(io.input(3)) : io.input(3);
var iPVar3 = Number(io.input(5));
var oPVar1_B;
var oPVar2_TP;

if(iPVar0 == "AOF"){
  io.output(0,io.input(6));
  oPVar2_TP = 0;
  oPVar1_B = 0;
}else if(iPVar1 == 9 && iPVar2 != 34){
  io.output(0,io.input(7));
  oPVar2_TP = 1;
  if(iPVar3 == 0){
    oPVar1_B = 1;
  }else{
    oPVar1_B = 0;
  }
}else if(iPVar3 == 0){
  io.output(0,io.input(8));
  oPVar2_TP = 0;
  oPVar1_B = 1;
}else{
  io.output(0,io.input(9));
  oPVar1_B = 0;
  oPVar2_TP = 0;
}

io.output(1,oPVar1_B);
io.output(2,oPVar2_TP);
---------------------------------------------------
Kind regards



More information about the nashorn-dev mailing list