What tool may i to spawn multiple threads to EJB 2.1 codes to simulate connection pool load?
i am trying to spawn multiple threads on an EJB 2.1 bean to test the load on the connection pool. Is there any way of doing so or open source tool i may look into?
Thanks if an开发者_StackOverflow社区yone has any experience in this.
Wrap your calls to your EJBs in a Servlet. There are a variety of tools in various languages to simulate load on web apps.
I use The Grinder for load testing OpenEJB. It's pretty great.
An example of a grinder.py file. This is essentially the client:
from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from javax.naming import Context,InitialContext
from java.util import Properties
# A shorter alias for the grinder.logger.output() method.
log = grinder.logger.output
tests = {
"ping" : Test(1, "ping"),
"add" : Test(2, "add"),
"sum" : Test(3, "sum"),
}
# Wrap the log() method with our Test and call the result logWrapper.
# Calls to logWrapper() will be recorded and forwarded on to the real
# log() method.
#logWrapper = test1.wrap(log)
# Initial context lookup for EJB home.
p = Properties()
p[Context.INITIAL_CONTEXT_FACTORY] = "org.apache.openejb.client.RemoteInitialContextFactory"
p[Context.PROVIDER_URL] = "ejbd://127.0.0.1:4201";
loadBean = InitialContext(p).lookup("LoadBeanRemote")
pingBean = tests["ping"].wrap(loadBean)
addBean = tests["add"].wrap(loadBean)
sumBean = tests["sum"].wrap(loadBean)
# A TestRunner instance is created for each thread. It can be used to
# store thread-specific data.
class TestRunner:
# This method is called for every run.
def __call__(self):
pingBean.ping()
addBean.add(3, 4)
sumBean.sum([3, 4, 5, 6])
Note the grinder.py file is written in jython so you can hookup any java client jars.
Here's an example grinder.properties file:
grinder.script grinder.py
grinder.processes 2
grinder.threads 20
grinder.runs 0
grinder.jvm.classpath=/Users/dblevins/work/grinder/openejb-3.1.4/lib/openejb-client-3.1.4.jar:\
/Users/dblevins/work/grinder/openejb-3.1.4/lib/javaee-api-5.0-3.jar:\
/Users/dblevins/work/grinder/openejb-3.1.4/lib/ejb31-experimental-api-3.1.4.jar:\
/Users/dblevins/work/grinder/load-beans/target/load-beans-1.0.jar
grinder.logDirectory logs
grinder.numberOfOldLogs 0
Then the LoadBean looks like so (the app you want to load test):
package org.superbiz.load;
import javax.ejb.*;
import java.lang.reflect.Method;
@Local
@Remote
@Singleton
@Lock(LockType.READ)
public class LoadBean implements Load {
public void ping() {
// do nothing
}
public int add(int a, int b) {
return a + b;
}
public int sum(int... items) {
int i = 0;
for (int item : items) {
i += item;
}
return i;
}
}
精彩评论