Thread BLOCKED using BS in Multi threads

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Thread BLOCKED using BS in Multi threads

Fred Rolland (frolland)
Hi all,

 

I am having an issue when running multiple BS at the same type in
different threads in the same JVM.

 

Almost all the treads are getting into BLOCKED state due to some
synchronized code in Class.forName.

As a result the time of operation is much longer.

 

I have noticed that it happens mainly when the scripts are using
"source" to load other scripts.

 

Each threads have his own engine.

 

Any suggestion ?

 

Thanks

 

Fred

 

Thread dump:

 

"Scheduler-collector-SnmpCollector(MC.CA-30.4.31.162
[248]-0:0:0:0:0:0:0:0 [64]" prio=3 tid=0x012aa400 nid=0x4c waiting for
monitor entry [0x9457e000]

   java.lang.Thread.State: BLOCKED (on object monitor)

        at java.lang.Class.forName0(Native Method)

        at java.lang.Class.forName(Class.java:169)

        at bsh.BshClassManager.plainClassForName(Unknown Source)

        at bsh.classpath.ClassManagerImpl.classForName(Unknown Source)

        at bsh.NameSpace.classForName(Unknown Source)

        at bsh.NameSpace.getImportedClassImpl(Unknown Source)

        at bsh.NameSpace.getClassImpl(Unknown Source)

        at bsh.NameSpace.getClass(Unknown Source)

        at bsh.NameSpace.getClass(Unknown Source)

        at bsh.Name.toClass(Unknown Source)

        - locked <0xe8988700> (a bsh.Name)

        at bsh.BSHAmbiguousName.toClass(Unknown Source)

        at bsh.BSHType.getType(Unknown Source)

        at bsh.BSHTypedVariableDeclaration.eval(Unknown Source)

        at bsh.BSHBlock.evalBlock(Unknown Source)

        at bsh.BSHBlock.eval(Unknown Source)

        at bsh.BSHBlock.eval(Unknown Source)

        at bsh.BSHTryStatement.eval(Unknown Source)

        at bsh.Interpreter.eval(Unknown Source)

        at bsh.Interpreter.eval(Unknown Source)

        at bsh.Interpreter.eval(Unknown Source)

        at bsh.util.BeanShellBSFEngine.eval(Unknown Source)

        at org.apache.bsf.BSFManager$5.run(Unknown Source)

        at java.security.AccessController.doPrivileged(Native Method)

        at org.apache.bsf.BSFManager.eval(Unknown Source)

------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Thread BLOCKED using BS in Multi threads

David Lee
I haven't seen this myself, we use BS in up to 200 threads and they are not
getting blocked to my knowledge.
However we are not using source, rather all BSH scripts are either resources
or provided as strings to the Interpreter instance.
Also we do a lot of caching to avoid having to 'compile' the scripts
frequently.  

----------------------------------------
David A. Lee
[hidden email]
http://www.xmlsh.org

-----Original Message-----
From: Fred Rolland (frolland) [mailto:[hidden email]]
Sent: Monday, November 15, 2010 6:50 AM
To: [hidden email]
Subject: [Beanshell-users] Thread BLOCKED using BS in Multi threads

Hi all,

 

I am having an issue when running multiple BS at the same type in
different threads in the same JVM.

 

Almost all the treads are getting into BLOCKED state due to some
synchronized code in Class.forName.

As a result the time of operation is much longer.

 

I have noticed that it happens mainly when the scripts are using
"source" to load other scripts.

 

Each threads have his own engine.

 

Any suggestion ?

 

Thanks

 

Fred

 

Thread dump:

 

"Scheduler-collector-SnmpCollector(MC.CA-30.4.31.162
[248]-0:0:0:0:0:0:0:0 [64]" prio=3 tid=0x012aa400 nid=0x4c waiting for
monitor entry [0x9457e000]

   java.lang.Thread.State: BLOCKED (on object monitor)

        at java.lang.Class.forName0(Native Method)

        at java.lang.Class.forName(Class.java:169)

        at bsh.BshClassManager.plainClassForName(Unknown Source)

        at bsh.classpath.ClassManagerImpl.classForName(Unknown Source)

        at bsh.NameSpace.classForName(Unknown Source)

        at bsh.NameSpace.getImportedClassImpl(Unknown Source)

        at bsh.NameSpace.getClassImpl(Unknown Source)

        at bsh.NameSpace.getClass(Unknown Source)

        at bsh.NameSpace.getClass(Unknown Source)

        at bsh.Name.toClass(Unknown Source)

        - locked <0xe8988700> (a bsh.Name)

        at bsh.BSHAmbiguousName.toClass(Unknown Source)

        at bsh.BSHType.getType(Unknown Source)

        at bsh.BSHTypedVariableDeclaration.eval(Unknown Source)

        at bsh.BSHBlock.evalBlock(Unknown Source)

        at bsh.BSHBlock.eval(Unknown Source)

        at bsh.BSHBlock.eval(Unknown Source)

        at bsh.BSHTryStatement.eval(Unknown Source)

        at bsh.Interpreter.eval(Unknown Source)

        at bsh.Interpreter.eval(Unknown Source)

        at bsh.Interpreter.eval(Unknown Source)

        at bsh.util.BeanShellBSFEngine.eval(Unknown Source)

        at org.apache.bsf.BSFManager$5.run(Unknown Source)

        at java.security.AccessController.doPrivileged(Native Method)

        at org.apache.bsf.BSFManager.eval(Unknown Source)

