[jboss-cvs] JBossAS SVN: r69621 - in projects/ejb3/trunk/sandbox/src: main/java/org/jboss/ejb3/sandbox/mc and 4 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Feb 5 09:20:44 EST 2008
Author: wolfc
Date: 2008-02-05 09:20:44 -0500 (Tue, 05 Feb 2008)
New Revision: 69621
Added:
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/mc/
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/mc/MC.java
projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/
projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/Calculator.java
projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/CalculatorBean.java
projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/Pi.java
projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/
projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/EJBUnitTestCase.java
projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/MCUnitTestCase.java
projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/StressCreator.java
Modified:
projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/stateless/StatelessInterceptor.java
Log:
Added performance test
Added: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/mc/MC.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/mc/MC.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/mc/MC.java 2008-02-05 14:20:44 UTC (rev 69621)
@@ -0,0 +1,95 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.sandbox.mc;
+
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.kernel.plugins.bootstrap.standalone.StandaloneBootstrap;
+import org.jboss.kernel.spi.dependency.KernelController;
+import org.jboss.kernel.spi.dependency.KernelControllerContext;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MC
+{
+ private static final Logger log = Logger.getLogger(MC.class);
+
+ private StandaloneBootstrap bootstrap;
+
+ public MC()
+ {
+ this(null);
+ }
+
+ public MC(String args[])
+ {
+ try
+ {
+ bootstrap = new StandaloneBootstrap(args);
+ bootstrap.run();
+ }
+ catch(Exception e)
+ {
+ // this actually never happens
+ throw new RuntimeException(e);
+ }
+ }
+
+ @Deprecated
+ public KernelController getController()
+ {
+ return bootstrap.getKernel().getController();
+ }
+
+ public void install(String name, Class<?> beanClass) throws Throwable
+ {
+ AbstractBeanMetaData metaData = new AbstractBeanMetaData(name, beanClass.getName());
+ metaData.setMode(ControllerMode.ON_DEMAND);
+ KernelControllerContext context = getController().install(metaData);
+ if(context.getError() != null)
+ throw context.getError();
+ }
+
+ public <T> T lookup(String name, Class<T> expectedType) throws Throwable
+ {
+ KernelController controller = getController();
+ ControllerContext context = controller.getContext(name, null);
+ controller.change(context, ControllerState.INSTALLED);
+ if(context.getError() != null)
+ throw context.getError();
+
+ if(context.getState() != ControllerState.INSTALLED) {
+ System.err.println(context.getDependencyInfo().getUnresolvedDependencies());
+ }
+ // TODO: it can be stalled because of dependencies
+ assert context.getState() == ControllerState.INSTALLED;
+
+ return expectedType.cast(context.getTarget());
+ }
+}
Property changes on: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/mc/MC.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Modified: projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/stateless/StatelessInterceptor.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/stateless/StatelessInterceptor.java 2008-02-05 14:20:04 UTC (rev 69620)
+++ projects/ejb3/trunk/sandbox/src/main/java/org/jboss/ejb3/sandbox/stateless/StatelessInterceptor.java 2008-02-05 14:20:44 UTC (rev 69621)
@@ -22,10 +22,15 @@
package org.jboss.ejb3.sandbox.stateless;
import java.lang.reflect.Method;
+import java.util.concurrent.TimeUnit;
+import javax.annotation.PostConstruct;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
+import org.jboss.ejb3.pool.Pool;
+import org.jboss.ejb3.pool.StatelessObjectFactory;
+import org.jboss.ejb3.pool.strictmax.StrictMaxPool;
import org.jboss.ejb3.sandbox.interceptorcontainer.InterceptorContainer;
import org.jboss.logging.Logger;
@@ -39,17 +44,76 @@
{
private static final Logger log = Logger.getLogger(StatelessInterceptor.class);
+ private Pool<Object> pool;
+
+ public static volatile long invocations, accumelatedWaitingTime, accumelatedExecutionTime;
+
+ public StatelessInterceptor()
+ {
+ }
+
@AroundInvoke
public Object invoke(InvocationContext ctx) throws Exception
{
+ /*
// TODO: a lot, the pool should be here
- InterceptorContainer container = (InterceptorContainer) ctx.getTarget();
+ InterceptorContainer container = (InterceptorContainer) ctx.getTarget();
Object instance = container.getBeanClass().newInstance();
- log.debug("ctx = " + ctx);
- Method method = (Method) ctx.getParameters()[0];
- Object args[] = (Object[]) ctx.getParameters()[1];
- Object result = method.invoke(instance, args);
- ctx.proceed();
- return result;
+ */
+ long startWait = System.currentTimeMillis();
+ Object instance = pool.get();
+ long startExecution = System.currentTimeMillis();
+ try
+ {
+ log.debug("ctx = " + ctx);
+ Method method = (Method) ctx.getParameters()[0];
+ Object args[] = (Object[]) ctx.getParameters()[1];
+ Object result = method.invoke(instance, args);
+ ctx.proceed();
+ return result;
+ }
+ finally
+ {
+ long endExecution = System.currentTimeMillis();
+ pool.release(instance);
+
+ invocations++;
+ accumelatedWaitingTime += (startExecution - startWait);
+ accumelatedExecutionTime += (endExecution - startExecution);
+ }
}
+
+ @PostConstruct
+ public void postConstruct(InvocationContext ctx) throws Exception
+ {
+ log.info("Creating pool");
+
+ InterceptorContainer container = (InterceptorContainer) ctx.getTarget();
+ final Class<?> beanClass = container.getBeanClass();
+ StatelessObjectFactory<Object> factory = new StatelessObjectFactory<Object>()
+ {
+ public Object create()
+ {
+ try
+ {
+ return beanClass.newInstance();
+ }
+ catch (InstantiationException e)
+ {
+ throw new RuntimeException(e);
+ }
+ catch (IllegalAccessException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+
+ public void destroy(Object obj)
+ {
+ // TODO Auto-generated method stub
+
+ }
+ };
+ pool = new StrictMaxPool<Object>(factory, 5, 30, TimeUnit.SECONDS);
+ }
}
Added: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/Calculator.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/Calculator.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/Calculator.java 2008-02-05 14:20:44 UTC (rev 69621)
@@ -0,0 +1,35 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.sandbox.performance;
+
+import java.math.BigDecimal;
+
+/**
+ * This one can only calculate PI
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public interface Calculator
+{
+ BigDecimal calculatePi(int digits);
+}
Property changes on: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/Calculator.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/CalculatorBean.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/CalculatorBean.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/CalculatorBean.java 2008-02-05 14:20:44 UTC (rev 69621)
@@ -0,0 +1,49 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.sandbox.performance;
+
+import java.math.BigDecimal;
+
+import javax.ejb.Stateless;
+
+import org.jboss.ejb3.sandbox.interceptorcontainer.ContainerInterceptors;
+import org.jboss.ejb3.sandbox.local.LocalBusinessInterfaceInterceptor;
+import org.jboss.ejb3.sandbox.stateless.StatelessInterceptor;
+import org.jboss.logging.Logger;
+
+/**
+ * The calculator bean just delegates to Pi.
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+ at ContainerInterceptors({ LocalBusinessInterfaceInterceptor.class, StatelessInterceptor.class })
+ at Stateless
+public class CalculatorBean implements Calculator
+{
+ private static final Logger log = Logger.getLogger(CalculatorBean.class);
+
+ public BigDecimal calculatePi(int digits)
+ {
+ return Pi.computePi(digits);
+ }
+}
Property changes on: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/CalculatorBean.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/Pi.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/Pi.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/Pi.java 2008-02-05 14:20:44 UTC (rev 69621)
@@ -0,0 +1,86 @@
+package org.jboss.ejb3.test.sandbox.performance;
+import java.math.BigDecimal;
+
+public class Pi {
+ public static void main(String args[]) throws NumberFormatException {
+ int digits = Integer.parseInt(args[0]);
+ String pi = computePi(digits).toString();
+ int freq[] = new int[10];
+ for(int i = 0;i < 10;i++) freq[i] = 0;
+ int c;
+ System.out.println(pi);
+ for(int i = 0;i < pi.length();i++) {
+ c = pi.charAt(i);
+ if(c == '.') continue;
+ c -= '0';
+ freq[c]++;
+ }
+ for(int i = 0;i < 10;i++) {
+ System.out.println("" + i + " " + freq[i]);
+ }
+ }
+ /** constants used in pi computation */
+ private static final BigDecimal FOUR = BigDecimal.valueOf(4);
+
+ /** rounding mode to use during pi computation */
+ private static final int roundingMode = BigDecimal.ROUND_HALF_EVEN;
+
+ /**
+ * Compute the value of pi to the specified number of
+ * digits after the decimal point. The value is
+ * computed using Machin's formula:
+ *
+ * pi/4 = 4*arctan(1/5) - arctan(1/239)
+ *
+ * and a power series expansion of arctan(x) to
+ * sufficient precision.
+ */
+ public static BigDecimal computePi(int digits) {
+ int scale = digits + 5;
+ BigDecimal arctan1_5 = arctan(5, scale);
+ BigDecimal arctan1_239 = arctan(239, scale);
+ BigDecimal pi = arctan1_5.multiply(FOUR).subtract(
+ arctan1_239).multiply(FOUR);
+ return pi.setScale(digits,
+ BigDecimal.ROUND_HALF_UP);
+ }
+ /**
+ * Compute the value, in radians, of the arctangent of
+ * the inverse of the supplied integer to the specified
+ * number of digits after the decimal point. The value
+ * is computed using the power series expansion for the
+ * arc tangent:
+ *
+ * arctan(x) = x - (x^3)/3 + (x^5)/5 - (x^7)/7 +
+ * (x^9)/9 ...
+ */
+ public static BigDecimal arctan(int inverseX,
+ int scale)
+ {
+ BigDecimal result, numer, term;
+ BigDecimal invX = BigDecimal.valueOf(inverseX);
+ BigDecimal invX2 =
+ BigDecimal.valueOf(inverseX * inverseX);
+
+ numer = BigDecimal.ONE.divide(invX,
+ scale, roundingMode);
+
+ result = numer;
+ int i = 1;
+ do {
+ numer =
+ numer.divide(invX2, scale, roundingMode);
+ int denom = 2 * i + 1;
+ term =
+ numer.divide(BigDecimal.valueOf(denom),
+ scale, roundingMode);
+ if ((i % 2) != 0) {
+ result = result.subtract(term);
+ } else {
+ result = result.add(term);
+ }
+ i++;
+ } while (term.compareTo(BigDecimal.ZERO) != 0);
+ return result;
+ }
+}
\ No newline at end of file
Property changes on: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/Pi.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/EJBUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/EJBUnitTestCase.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/EJBUnitTestCase.java 2008-02-05 14:20:44 UTC (rev 69621)
@@ -0,0 +1,80 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.sandbox.performance.unit;
+
+
+import java.net.URL;
+
+import javax.naming.InitialContext;
+
+import junit.framework.TestCase;
+
+import org.jboss.aop.AspectXmlLoader;
+import org.jboss.ejb3.interceptors.direct.DirectContainer;
+import org.jboss.ejb3.sandbox.interceptorcontainer.InterceptorContainer;
+import org.jboss.ejb3.sandbox.stateless.StatelessInterceptor;
+import org.jboss.ejb3.test.sandbox.performance.Calculator;
+import org.jboss.ejb3.test.sandbox.performance.CalculatorBean;
+import org.jboss.logging.Logger;
+import org.jnp.server.SingletonNamingServer;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class EJBUnitTestCase extends TestCase
+{
+ private static final Logger log = Logger.getLogger(EJBUnitTestCase.class);
+
+ public void test1() throws Throwable
+ {
+ SingletonNamingServer namingServer = new SingletonNamingServer();
+
+ // Bootstrap AOP
+ URL url = Thread.currentThread().getContextClassLoader().getResource("stateless/jboss-aop.xml");
+ log.info("deploying AOP from " + url);
+ AspectXmlLoader.deployXML(url);
+
+ DirectContainer<InterceptorContainer> interceptorContainerContainer = new DirectContainer<InterceptorContainer>("FIXME", "InterceptorContainer", InterceptorContainer.class);
+ Object args[] = { CalculatorBean.class };
+ Class<?> parameterTypes[] = { Class.class };
+ InterceptorContainer interceptorContainer = interceptorContainerContainer.construct(args, parameterTypes);
+
+ InitialContext ctx = new InitialContext();
+
+ Calculator bean = (Calculator) ctx.lookup("CalculatorBean/local");
+
+ assertNotNull(bean);
+
+ System.out.println("BLACKBOX MEASURED STATS:");
+ StressCreator.createStress(bean);
+ //System.err.println(bean.calculatePi(10));
+
+ namingServer.destroy();
+
+ System.out.println("WHITEBOX MEASURED STATS:");
+ System.out.println("Average wait queue " + ((StatelessInterceptor.accumelatedWaitingTime / 100.0) / 1000.0));
+ System.out.println("Average execution " + ((StatelessInterceptor.accumelatedExecutionTime / 100.0) / 1000.0));
+ }
+}
Property changes on: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/EJBUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/MCUnitTestCase.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/MCUnitTestCase.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/MCUnitTestCase.java 2008-02-05 14:20:44 UTC (rev 69621)
@@ -0,0 +1,54 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.sandbox.performance.unit;
+
+
+import junit.framework.TestCase;
+
+import org.jboss.ejb3.sandbox.mc.MC;
+import org.jboss.ejb3.test.sandbox.performance.Calculator;
+import org.jboss.ejb3.test.sandbox.performance.CalculatorBean;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class MCUnitTestCase extends TestCase
+{
+ private static final Logger log = Logger.getLogger(MCUnitTestCase.class);
+
+ public void test1() throws Throwable
+ {
+ MC mc = new MC();
+
+ mc.install("calculator", CalculatorBean.class);
+
+ Calculator calculator = mc.lookup("calculator", Calculator.class);
+
+ //System.out.println(calculator.calculatePi(40));
+
+ StressCreator.createStress(calculator);
+ }
+}
Property changes on: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/MCUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
Added: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/StressCreator.java
===================================================================
--- projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/StressCreator.java (rev 0)
+++ projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/StressCreator.java 2008-02-05 14:20:44 UTC (rev 69621)
@@ -0,0 +1,139 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2007, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.ejb3.test.sandbox.performance.unit;
+
+import static java.util.concurrent.TimeUnit.NANOSECONDS;
+import static java.util.concurrent.TimeUnit.SECONDS;
+
+import java.math.BigDecimal;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Future;
+import java.util.concurrent.SynchronousQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+
+import org.jboss.ejb3.test.sandbox.performance.Calculator;
+import org.jboss.logging.Logger;
+
+/**
+ * Comment
+ *
+ * @author <a href="mailto:carlo.dewolf at jboss.com">Carlo de Wolf</a>
+ * @version $Revision: $
+ */
+public class StressCreator
+{
+ private static final Logger log = Logger.getLogger(StressCreator.class);
+
+ private static class Task implements Callable<BigDecimal>
+ {
+ private Calculator calculator;
+ long enteredQueue;
+ long start, end;
+
+ Task(Calculator calculator)
+ {
+ assert calculator != null : "calculator is null";
+ this.calculator = calculator;
+ enteredQueue = System.currentTimeMillis();
+ }
+
+ public BigDecimal call() throws Exception
+ {
+ start = System.currentTimeMillis();
+ try
+ {
+ return calculator.calculatePi(10000);
+ }
+ finally
+ {
+ end = System.currentTimeMillis();
+ }
+ }
+ }
+
+ public static double createStress(final Calculator calculator)
+ {
+ ExecutorService executor = new ThreadPoolExecutor(0, Integer.MAX_VALUE, Long.MAX_VALUE, NANOSECONDS,
+ new SynchronousQueue<Runnable>());
+ Task tasks[] = new Task[100];
+ Future<BigDecimal> results[] = new Future[100];
+ long start = System.currentTimeMillis();
+ for (int i = 0; i < results.length; i++)
+ {
+ results[i] = executor.submit(tasks[i] = new Task(calculator));
+ }
+ executor.shutdown();
+ try
+ {
+ boolean terminated = executor.awaitTermination(120, SECONDS);
+ if (!terminated)
+ System.err.println("Warning: not terminated");
+ int failures = 0;
+ for (Future<BigDecimal> result : results)
+ {
+ try
+ {
+ result.get();
+ }
+ catch(ExecutionException e)
+ {
+ log.warn(e.getCause().getMessage());
+ failures++;
+ }
+ }
+ long end = System.currentTimeMillis();
+ double d = (end - start) / 1000.0;
+ System.out.println("Took " + d + " seconds");
+
+ long totalWaitQueue = 0;
+ long totalExecution = 0;
+ long maxWaitQueue = 0;
+ long maxExecution = 0;
+ for (Task task : tasks)
+ {
+ long waitQueue = (task.start - task.enteredQueue);
+ long execution = (task.end - task.start);
+ totalWaitQueue += waitQueue;
+ totalExecution += execution;
+ maxWaitQueue = Math.max(maxWaitQueue, waitQueue);
+ maxExecution = Math.max(maxExecution, execution);
+ }
+
+ System.out.println("Average wait queue " + ((totalWaitQueue / 100.0) / 1000.0));
+ System.out.println("Average execution " + ((totalExecution / 100.0) / 1000.0));
+
+ System.out.println("Max wait queue " + (maxWaitQueue / 1000.0));
+ System.out.println("Max execution " + (maxExecution / 1000.0));
+
+ if(failures > 0)
+ System.out.println("WITH " + failures + " FAILURES!");
+
+ return d;
+ }
+ catch (InterruptedException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+}
Property changes on: projects/ejb3/trunk/sandbox/src/test/java/org/jboss/ejb3/test/sandbox/performance/unit/StressCreator.java
___________________________________________________________________
Name: svn:keywords
+ Author Date Id Revision
Name: svn:eol-style
+ native
More information about the jboss-cvs-commits
mailing list