GroovyScriptEngine...maximizing performance?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
38 messages Options
1234
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

GroovyScriptEngine...maximizing performance?

paduffy
Folks,

My team is about to select a scripting language to be embedded in our server product.  Goal is to allow customers to modify select server operations via scripting.  Being a Java shop, JavaScript/Rhino and Groovy are the two contenders...JyThon being a distant third possibility.

We are in the midst of the JavaScript/Groovy comparison.  Numbers are not looking good for Groovy, but I am not at all sure we are not doing something wrong.

Snippet of the Java code invoking the script engine...

        // arg[0] - script path.
        // arg[1] - script name.
        // arg[2] - number of passes to run.
        //
        System.out.println("Groovy script roots: " + args[0]);        
        System.out.println("Executing Groovy script: " + args[1]);
       
        String[] roots = new String[1];
        roots[0] = args[0];
        int passes = Integer.parseInt(args[2]);
               
        Binding binding = new Binding();
       
        ...
        ...

        long duration = 0L;
        try
        {
            GroovyScriptEngine gse = new GroovyScriptEngine(roots);
           
            long startTime = System.currentTimeMillis();
            for (int i = 0; i < passes; i++)
            {
                gse.run(args[1], binding);
            }
            duration = System.currentTimeMillis() - startTime;
        }

A couple qs...

- Is there any other script engine techniques I should be applying to maximize performance?
- I assume the first call to gre.run(...) compiles and caches the script bytecode, such that subsequent runs merely execute the cached bytecode?

Appreciate any help.

Thank you.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GroovyScriptEngine...maximizing performance?

paduffy
P.S.  I must be doing something wrong here (same hardware...).

- GroovyScriptEngine.run() is giving me 71 executions/sec
- Java equivalent gives me 62,000+ executions/sec


paduffy wrote
Folks,

My team is about to select a scripting language to be embedded in our server product.  Goal is to allow customers to modify select server operations via scripting.  Being a Java shop, JavaScript/Rhino and Groovy are the two contenders...JyThon being a distant third possibility.

We are in the midst of the JavaScript/Groovy comparison.  Numbers are not looking good for Groovy, but I am not at all sure we are not doing something wrong.

Snippet of the Java code invoking the script engine...

        // arg[0] - script path.
        // arg[1] - script name.
        // arg[2] - number of passes to run.
        //
        System.out.println("Groovy script roots: " + args[0]);        
        System.out.println("Executing Groovy script: " + args[1]);
       
        String[] roots = new String[1];
        roots[0] = args[0];
        int passes = Integer.parseInt(args[2]);
               
        Binding binding = new Binding();
       
        ...
        ...

        long duration = 0L;
        try
        {
            GroovyScriptEngine gse = new GroovyScriptEngine(roots);
           
            long startTime = System.currentTimeMillis();
            for (int i = 0; i < passes; i++)
            {
                gse.run(args[1], binding);
            }
            duration = System.currentTimeMillis() - startTime;
        }

A couple qs...

- Is there any other script engine techniques I should be applying to maximize performance?
- I assume the first call to gre.run(...) compiles and caches the script bytecode, such that subsequent runs merely execute the cached bytecode?

Appreciate any help.

Thank you.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GroovyScriptEngine...maximizing performance?

Michael Baehr
I'm not an expert, but:

You create a new instance of GroovyScriptEngine in every run. To my
understanding, this means it will recompile the script on each run!

You should create only one instance and reuse it. GroovyScriptEngine
will then cache the compiled script and recompile it only if the script
changes!

That should boost the performance quite a bit ...

Michael

paduffy schrieb:

