Nashorn创业缓慢可以克服吗? [英] Can Nashorn startup slowness be overcome?

查看:98
本文介绍了Nashorn创业缓慢可以克服吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用Rhino作为图形内部的脚本组件。在该项目中,大约有200个小脚本独立运行。启动应用程序时,脚本应立即全速运行。 Rhino的表现已经足够了,但自从Oracle建议迁移到Nashorn之后,我面临着一个困境。

I've used Rhino for a scripting component inside graphics. In the project there are about 200 small scripts running independantly. Immediately when starting the application the scripts should be at full speed. Rhino's performance was sufficient, but since Oracle advices to migrate to Nashorn, i'm facing a dilema.

下图显示了Rhino和Nashorn之间在大约15,000次脚本调用时的负载差异。 Nashorn的Startup缓慢是我最大的问题。

Below a picture showing the load difference between Rhino and Nashorn at approximayely 15,000 invocations of the scripts. The Startup slowness of Nashorn is my biggest issue.

注意,这又回到了JDK 1.8.0。 JDK 1.8u5类似

我希望图片清晰。

这是我如何使用ScriptEngine的概述:

This is an outline of how i use the ScriptEngine:


  • 我' m使用一个脚本引擎实例,

  • 我为每个脚本创建一个CompiledScript对象,

  • Swingworker执行一次CompiledScript.eval()。

  • SwingWorkers每半秒启动一次。

  • 每个CompiledScript都有自己的SimpleScriptContext实例,每次执行都会重复使用。

  • I'm using One scripting Engine instance,
  • i create a CompiledScript object for each script,
  • A Swingworker executes a CompiledScript.eval() once.
  • Every half second the SwingWorkers are started.
  • Each CompiledScript has its own SimpleScriptContext instance which is reused for every execution.

下面我包含了一个运行时配置文件,说明了引擎随时间的繁忙程度;

Below i included a runtime profile of how busy the engine is over time;

谁知道如何克服Nashorn的创业缓慢?

Does anyone know how to overcome the startup slowness of Nashorn?

更新2015年4月15日 < br>
在Java8u45上使用200个单独的脚本进行相同的测试。

性能要好得多!在Java7上以与Rhino类似的速度运行。

UPDATE 15 April '15
Ran the same test with 200 seperate scripts on Java8u45.
Performance is much better! Runs similarly fast as Rhino on Java7.

推荐答案

在Java 1.8上,您可以通过 javax使用Rhino .script API使用此Maven依赖项并请求引擎 rhino

On Java 1.8, you can use Rhino via the javax.script API by using this Maven dependency and requesting the engine rhino:

    <dependency>
        <groupId>de.christophkraemer</groupId>
        <artifactId>rhino-script-engine</artifactId>
        <version>1.1.1</version>
    </dependency>

首页: https://github.com/cevou/rhino-script-engine

二进制文件:这里

如果您想要最新版本的Rhino,可以通过添加以下内容来覆盖它:

If you want the very latest version of Rhino, you can override it by adding something like this:

    <dependency>
        <groupId>org.mozilla</groupId>
        <artifactId>rhino</artifactId>
        <version>${rhinoVersion}</version>
    </dependency>

二进制文件:此处

顺便提一下,如果你想使用通过 javax.script 在Java 1.7上获取最新的Rhino,你应该请求引擎名称 rhino17R5 或者你可以随机获得一个旧的Rhino实例,它是JRE的一部分。所需的确切引擎名称取决于 rhino-script-engine 的版本。对于1.1.1,它是 rhino17R5

Incidentally, if you want to use get the latest Rhino on Java 1.7 via javax.script, you should request the engine name rhino17R5 or you might randomly get an instance of the old Rhino which is part of the JRE. The exact engine name required depends on the version of rhino-script-engine. For 1.1.1, it is rhino17R5.

这篇关于Nashorn创业缓慢可以克服吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