Hey folks, I've tried many different ways of using Nashorn multithreaded based on what I've found on the internet and I still can't get a single one to scale. Even the most naive method of making many script engines with my script tends to bottleneck itself when I have more than 10 threads invoking functions.
I'm using the following code to compile my script and invocable.invokeFunction("transform", input) to execute: > static Invocable generateInvocable(String script) throws > ScriptException { > ScriptEngineManager manager = new ScriptEngineManager(); > ScriptEngine engine = > manager.getEngineByName(JAVASCRIPT_ENGINE_NAME); > Compilable compilable = (Compilable) engine; > final CompiledScript compiled = compilable.compile(script); > compiled.eval(); > return (Invocable) engine; > } The script I'm compiling is: > String script = "function transform(input) {" + > "var result = JSON.parse(input);" + > "response = {};\n" + > "for (var i = 0; i < result.length; i++) {\n" + > " var summoner = {};\n" + > " summoner.id = result[i].id;\n" + > " summoner.name = result[i].name;\n" + > " summoner.profileIconId = result[i].profileIconId;\n" + > " summoner.revisionDate = result[i].revisionDate;\n" + > " summoner.summonerLevel = result[i].level;\n" + > " response[summoner.id] = summoner;\n" + > "}\n" + > "result = response;" + > "return JSON.stringify(result);" + > "};"; I've also tried other more scaleable ways to work with scripts concurrently, but given that this is the most naive method where everything is brand new and I still get slowness calling them concurrently I fear that maybe I'm overlooking something extremely basic on my code. Thanks. -Jesus Luzon