> P.S.  I must be doing something wrong here (same hardware...).
>
> - GroovyScriptEngine.run() is giving me 71 executions/sec
> - Java equivalent gives me 62,000+ executions/sec
>
>
>
> paduffy wrote:
>  
>> Folks,
>>
>> My team is about to select a scripting language to be embedded in our
>> server product.  Goal is to allow customers to modify select server
>> operations via scripting.  Being a Java shop, JavaScript/Rhino and Groovy
>> are the two contenders...JyThon being a distant third possibility.
>>
>> We are in the midst of the JavaScript/Groovy comparison.  Numbers are not
>> looking good for Groovy, but I am not at all sure we are not doing
>> something wrong.
>>
>> Snippet of the Java code invoking the script engine...
>>
>>         // arg[0] - script path.
>>         // arg[1] - script name.
>>         // arg[2] - number of passes to run.
>>         //
>>         System.out.println("Groovy script roots: " + args[0]);        
>>         System.out.println("Executing Groovy script: " + args[1]);
>>        
>>         String[] roots = new String[1];
>>         roots[0] = args[0];
>>         int passes = Integer.parseInt(args[2]);
>>                
>>         Binding binding = new Binding();
>>        
>>         ...
>>         ...
>>
>>         long duration = 0L;
>>         try
>>         {
>>             GroovyScriptEngine gse = new GroovyScriptEngine(roots);
>>            
>>             long startTime = System.currentTimeMillis();
>>             for (int i = 0; i < passes; i++)
>>             {
>>                 gse.run(args[1], binding);
>>             }
>>             duration = System.currentTimeMillis() - startTime;
>>         }
>>
>> A couple qs...
>>
>> - Is there any other script engine techniques I should be applying to
>> maximize performance?
>> - I assume the first call to gre.run(...) compiles and caches the script
>> bytecode, such that subsequent runs merely execute the cached bytecode?
>>
>> Appreciate any help.
>>
>> Thank you.
>>
>>
>>    
>
>  


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GroovyScriptEngine...maximizing performance?

paduffy
The GroovyScriptEngine is created once before the run() loop is entered.

Michael Baehr wrote
I'm not an expert, but:

You create a new instance of GroovyScriptEngine in every run. To my
understanding, this means it will recompile the script on each run!

You should create only one instance and reuse it. GroovyScriptEngine
will then cache the compiled script and recompile it only if the script
changes!

That should boost the performance quite a bit ...

Michael

paduffy schrieb:
> P.S.  I must be doing something wrong here (same hardware...).
>
> - GroovyScriptEngine.run() is giving me 71 executions/sec
> - Java equivalent gives me 62,000+ executions/sec
>
>
>
> paduffy wrote:
>  
>> Folks,
>>
>> My team is about to select a scripting language to be embedded in our
>> server product.  Goal is to allow customers to modify select server
>> operations via scripting.  Being a Java shop, JavaScript/Rhino and Groovy
>> are the two contenders...JyThon being a distant third possibility.
>>
>> We are in the midst of the JavaScript/Groovy comparison.  Numbers are not
>> looking good for Groovy, but I am not at all sure we are not doing
>> something wrong.
>>
>> Snippet of the Java code invoking the script engine...
>>
>>         // arg[0] - script path.
>>         // arg[1] - script name.
>>         // arg[2] - number of passes to run.
>>         //
>>         System.out.println("Groovy script roots: " + args[0]);        
>>         System.out.println("Executing Groovy script: " + args[1]);
>>        
>>         String[] roots = new String[1];
>>         roots[0] = args[0];
>>         int passes = Integer.parseInt(args[2]);
>>                
>>         Binding binding = new Binding();
>>        
>>         ...
>>         ...
>>
>>         long duration = 0L;
>>         try
>>         {
>>             GroovyScriptEngine gse = new GroovyScriptEngine(roots);
>>            
>>             long startTime = System.currentTimeMillis();
>>             for (int i = 0; i < passes; i++)
>>             {
>>                 gse.run(args[1], binding);
>>             }
>>             duration = System.currentTimeMillis() - startTime;
>>         }
>>
>> A couple qs...
>>
>> - Is there any other script engine techniques I should be applying to
>> maximize performance?
>> - I assume the first call to gre.run(...) compiles and caches the script
>> bytecode, such that subsequent runs merely execute the cached bytecode?
>>
>> Appreciate any help.
>>
>> Thank you.
>>
>>
>>    
>
>  


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GroovyScriptEngine...maximizing performance?

Michael Baehr
I shouldn't answer on newsgroups at 1:40 am ...

Would you post your script (Groovy and Java equivalent) so we can try it
out as well? And so that the real Groovy experts can comment on it?

Those results don't look like anything I've seen so far ...

Michael

paduffy schrieb:

