-
1. Re: mbean invocation performance
metatype Jul 1, 2004 6:17 PM (in response to metatype)Ok, so further investigation shows a fairly constant overhead of about 15-25 microsecs per invocation using standard mbeans. I've seen references to over 1M invocations/sec here:
http://www.samspublishing.com/articles/article.asp?p=27196&seqNum=4
What do I need to do to get that kind of performance?
What is the downside of exposing a shortcut like getDirectRef() and doing direct invocations rather than going through the mbean proxy?
TIA -
2. Re: mbean invocation performance
metatype Jul 1, 2004 6:24 PM (in response to metatype)Here's the code in question...
jboss-service.xml:
hello
no hands
<depends optional-attribute-name="HelloWorld" proxy-type="attribute">my.hello:service=hw1
HelloWorldMBean.java:
package hello;
import org.jboss.system.ServiceMBean;
public interface HelloWorldMBean extends ServiceMBean {
public void setMessage(String msg);
public void sayHi();
public void setHelloWorld(HelloWorldMBean hello);
public HelloWorldMBean getDirectRef();
public void echo();
}
HelloWorld.java:
package hello;
import org.jboss.system.ServiceMBeanSupport;
public class HelloWorld extends ServiceMBeanSupport implements HelloWorldMBean {
private double r;
private double incr = 1.7d;
private String message;
private HelloWorldMBean hello;
public HelloWorldMBean getDirectRef() {
return this;
}
public void setMessage(String msg) {
message = msg;
}
public void sayHi() {
r += Math.random() / incr;
}
public void setHelloWorld(HelloWorldMBean hello) {
this.hello = hello;
}
public void echo() {
hello.sayHi();
}
protected void startService() {
log.info("Starting " + message);
if (hello != null) {
double t1 = testEcho();
log.info("invoke ms " + t1 / 1000000.0);
}
}
protected void stopService() {
log.info("Stopping " + message);
}
private double testEcho() {
for (int i = 0; i < 50000; i++) {
hello.sayHi();
}
long start = System.currentTimeMillis();
for (int i = 0; i < 1000000; i++) {
hello.sayHi();
}
long elapsed = System.currentTimeMillis() - start;
double rate = (1000000 * 1000.0 / elapsed);
log.info("jmx " + rate);
return elapsed;
}
} -
3. Re: mbean invocation performance
genman Jul 2, 2004 6:15 PM (in response to metatype)
You can return a POJO through a "getRef" method, including the MBean interface itself. Example:HelloMBean h = MBeanServer.getAttribute(name, "Ref")
If you are doing something like this, it should be plenty fast:Object args[] = { a, b, c}; String sig[] = "java.lang.Object", ... while (true) getServer().invoke(name, args, sig);
If you're going over RMI it's slower, it's also slower to construct the args/sig arrays each invocation. Java 1.4 is a lot faster with Reflection. -
4. Re: mbean invocation performance
genman Jul 2, 2004 6:23 PM (in response to metatype)
You can set the system property
jbossmx.optimized.dispatcher
to "true". I don't know if it's officially supported in JBoss, however.
Check out ./src/main/org/jboss/mx/capability/DispatcherFactory.java in the JMX source.