----------------------------------------------------------------------------
--
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users


------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Thread BLOCKED using BS in Multi threads

Fred Rolland (frolland)
David, thanks for your response.

What kind of caching are you using ?

I am currently considering to override NameSpace to cache the classes in
a static map.
Maybe it will help avoid the blocking in my case.



-----Original Message-----
From: David Lee [mailto:[hidden email]]
Sent: Monday, November 15, 2010 2:57 PM
To: Fred Rolland (frolland); [hidden email]
Subject: RE: [Beanshell-users] Thread BLOCKED using BS in Multi threads

I haven't seen this myself, we use BS in up to 200 threads and they are
not
getting blocked to my knowledge.
However we are not using source, rather all BSH scripts are either
resources
or provided as strings to the Interpreter instance.
Also we do a lot of caching to avoid having to 'compile' the scripts
frequently.  

----------------------------------------
David A. Lee
[hidden email]
http://www.xmlsh.org

-----Original Message-----
From: Fred Rolland (frolland) [mailto:[hidden email]]
Sent: Monday, November 15, 2010 6:50 AM
To: [hidden email]
Subject: [Beanshell-users] Thread BLOCKED using BS in Multi threads

Hi all,

 

I am having an issue when running multiple BS at the same type in
different threads in the same JVM.

 

Almost all the treads are getting into BLOCKED state due to some
synchronized code in Class.forName.

As a result the time of operation is much longer.

 

I have noticed that it happens mainly when the scripts are using
"source" to load other scripts.

 

Each threads have his own engine.

 

Any suggestion ?

 

Thanks

 

Fred

 

Thread dump:

 

"Scheduler-collector-SnmpCollector(MC.CA-30.4.31.162
[248]-0:0:0:0:0:0:0:0 [64]" prio=3 tid=0x012aa400 nid=0x4c waiting for
monitor entry [0x9457e000]

   java.lang.Thread.State: BLOCKED (on object monitor)

        at java.lang.Class.forName0(Native Method)

        at java.lang.Class.forName(Class.java:169)

        at bsh.BshClassManager.plainClassForName(Unknown Source)

        at bsh.classpath.ClassManagerImpl.classForName(Unknown Source)

        at bsh.NameSpace.classForName(Unknown Source)

        at bsh.NameSpace.getImportedClassImpl(Unknown Source)

        at bsh.NameSpace.getClassImpl(Unknown Source)

        at bsh.NameSpace.getClass(Unknown Source)

        at bsh.NameSpace.getClass(Unknown Source)

        at bsh.Name.toClass(Unknown Source)

        - locked <0xe8988700> (a bsh.Name)

        at bsh.BSHAmbiguousName.toClass(Unknown Source)

        at bsh.BSHType.getType(Unknown Source)

        at bsh.BSHTypedVariableDeclaration.eval(Unknown Source)

        at bsh.BSHBlock.evalBlock(Unknown Source)

        at bsh.BSHBlock.eval(Unknown Source)

        at bsh.BSHBlock.eval(Unknown Source)

        at bsh.BSHTryStatement.eval(Unknown Source)

        at bsh.Interpreter.eval(Unknown Source)

        at bsh.Interpreter.eval(Unknown Source)

        at bsh.Interpreter.eval(Unknown Source)

        at bsh.util.BeanShellBSFEngine.eval(Unknown Source)

        at org.apache.bsf.BSFManager$5.run(Unknown Source)

        at java.security.AccessController.doPrivileged(Native Method)

        at org.apache.bsf.BSFManager.eval(Unknown Source)

------------------------------------------------------------------------
----
--
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users


------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Thread BLOCKED using BS in Multi threads

David Lee
In my case each thread runs its own Interpreter object.   The contents of
all BS scripts are known at time of thread startup.
I cache the interpreter object for the lifetime of the thread.   At thread
startup I execute all dynamic and static script, as well as import statement
for system commands.   All scripts are simply function declarations, do not
execute code that needs to be re-evaluated ever.
Then when the threads access BS I only allow them to call functions (via the
java API).   Since the function declarations have been pre-run there is no
compilation going on (unless the call hits a branch that invokes a system
defined command which is implemented as a .bsh script in a resource, in that
case it might interpret it, but I have few of those).