> The GroovyScriptEngine is created once before the run() loop is entered.
>
>
> Michael Baehr wrote:
>  
>> I'm not an expert, but:
>>
>> You create a new instance of GroovyScriptEngine in every run. To my
>> understanding, this means it will recompile the script on each run!
>>
>> You should create only one instance and reuse it. GroovyScriptEngine
>> will then cache the compiled script and recompile it only if the script
>> changes!
>>
>> That should boost the performance quite a bit ...
>>
>> Michael
>>
>> paduffy schrieb:
>>    
>>> P.S.  I must be doing something wrong here (same hardware...).
>>>
>>> - GroovyScriptEngine.run() is giving me 71 executions/sec
>>> - Java equivalent gives me 62,000+ executions/sec
>>>
>>>
>>>
>>> paduffy wrote:
>>>  
>>>      
>>>> Folks,
>>>>
>>>> My team is about to select a scripting language to be embedded in our
>>>> server product.  Goal is to allow customers to modify select server
>>>> operations via scripting.  Being a Java shop, JavaScript/Rhino and
>>>> Groovy
>>>> are the two contenders...JyThon being a distant third possibility.
>>>>
>>>> We are in the midst of the JavaScript/Groovy comparison.  Numbers are
>>>> not
>>>> looking good for Groovy, but I am not at all sure we are not doing
>>>> something wrong.
>>>>
>>>> Snippet of the Java code invoking the script engine...
>>>>
>>>>         // arg[0] - script path.
>>>>         // arg[1] - script name.
>>>>         // arg[2] - number of passes to run.
>>>>         //
>>>>         System.out.println("Groovy script roots: " + args[0]);        
>>>>         System.out.println("Executing Groovy script: " + args[1]);
>>>>        
>>>>         String[] roots = new String[1];
>>>>         roots[0] = args[0];
>>>>         int passes = Integer.parseInt(args[2]);
>>>>                
>>>>         Binding binding = new Binding();
>>>>        
>>>>         ...
>>>>         ...
>>>>
>>>>         long duration = 0L;
>>>>         try
>>>>         {
>>>>             GroovyScriptEngine gse = new GroovyScriptEngine(roots);
>>>>            
>>>>             long startTime = System.currentTimeMillis();
>>>>             for (int i = 0; i < passes; i++)
>>>>             {
>>>>                 gse.run(args[1], binding);
>>>>             }
>>>>             duration = System.currentTimeMillis() - startTime;
>>>>         }
>>>>
>>>> A couple qs...
>>>>
>>>> - Is there any other script engine techniques I should be applying to
>>>> maximize performance?
>>>> - I assume the first call to gre.run(...) compiles and caches the script
>>>> bytecode, such that subsequent runs merely execute the cached bytecode?
>>>>
>>>> Appreciate any help.
>>>>
>>>> Thank you.
>>>>
>>>>
>>>>    
>>>>        
>>>  
>>>      
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>>
>>    
>
>  


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GroovyScriptEngine...maximizing performance?

paduffy
Here's the entire script...

Appreciate any help.

---
// The point of this script is to allow customers to build a custom list of foo.
//
// Binding passes in...
//
//   fooList - the list of foo to be populated by this script.
//   factory - create a foo.
//   sysCtx - system context, used for looking up values for conditionals, etc.
//
//   NOTE: the factory and sysCtx are merely stubbed for now.
//
//
fooList.add(factory.createFoo("FOO-1", "1"))

a = sysCtx.getProperty("A", "64000")
b = sysCtx.getProperty("B", "Gold");

// Composite foo.
//
aFoo = factory.createFoo("FOO-2")
aFoo.add(factory.createFoo("1", "2"))
aFoo.add(factory.createFoo("2", "7"))
aFoo.add(factory.createFoo("3", "1"))
aFoo.add(factory.createFoo("4", a))
if(b == "Gold")
{
  aFoo.add(factory.createFoo("5", "When I get to it..."))
}
else
{
  aFoo.add(factory.createFoo("5", "Best Effort!"))
}
fooList.add(aFoo)

aFoo = factory.createFoo("FOO-3")
aFoo.add(factory.createFoo("1", "1"))
aFoo.add(factory.createFoo("6", "7"))
aFoo.add(factory.createFoo("7", "1"))
aFoo.add(factory.createFoo("8", "128000"))
fooList.add(aFoo)

fooList.add(factory.createFoo("FOO-4", [".mib-2.1", "Integer", "4"]))

