graaljs
graaljs copied to clipboard
Graal JS Script Engine is very slow compared to Rhino
We have this https://github.com/nmondal/cowj where we use js engines. We have ran some tests and in summary, when we use Graal Script Engine + GraalVM, it is very, very slow compared to Rhino + Temurin 21 VM.
To reproduce:
- Clone the cowj repo
- Switch branch to
graal
- Build the project
gradle clean build -x test
- Go to the
app/build/libs
folder and - Run the command
java -jar cowj-0.1-SNAPSHOT.jar ../../samples/hello/hello.yaml true
- Or, if running in graal -
gava -Dpolyglot.js.nashorn-compat=true -jar cowj-0.1-SNAPSHOT.jar ../../samples/hello/hello.yaml true
- Then run the following
wrk --latency -t12 -c400 -d30s http://127.0.0.1:5003/hello/j
We used wrk
tool from here ( https://github.com/wg/wrk )
The script file hello.js
contains the following:
// here is the return value
// here is a require
//let add = require( "./demo.js")
//_log.info( "10 + 20 is {}", add(10,20) )
//Test.print(req + "\n")
//Test.printe(resp + "\n")
//Test.panic(true,"Boom!")
"hello, world!"
It just returns "hello, world!"
We found out that graal is very slow compared to Rhino.
Attached are the benchmark results. In summary, the best performance for these two:
GRAAL
wrk git:(master) ./wrk --latency -t12 -c400 -d30s http://127.0.0.1:5003/hello/j
Running 30s test @ http://127.0.0.1:5003/hello/j
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 151.87ms 229.33ms 1.41s 91.82%
Req/Sec 456.94 296.54 1.97k 59.53%
Latency Distribution
50% 65.13ms
75% 177.84ms
90% 323.05ms
99% 1.21s
132949 requests in 30.10s, 21.55MB read
Requests/sec: 4417.54
Transfer/sec: 733.39KB
Rhino
wrk git:(master) ./wrk --latency -t12 -c400 -d30s http://127.0.0.1:5003/hello/j
Running 30s test @ http://127.0.0.1:5003/hello/j
12 threads and 400 connections
Thread Stats Avg Stdev Max +/- Stdev
Latency 5.74ms 2.64ms 215.97ms 85.20%
Req/Sec 5.72k 455.54 14.28k 92.53%
Latency Distribution
50% 6.39ms
75% 6.76ms
90% 7.24ms
99% 9.06ms
2050856 requests in 30.05s, 332.49MB read
Requests/sec: 68246.99
Transfer/sec: 11.06MB
This is a HUGE gap, order of magnitude high gap.
Notes
Build was done using temurin open jdk 21