I'm making heavy use of the interface API's to Interpreter so that calls
into it do not involve dynamic compilation.

I have not had to change any BS code to accomplish this.


----------------------------------------
David A. Lee
[hidden email]
http://www.xmlsh.org


-----Original Message-----
From: Fred Rolland (frolland) [mailto:[hidden email]]
Sent: Monday, November 15, 2010 8:16 AM
To: David Lee; [hidden email]
Subject: RE: [Beanshell-users] Thread BLOCKED using BS in Multi threads


David, thanks for your response.

What kind of caching are you using ?

I am currently considering to override NameSpace to cache the classes in
a static map.
Maybe it will help avoid the blocking in my case.



-----Original Message-----
From: David Lee [mailto:[hidden email]]
Sent: Monday, November 15, 2010 2:57 PM
To: Fred Rolland (frolland); [hidden email]
Subject: RE: [Beanshell-users] Thread BLOCKED using BS in Multi threads

I haven't seen this myself, we use BS in up to 200 threads and they are
not
getting blocked to my knowledge.
However we are not using source, rather all BSH scripts are either
resources
or provided as strings to the Interpreter instance.
Also we do a lot of caching to avoid having to 'compile' the scripts
frequently.  

----------------------------------------
David A. Lee
[hidden email]
http://www.xmlsh.org

-----Original Message-----
From: Fred Rolland (frolland) [mailto:[hidden email]]
Sent: Monday, November 15, 2010 6:50 AM
To: [hidden email]
Subject: [Beanshell-users] Thread BLOCKED using BS in Multi threads

Hi all,

 

I am having an issue when running multiple BS at the same type in
different threads in the same JVM.

 

Almost all the treads are getting into BLOCKED state due to some
synchronized code in Class.forName.

As a result the time of operation is much longer.

 

I have noticed that it happens mainly when the scripts are using
"source" to load other scripts.

 

Each threads have his own engine.

 

Any suggestion ?

 

Thanks

 

Fred

 

Thread dump:

 

"Scheduler-collector-SnmpCollector(MC.CA-30.4.31.162
[248]-0:0:0:0:0:0:0:0 [64]" prio=3 tid=0x012aa400 nid=0x4c waiting for
monitor entry [0x9457e000]

   java.lang.Thread.State: BLOCKED (on object monitor)

        at java.lang.Class.forName0(Native Method)

        at java.lang.Class.forName(Class.java:169)

        at bsh.BshClassManager.plainClassForName(Unknown Source)

        at bsh.classpath.ClassManagerImpl.classForName(Unknown Source)

        at bsh.NameSpace.classForName(Unknown Source)

        at bsh.NameSpace.getImportedClassImpl(Unknown Source)

        at bsh.NameSpace.getClassImpl(Unknown Source)

        at bsh.NameSpace.getClass(Unknown Source)

        at bsh.NameSpace.getClass(Unknown Source)

        at bsh.Name.toClass(Unknown Source)

        - locked <0xe8988700> (a bsh.Name)

        at bsh.BSHAmbiguousName.toClass(Unknown Source)

        at bsh.BSHType.getType(Unknown Source)

        at bsh.BSHTypedVariableDeclaration.eval(Unknown Source)

        at bsh.BSHBlock.evalBlock(Unknown Source)

        at bsh.BSHBlock.eval(Unknown Source)

        at bsh.BSHBlock.eval(Unknown Source)

        at bsh.BSHTryStatement.eval(Unknown Source)

        at bsh.Interpreter.eval(Unknown Source)

        at bsh.Interpreter.eval(Unknown Source)

        at bsh.Interpreter.eval(Unknown Source)

        at bsh.util.BeanShellBSFEngine.eval(Unknown Source)

        at org.apache.bsf.BSFManager$5.run(Unknown Source)

        at java.security.AccessController.doPrivileged(Native Method)

        at org.apache.bsf.BSFManager.eval(Unknown Source)

------------------------------------------------------------------------
----
--
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users



------------------------------------------------------------------------------
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
_______________________________________________
Beanshell-users mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/beanshell-users
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Thread BLOCKED using BS in Multi threads

Peter
This post has NOT been accepted by the mailing list yet.
In reply to this post by Fred Rolland (frolland)
Class-Generation was not thread safe with "old" BeanShell. This has been fixed in BeanShell2, see this issue:
http://code.google.com/p/beanshell2/issues/detail?id=40

To get an idea of how to cache scripts see the corresponding test class for the issue at http://code.google.com/p/beanshell2/source/browse/trunk/tests/junitTests/src/bsh/InterpreterConcurrencyTest.java

But keep in mind that with v2.0b4 you'll get random errors. You could use 2.1b0 or newer from http://code.google.com/p/beanshell2/downloads/list

--Peter
Loading...