fooList.add(factory.createFoo("FOO-4", [".mib-2.2" "IP Address", "255.255.255.255"]))

fooList.add(factory.createFoo("FOO-4", [".mib-2.3", "IP Address",  "255.255.255.0"]))
   
fooList.add(factory.createFoo("FOO-4", [".mib-2.4", "Octet String", "private"]))

fooList.add(factory.createFoo("FOO-4", [".mib-2.5", "Integer", "3"]))

fooList.add(factory.createFoo("FOO-4", [".mib-2.6", "Integer", "4"]))

fooList.add(factory.createFoo("FOO-4", [".mib-2.7", "IP Address",  "255.255.255.255"]))

fooList.add(factory.createFoo("FOO-4", [".mib-2.8", "IP Address",  "255.255.255.0"]))
   
fooList.add(factory.createFoo("FOO-4", [".mib-2.9", "Octet String", "public"]))

fooList.add(factory.createFoo("FOO-5", "1"));

fooList.add(factory.createFoo("FOO-6", "0"));

---


Michael Baehr wrote
I shouldn't answer on newsgroups at 1:40 am ...


Would you post your script (Groovy and Java equivalent) so we can try it
out as well? And so that the real Groovy experts can comment on it?

Those results don't look like anything I've seen so far ...

Michael

paduffy schrieb:
> The GroovyScriptEngine is created once before the run() loop is entered.
>
>
> Michael Baehr wrote:
>  
>> I'm not an expert, but:
>>
>> You create a new instance of GroovyScriptEngine in every run. To my
>> understanding, this means it will recompile the script on each run!
>>
>> You should create only one instance and reuse it. GroovyScriptEngine
>> will then cache the compiled script and recompile it only if the script
>> changes!
>>
>> That should boost the performance quite a bit ...
>>
>> Michael
>>
>> paduffy schrieb:
>>    
>>> P.S.  I must be doing something wrong here (same hardware...).
>>>
>>> - GroovyScriptEngine.run() is giving me 71 executions/sec
>>> - Java equivalent gives me 62,000+ executions/sec
>>>
>>>
>>>
>>> paduffy wrote:
>>>  
>>>      
>>>> Folks,
>>>>
>>>> My team is about to select a scripting language to be embedded in our
>>>> server product.  Goal is to allow customers to modify select server
>>>> operations via scripting.  Being a Java shop, JavaScript/Rhino and
>>>> Groovy
>>>> are the two contenders...JyThon being a distant third possibility.
>>>>
>>>> We are in the midst of the JavaScript/Groovy comparison.  Numbers are
>>>> not
>>>> looking good for Groovy, but I am not at all sure we are not doing
>>>> something wrong.
>>>>
>>>> Snippet of the Java code invoking the script engine...
>>>>
>>>>         // arg[0] - script path.
>>>>         // arg[1] - script name.
>>>>         // arg[2] - number of passes to run.
>>>>         //
>>>>         System.out.println("Groovy script roots: " + args[0]);        
>>>>         System.out.println("Executing Groovy script: " + args[1]);
>>>>        
>>>>         String[] roots = new String[1];
>>>>         roots[0] = args[0];
>>>>         int passes = Integer.parseInt(args[2]);
>>>>                
>>>>         Binding binding = new Binding();
>>>>        
>>>>         ...
>>>>         ...
>>>>
>>>>         long duration = 0L;
>>>>         try
>>>>         {
>>>>             GroovyScriptEngine gse = new GroovyScriptEngine(roots);
>>>>            
>>>>             long startTime = System.currentTimeMillis();
>>>>             for (int i = 0; i < passes; i++)
>>>>             {
>>>>                 gse.run(args[1], binding);
>>>>             }
>>>>             duration = System.currentTimeMillis() - startTime;
>>>>         }
>>>>
>>>> A couple qs...
>>>>
>>>> - Is there any other script engine techniques I should be applying to
>>>> maximize performance?
>>>> - I assume the first call to gre.run(...) compiles and caches the script
>>>> bytecode, such that subsequent runs merely execute the cached bytecode?
>>>>
>>>> Appreciate any help.
>>>>
>>>> Thank you.
>>>>
>>>>
>>>>    
>>>>        
>>>  
>>>      
>> ---------------------------------------------------------------------
>> To unsubscribe from this list please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>>
>>    
>
>  


---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GroovyScriptEngine...maximizing performance?

paduffy
In reply to this post by paduffy
Leatest test results. Running equivalent code...

- Java: 130,000 runs/sec
- Javascript/Rhino: 4400 runs/sec
- Groovy: 80 runs/sec.

Java is obviously compiled.  No suprise here.
Javascript main explicitly compiles the script before entering the script execution loop.

I'm guessing that my previous assumption of GroovyScriptEngine.run() compiling and caching the bytecode on its first invocation is incorrect.  So I also assume I'm missing the Groovy compile before run step.  Groovy test must be  parsing on each pass.

Can someone please point me to a clear example re: getting GroovyScriptEngine to run at full speed?  Can I compile the script before invoking scipt engine run? Or is this an area in which Groovy is not a contender?

Cheers

paduffy wrote
Folks,

My team is about to select a scripting language to be embedded in our server product.  Goal is to allow customers to modify select server operations via scripting.  Being a Java shop, JavaScript/Rhino and Groovy are the two contenders...JyThon being a distant third possibility.

We are in the midst of the JavaScript/Groovy comparison.  Numbers are not looking good for Groovy, but I am not at all sure we are not doing something wrong.

Snippet of the Java code invoking the script engine...

        // arg[0] - script path.
        // arg[1] - script name.
        // arg[2] - number of passes to run.
        //
        System.out.println("Groovy script roots: " + args[0]);        
        System.out.println("Executing Groovy script: " + args[1]);
       
        String[] roots = new String[1];
        roots[0] = args[0];
        int passes = Integer.parseInt(args[2]);
               
        Binding binding = new Binding();
       
        ...
        ...

        long duration = 0L;
        try
        {
            GroovyScriptEngine gse = new GroovyScriptEngine(roots);
           
            long startTime = System.currentTimeMillis();
            for (int i = 0; i < passes; i++)
            {
                gse.run(args[1], binding);
            }
            duration = System.currentTimeMillis() - startTime;
        }

A couple qs...

- Is there any other script engine techniques I should be applying to maximize performance?
- I assume the first call to gre.run(...) compiles and caches the script bytecode, such that subsequent runs merely execute the cached bytecode?

Appreciate any help.

Thank you.
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GroovyScriptEngine...maximizing performance?

Michael Baehr
I cannot offer you a fix, but I can reproduce your results!

I loaded a Groovy script via GroovyClassLoader. Instantiating and
calling this class 100000 times produced the following results:

Running now ...
Running took 4056.072769ms
Average took 0.04056072769ms

Running the same script via GroovyScriptEngine gave the following results:

Running now ...
Running took 173280.63455ms
Average took 1.7328063455ms

It seams that GroovyScriptEngine indeed recompiles at every run which
would be a bug!

Can some Groovy guru comfirm?

Michael

paduffy schrieb:

> Leatest test results. Running equivalent code...
>
> - Java: 130,000 runs/sec
> - Javascript/Rhino: 4400 runs/sec
> - Groovy: 80 runs/sec.
>
> Java is obviously compiled.  No suprise here.
> Javascript main explicitly compiles the script before entering the script
> execution loop.
>
> I'm guessing that my previous assumption of GroovyScriptEngine.run()
> compiling and caching the bytecode on its first invocation is incorrect.  So
> I also assume I'm missing the Groovy compile before run step.  Groovy test
> must be  parsing on each pass.
>
> Can someone please point me to a clear example re: getting
> GroovyScriptEngine to run at full speed?  Can I compile the script before
> invoking scipt engine run? Or is this an area in which Groovy is not a
> contender?
>
> Cheers
>
>
> paduffy wrote:
>  
>> Folks,
>>
>> My team is about to select a scripting language to be embedded in our
>> server product.  Goal is to allow customers to modify select server
>> operations via scripting.  Being a Java shop, JavaScript/Rhino and Groovy
>> are the two contenders...JyThon being a distant third possibility.
>>
>> We are in the midst of the JavaScript/Groovy comparison.  Numbers are not
>> looking good for Groovy, but I am not at all sure we are not doing
>> something wrong.
>>
>> Snippet of the Java code invoking the script engine...
>>
>>         // arg[0] - script path.
>>         // arg[1] - script name.
>>         // arg[2] - number of passes to run.
>>         //
>>         System.out.println("Groovy script roots: " + args[0]);        
>>         System.out.println("Executing Groovy script: " + args[1]);
>>        
>>         String[] roots = new String[1];
>>         roots[0] = args[0];
>>         int passes = Integer.parseInt(args[2]);
>>                
>>         Binding binding = new Binding();
>>        
>>         ...
>>         ...
>>
>>         long duration = 0L;
>>         try
>>         {
>>             GroovyScriptEngine gse = new GroovyScriptEngine(roots);
>>            
>>             long startTime = System.currentTimeMillis();
>>             for (int i = 0; i < passes; i++)
>>             {
>>                 gse.run(args[1], binding);
>>             }
>>             duration = System.currentTimeMillis() - startTime;
>>         }
>>
>> A couple qs...
>>
>> - Is there any other script engine techniques I should be applying to
>> maximize performance?
>> - I assume the first call to gre.run(...) compiles and caches the script
>> bytecode, such that subsequent runs merely execute the cached bytecode?
>>
>> Appreciate any help.
>>
>> Thank you.
>>
>>
>>    
>
>  

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GroovyScriptEngine...maximizing performance?

Guillaume Laforge
Administrator
This really sounds like GroovyScriptEngine recompiles stuff all the
time, which is really a bug :-(
But I haven't looked at the code to check what's happening, but the
symptoms are really obvious.

On 2/13/07, Michael Baehr <[hidden email]> wrote:

> I cannot offer you a fix, but I can reproduce your results!
>
> I loaded a Groovy script via GroovyClassLoader. Instantiating and
> calling this class 100000 times produced the following results:
>
> Running now ...
> Running took 4056.072769ms
> Average took 0.04056072769ms
>
> Running the same script via GroovyScriptEngine gave the following results:
>
> Running now ...
> Running took 173280.63455ms
> Average took 1.7328063455ms
>
> It seams that GroovyScriptEngine indeed recompiles at every run which
> would be a bug!
>
> Can some Groovy guru comfirm?
>
> Michael
>
> paduffy schrieb:
> > Leatest test results. Running equivalent code...
> >
> > - Java: 130,000 runs/sec
> > - Javascript/Rhino: 4400 runs/sec
> > - Groovy: 80 runs/sec.
> >
> > Java is obviously compiled.  No suprise here.
> > Javascript main explicitly compiles the script before entering the script
> > execution loop.
> >
> > I'm guessing that my previous assumption of GroovyScriptEngine.run()
> > compiling and caching the bytecode on its first invocation is incorrect.  So
> > I also assume I'm missing the Groovy compile before run step.  Groovy test
> > must be  parsing on each pass.
> >
> > Can someone please point me to a clear example re: getting
> > GroovyScriptEngine to run at full speed?  Can I compile the script before
> > invoking scipt engine run? Or is this an area in which Groovy is not a
> > contender?
> >
> > Cheers
> >
> >
> > paduffy wrote:
> >
> >> Folks,
> >>
> >> My team is about to select a scripting language to be embedded in our
> >> server product.  Goal is to allow customers to modify select server
> >> operations via scripting.  Being a Java shop, JavaScript/Rhino and Groovy
> >> are the two contenders...JyThon being a distant third possibility.
> >>
> >> We are in the midst of the JavaScript/Groovy comparison.  Numbers are not
> >> looking good for Groovy, but I am not at all sure we are not doing
> >> something wrong.
> >>
> >> Snippet of the Java code invoking the script engine...
> >>
> >>         // arg[0] - script path.
> >>         // arg[1] - script name.
> >>         // arg[2] - number of passes to run.
> >>         //
> >>         System.out.println("Groovy script roots: " + args[0]);
> >>         System.out.println("Executing Groovy script: " + args[1]);
> >>
> >>         String[] roots = new String[1];
> >>         roots[0] = args[0];
> >>         int passes = Integer.parseInt(args[2]);
> >>
> >>         Binding binding = new Binding();
> >>
> >>         ...
> >>         ...
> >>
> >>         long duration = 0L;
> >>         try
> >>         {
> >>             GroovyScriptEngine gse = new GroovyScriptEngine(roots);
> >>
> >>             long startTime = System.currentTimeMillis();
> >>             for (int i = 0; i < passes; i++)
> >>             {
> >>                 gse.run(args[1], binding);
> >>             }
> >>             duration = System.currentTimeMillis() - startTime;
> >>         }
> >>
> >> A couple qs...
> >>
> >> - Is there any other script engine techniques I should be applying to
> >> maximize performance?
> >> - I assume the first call to gre.run(...) compiles and caches the script
> >> bytecode, such that subsequent runs merely execute the cached bytecode?
> >>
> >> Appreciate any help.
> >>
> >> Thank you.
> >>
> >>
> >>
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe from this list please visit:
>
>     http://xircles.codehaus.org/manage_email
>
>


--
Guillaume Laforge
Groovy Project Manager
http://glaforge.free.fr/blog/groovy

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: GroovyScriptEngine...maximizing performance?

Michael Baehr
Guillaume,

Here is my Java class I used to test:

/*
 * Created on 13.02.2007
 */
package de.codex.groovy;

import java.io.File;

import groovy.lang.Binding;
import groovy.lang.GroovyClassLoader;
import groovy.lang.GroovyObject;
import groovy.util.GroovyScriptEngine;

public class EmbeddingBenchmark {

    private String scriptPath;
    private String scriptName;
    private int repetitions;
   
    public EmbeddingBenchmark(String scriptPath, String scriptName, int
repetitions) {
        this.scriptPath = scriptPath;
        this.scriptName = scriptName;
        this.repetitions= repetitions;
    }
   
    public void testClassLoader() throws Exception {
        ClassLoader parent = getClass().getClassLoader();
        GroovyClassLoader loader = new GroovyClassLoader(parent);
        long compileStart = System.nanoTime();
        Class groovyClass = loader.parseClass(new
File(scriptPath,scriptName));
        long compileEnd = System.nanoTime();
        System.out.println("Compiling took
"+((compileEnd-compileStart)/1000000.0)+"ms");

        System.out.println("Running now ...");
        long runStart = System.nanoTime();
        for (int i=0; i<repetitions; i++) {
            GroovyObject groovyObject = (GroovyObject)
groovyClass.newInstance();
            Object[] args = {};
            groovyObject.invokeMethod("run", args);
        }
        long runEnd = System.nanoTime();
        System.out.println("Running took
"+((runEnd-runStart)/1000000.0)+"ms");
        System.out.println("Average took
"+((runEnd-runStart)/1000000.0/repetitions)+"ms");

    }
   
    public void testScriptEngine() throws Exception {
        String[] roots = new String[] { scriptPath };
        GroovyScriptEngine gse = new GroovyScriptEngine(roots);
        Binding binding = new Binding();
        System.out.println("Running now ...");
        long runStart = System.nanoTime();
        for (int i=0; i<repetitions; i++) {
            gse.run(scriptName, binding);
        }
        long runEnd = System.nanoTime();
        System.out.println("Running took
"+((runEnd-runStart)/1000000.0)+"ms");
        System.out.println("Average took
"+((runEnd-runStart)/1000000.0/repetitions)+"ms");
    }
   
    public static void main(String[] args) throws Exception {
        if (args.length != 3) {
            System.out.println("Need 3 arguments: scriptPath scriptName
repetitions");
        } else {
            String scriptPath = args[0];
            String scriptName = args[1];
            int repetitions = Integer.parseInt(args[2]);
            System.out.println("ScriptPath="+scriptPath+",
ScriptName="+scriptName+", Repetitions="+repetitions);
            EmbeddingBenchmark eb = new EmbeddingBenchmark(scriptPath,
scriptName, repetitions);
            System.out.println();
            System.out.println("Run via GroovyClassLoader:");
            eb.testClassLoader();
            System.out.println();
            System.out.println("Run via GroovyScriptEngine:");
            eb.testScriptEngine();
        }
    }

}


Guillaume Laforge schrieb:
> This really sounds like GroovyScriptEngine recompiles stuff all the
> time, which is really a bug :-(
> But I haven't looked at the code to check what's happening, but the
> symptoms are really obvious.
>

---------------------------------------------------------------------
To unsubscribe from this list please visit:

    http://xircles.codehaus.org/manage_email

1234
Loading...