43
6/13/2022 Page 1 of 43 JMS Performance Test Tool Evaluation An experiment

JMS Performance Test Tool Evaluation

Embed Size (px)

Citation preview

Page 1: JMS Performance Test Tool Evaluation

4/10/2023 Page 1 of 29

JMS Performance Test Tool Evaluation

An experiment

Page 2: JMS Performance Test Tool Evaluation

4/10/2023 Page 2 of 29

`

Introduction......................................................................................3

Environment....................................................................................3

Objective..........................................................................................3

Approach..........................................................................................4

Observations....................................................................................4

Tool Evaluation................................................................................5

References........................................................................................6

Appendix..........................................................................................7

Page 3: JMS Performance Test Tool Evaluation

4/10/2023 Page 3 of 29

Introduction

Performance testing primarily involves 3 tasks.1. Drive the load2. Monitor the metrics when the load is hitting the server.3. Analyze the results and present the observations.

A small experiment has been done to see which tool would be good to be used for testing a JMS Product. This document should not be treated as a comprehensive analysis of all the features the tools support but will only summarize the efforts made, to make a simple set of JMS features working through each of the tools under test. JMeter, Grinder, LoadRunner are the tools that have been considered for the experiment. Below is presented a summary of the efforts made for that purpose.

Environment

As a first step, Java MQ server has been installed.

All the performance testing tools required an LDAP server to be setup to run the tests They looked for the LDAP server to build the InitialContext. It is for that purpose OpenDS has been chosen for doing the evaluation.

JConsole has been used to monitor the broker. The support provided in the testing tool can also be used to measure metrics like response times and CPU utilization. However it is to note that response times will include latencies that are brought in by the network connectivity and the number of hops.

Objective

Develop a test case to send/receive to/from a queue.Develop a test case to publish/subscribe to/from a topic.

And

Evaluate the product in terms of the following parameters

Configurable Tool Multithreading Support (Create Multiple Pub/Sub Queue/Topic) Data generating mechanism Ease of Use

Page 4: JMS Performance Test Tool Evaluation

4/10/2023 Page 4 of 29

Java/JMS version support Reporting

Approach

Imqadmin, the default tool provided by Sun JMS has been used and the following objects have been added.

An object store has been added with the following properties

java.naming.provider.url ldap://localhost:389java.naming.factory.initial com.sun.jndi.ldap.LdapCtxFactoryjava.naming.security.principal cn=Directory Managerjava.naming.security.credentials adminjava.naming.security.authentication simple

Created a queue connection factory QCF and a Queue Q1 Created a topic connection factory TCF and a Topic T1

After that, sample clients programs have been written using each of the testing tools to drive load to hit the JMS server.

Observations

1. Each tool provides support for performance testing a JMS product in a different way.

JMeter has a UI based JMS configuration tool for Queues and Topics separately.No coding is required for doing the basic tasks. They may be a necessity for tweaking the tool a bit for achieving what is desired for test.

Grinder

Test Script is configurable and needs  Jython scripting knowledge.Basic examples of queues compile and run ok.

LoadRunner

A java virtual user protocol has to be used to write the test client.

Page 5: JMS Performance Test Tool Evaluation

4/10/2023 Page 5 of 29

Basic examples of queues compile and run ok. Will require java licenses to run the scripts in the controller. Provides very good analysis reports, and the ability to easily put transactions.

Soniq Test Harness

Though this test harness is being told as generic for any JMS product, it requires more effort than expected in terms of setting up the properties and changing stuff related to the Sun product. On top of that it does not provide very good analysis features and lacks features that a performance test tool would have. It can be considered as a framework rather than a tool and hence it has been removed out of the scope for analysis of the tools.

2. None of the tools can be used out-of the-box.

JMeter

Found issues with the FixedQueueExecutor during multi-threading testing.ERROR - jmeter.protocol.jms.sampler.FixedQueueExecutor: Correlation id is null. Set the JMSCorrelationID header

The message fields cannot be set without tweaking the java files and recompiling JMeter.

Grinder

Topic tests fail with compilation error. NO MODULE NAMED THREADING (threading.py). Need more tweaking to be done to the test scripts to get it working.

LoadRunner

Found issues with the topic examples. They compile fine but do not hit the server. Tool reports that messages have been sent but JConsole does not show that the messages are consumed by the broker.

3. Tool Evaluation

Points 1-5 are given against each of the attributes

JMeter Grinder Loadrunner Sonic Test Harness

Configurable Tool

2 3 3 2

Multithreading Support ( Create Multiple Pub/Sub

3 2 3 2

Page 6: JMS Performance Test Tool Evaluation

4/10/2023 Page 6 of 29

Queue/Topic)Data Generating mechanism

2 2 3 2

Ease of Use 4 2 3 1Java/JMS version support

4 3 2 3

Reporting 1 2 4 1

Points 16 14 18 11

References

Sun MQ Serverhttps://mq.dev.java.net

OpenDShttps://opends.dev.java.net/

JConsolehttp://java.sun.com/developer/technicalArticles/J2SE/jconsole.html

Testing Tool Links

JMeter

http://jakarta.apache.org/jmeter/

JMeter Frameworkhttp://jakarta.apache.org/jmeter/usermanual/build-jms-topic-test-plan.htmlhttp://jakarta.apache.org/jmeter/usermanual/build-jms-point-to-point-test-plan.html

Grinderhttp://grinder.sourceforge.net

HP Loadrunnerhttps://h10078.www1.hp.com/cda/hpms/display/main/hpms_content.jsp?zn=bto&cp=1-11-126-17^8_4000_100__

Soniq MQ Test Harnesshttp://www.sonicsoftware.com/products/sonicmq/performance_benchmarking/index.ssp

Page 7: JMS Performance Test Tool Evaluation

4/10/2023 Page 7 of 29

Appendix

JMeter

Point to Point Test Case

<?xml version="1.0" encoding="UTF-8"?><jmeterTestPlan version="1.2" properties="2.1"> <hashTree> <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="PointToPoint" enabled="true"> <stringProp name="TestPlan.comments"></stringProp> <boolProp name="TestPlan.functional_mode">false</boolProp> <boolProp name="TestPlan.serialize_threadgroups">false</boolProp> <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="TestPlan.user_define_classpath"></stringProp> </TestPlan> <hashTree> <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Sender" enabled="true"> <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> <boolProp name="LoopController.continue_forever">false</boolProp> <stringProp name="LoopController.loops">0</stringProp> </elementProp> <stringProp name="ThreadGroup.num_threads">0</stringProp> <stringProp name="ThreadGroup.ramp_time">0</stringProp> <longProp name="ThreadGroup.start_time">1218663512000</longProp> <longProp name="ThreadGroup.end_time">1218663512000</longProp> <boolProp name="ThreadGroup.scheduler">false</boolProp> <stringProp name="ThreadGroup.on_sample_error">stopthread</stringProp> <stringProp name="ThreadGroup.duration"></stringProp> <stringProp name="ThreadGroup.delay"></stringProp> </ThreadGroup> <hashTree> <JMSSampler guiclass="JMSConfigGui" testclass="JMSSampler" testname="LDAP" enabled="true"> <stringProp name="JMSSampler.queueconnectionfactory">cn=QCF;dc=example;dc=com</stringProp>

Page 8: JMS Performance Test Tool Evaluation

4/10/2023 Page 8 of 29

<stringProp name="JMSSampler.SendQueue">cn=Q1;dc=example;dc=com</stringProp> <stringProp name="JMSSampler.ReceiveQueue"></stringProp> <boolProp name="JMSSampler.isFireAndForget">true</boolProp> <boolProp name="JMSSampler.isNonPersistent">false</boolProp> <stringProp name="JMSSampler.timeout">2000</stringProp> <stringProp name="HTTPSamper.xml_data">test</stringProp> <stringProp name="JMSSampler.initialContextFactory"></stringProp> <stringProp name="JMSSampler.contextProviderUrl"></stringProp> <elementProp name="JMSSampler.jndiProperties" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"> <elementProp name="java.naming.provider.url" elementType="Argument"> <stringProp name="Argument.name">java.naming.provider.url</stringProp> <stringProp name="Argument.value">ldap://localhost:389</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="java.naming.factory.initial" elementType="Argument"> <stringProp name="Argument.name">java.naming.factory.initial</stringProp> <stringProp name="Argument.value">com.sun.jndi.ldap.LdapCtxFactory</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="java.naming.security.principal" elementType="Argument"> <stringProp name="Argument.name">java.naming.security.principal</stringProp> <stringProp name="Argument.value">cn=Directory Manager</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="java.naming.security.credentials" elementType="Argument"> <stringProp name="Argument.name">java.naming.security.credentials</stringProp> <stringProp name="Argument.value">admin</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> </collectionProp> </elementProp> <elementProp name="arguments" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> </JMSSampler>

Page 9: JMS Performance Test Tool Evaluation

4/10/2023 Page 9 of 29

<hashTree/> <ResultCollector guiclass="GraphVisualizer" testclass="ResultCollector" testname="Graph Results" enabled="true"> <boolProp name="ResultCollector.error_logging">false</boolProp> <objProp> <name>saveConfig</name> <value class="SampleSaveConfiguration"> <time>true</time> <latency>true</latency> <timestamp>true</timestamp> <success>true</success> <label>true</label> <code>true</code> <message>true</message> <threadName>true</threadName> <dataType>true</dataType> <encoding>false</encoding> <assertions>true</assertions> <subresults>true</subresults> <responseData>false</responseData> <samplerData>false</samplerData> <xml>true</xml> <fieldNames>false</fieldNames> <responseHeaders>false</responseHeaders> <requestHeaders>false</requestHeaders> <responseDataOnError>false</responseDataOnError> <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage> <assertionsResultsToSave>0</assertionsResultsToSave> <bytes>true</bytes> </value> </objProp> <stringProp name="filename"></stringProp> </ResultCollector> <hashTree/> </hashTree> <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Sender-Receiver" enabled="true"> <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> <boolProp name="LoopController.continue_forever">false</boolProp> <intProp name="LoopController.loops">-1</intProp> </elementProp> <stringProp name="ThreadGroup.num_threads">1</stringProp> <stringProp name="ThreadGroup.ramp_time">1</stringProp>

Page 10: JMS Performance Test Tool Evaluation

4/10/2023 Page 10 of 29

<longProp name="ThreadGroup.start_time">1218728091000</longProp> <longProp name="ThreadGroup.end_time">1218728091000</longProp> <boolProp name="ThreadGroup.scheduler">false</boolProp> <stringProp name="ThreadGroup.on_sample_error">continue</stringProp> <stringProp name="ThreadGroup.duration"></stringProp> <stringProp name="ThreadGroup.delay"></stringProp> </ThreadGroup> <hashTree> <JMSSampler guiclass="JMSConfigGui" testclass="JMSSampler" testname="LDAP" enabled="true"> <stringProp name="JMSSampler.queueconnectionfactory">cn=QCF;dc=example;dc=com</stringProp> <stringProp name="JMSSampler.SendQueue">cn=Q1;dc=example;dc=com</stringProp> <stringProp name="JMSSampler.ReceiveQueue">cn=Q1;dc=example;dc=com</stringProp> <boolProp name="JMSSampler.isFireAndForget">false</boolProp> <boolProp name="JMSSampler.isNonPersistent">false</boolProp> <stringProp name="JMSSampler.timeout">2000</stringProp> <stringProp name="HTTPSamper.xml_data">test</stringProp> <stringProp name="JMSSampler.initialContextFactory"></stringProp> <stringProp name="JMSSampler.contextProviderUrl"></stringProp> <elementProp name="JMSSampler.jndiProperties" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"> <elementProp name="java.naming.provider.url" elementType="Argument"> <stringProp name="Argument.name">java.naming.provider.url</stringProp> <stringProp name="Argument.value">ldap://localhost:389</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="java.naming.factory.initial" elementType="Argument"> <stringProp name="Argument.name">java.naming.factory.initial</stringProp> <stringProp name="Argument.value">com.sun.jndi.ldap.LdapCtxFactory</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> <elementProp name="java.naming.security.principal" elementType="Argument"> <stringProp name="Argument.name">java.naming.security.principal</stringProp> <stringProp name="Argument.value">cn=Directory Manager</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp>

Page 11: JMS Performance Test Tool Evaluation

4/10/2023 Page 11 of 29

<elementProp name="java.naming.security.credentials" elementType="Argument"> <stringProp name="Argument.name">java.naming.security.credentials</stringProp> <stringProp name="Argument.value">admin</stringProp> <stringProp name="Argument.metadata">=</stringProp> </elementProp> </collectionProp> </elementProp> <elementProp name="arguments" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> </JMSSampler> <hashTree> <ResultCollector guiclass="GraphVisualizer" testclass="ResultCollector" testname="Graph Results" enabled="true"> <boolProp name="ResultCollector.error_logging">false</boolProp> <objProp> <name>saveConfig</name> <value class="SampleSaveConfiguration"> <time>true</time> <latency>true</latency> <timestamp>true</timestamp> <success>true</success> <label>true</label> <code>true</code> <message>true</message> <threadName>true</threadName> <dataType>true</dataType> <encoding>false</encoding> <assertions>true</assertions> <subresults>true</subresults> <responseData>false</responseData> <samplerData>false</samplerData> <xml>true</xml> <fieldNames>false</fieldNames> <responseHeaders>false</responseHeaders> <requestHeaders>false</requestHeaders> <responseDataOnError>false</responseDataOnError> <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage> <assertionsResultsToSave>0</assertionsResultsToSave> <bytes>true</bytes> </value>

Page 12: JMS Performance Test Tool Evaluation

4/10/2023 Page 12 of 29

</objProp> <stringProp name="filename"></stringProp> </ResultCollector> <hashTree/> </hashTree> </hashTree> </hashTree> </hashTree></jmeterTestPlan>

Publisher- Subscriber Test

<?xml version="1.0" encoding="UTF-8"?><jmeterTestPlan version="1.2" properties="2.1"> <hashTree> <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="PubSub" enabled="true"> <stringProp name="TestPlan.comments"></stringProp> <boolProp name="TestPlan.functional_mode">false</boolProp> <boolProp name="TestPlan.serialize_threadgroups">false</boolProp> <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true"> <collectionProp name="Arguments.arguments"/> </elementProp> <stringProp name="TestPlan.user_define_classpath"></stringProp> </TestPlan> <hashTree> <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Publisher" enabled="true"> <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> <boolProp name="LoopController.continue_forever">false</boolProp> <stringProp name="LoopController.loops">1</stringProp> </elementProp> <stringProp name="ThreadGroup.num_threads">1</stringProp> <stringProp name="ThreadGroup.ramp_time">0</stringProp> <longProp name="ThreadGroup.start_time">1218729150000</longProp> <longProp name="ThreadGroup.end_time">1218729150000</longProp> <boolProp name="ThreadGroup.scheduler">false</boolProp> <stringProp name="ThreadGroup.on_sample_error">stoptest</stringProp> <stringProp name="ThreadGroup.duration"></stringProp> <stringProp name="ThreadGroup.delay"></stringProp> </ThreadGroup>

Page 13: JMS Performance Test Tool Evaluation

4/10/2023 Page 13 of 29

<hashTree> <PublisherSampler guiclass="JMSPublisherGui" testclass="PublisherSampler" testname="LDAP" enabled="true"> <stringProp name="jms.jndi_properties">false</stringProp> <stringProp name="jms.initial_context_factory">com.sun.jndi.ldap.LdapCtxFactory</stringProp> <stringProp name="jms.provider_url">ldap://localhost:389</stringProp> <stringProp name="jms.connection_factory">cn=TCF;dc=example;dc=com</stringProp> <stringProp name="jms.topic">cn=T1;dc=example;dc=com</stringProp> <stringProp name="jms.security_principle">cn=Directory Manager</stringProp> <stringProp name="jms.security_credentials">admin</stringProp> <stringProp name="jms.text_message">test</stringProp> <stringProp name="jms.input_file"></stringProp> <stringProp name="jms.random_path"></stringProp> <stringProp name="jms.config_choice">Textarea</stringProp> <stringProp name="jms.config_msg_type">Text Message</stringProp> <stringProp name="jms.iterations">10</stringProp> <stringProp name="jms.authenticate">Required</stringProp> </PublisherSampler> <hashTree> <ResultCollector guiclass="GraphVisualizer" testclass="ResultCollector" testname="Graph Results" enabled="true"> <boolProp name="ResultCollector.error_logging">false</boolProp> <objProp> <name>saveConfig</name> <value class="SampleSaveConfiguration"> <time>true</time> <latency>true</latency> <timestamp>true</timestamp> <success>true</success> <label>true</label> <code>true</code> <message>true</message> <threadName>true</threadName> <dataType>true</dataType> <encoding>false</encoding> <assertions>true</assertions> <subresults>true</subresults> <responseData>false</responseData> <samplerData>false</samplerData> <xml>true</xml> <fieldNames>false</fieldNames> <responseHeaders>false</responseHeaders> <requestHeaders>false</requestHeaders> <responseDataOnError>false</responseDataOnError>

Page 14: JMS Performance Test Tool Evaluation

4/10/2023 Page 14 of 29

<saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage> <assertionsResultsToSave>0</assertionsResultsToSave> <bytes>true</bytes> </value> </objProp> <stringProp name="filename"></stringProp> </ResultCollector> <hashTree/> </hashTree> </hashTree> <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Subscriber" enabled="true"> <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true"> <boolProp name="LoopController.continue_forever">false</boolProp> <stringProp name="LoopController.loops">10</stringProp> </elementProp> <stringProp name="ThreadGroup.num_threads">1</stringProp> <stringProp name="ThreadGroup.ramp_time">0</stringProp> <longProp name="ThreadGroup.start_time">1218729154000</longProp> <longProp name="ThreadGroup.end_time">1218729154000</longProp> <boolProp name="ThreadGroup.scheduler">false</boolProp> <stringProp name="ThreadGroup.on_sample_error">stopthread</stringProp> <stringProp name="ThreadGroup.duration"></stringProp> <stringProp name="ThreadGroup.delay"></stringProp> </ThreadGroup> <hashTree> <SubscriberSampler guiclass="JMSSubscriberGui" testclass="SubscriberSampler" testname="LDAP" enabled="true"> <stringProp name="jms.jndi_properties">false</stringProp> <stringProp name="jms.initial_context_factory">com.sun.jndi.ldap.LdapCtxFactory</stringProp> <stringProp name="jms.provider_url">ldap://localhost:389</stringProp> <stringProp name="jms.connection_factory">cn=TCF;dc=example;dc=com</stringProp> <stringProp name="jms.topic">cn=T1;dc=example;dc=com</stringProp> <stringProp name="jms.security_principle">cn=Directory Manager</stringProp> <stringProp name="jms.security_credentials">admin</stringProp> <stringProp name="jms.authenticate">Required</stringProp> <stringProp name="jms.iterations"></stringProp> <stringProp name="jms.read_response">true</stringProp> <stringProp name="jms.client_choice">Use TopicSubscriber.receive()</stringProp> </SubscriberSampler>

Page 15: JMS Performance Test Tool Evaluation

4/10/2023 Page 15 of 29

<hashTree/> </hashTree> </hashTree> </hashTree></jmeterTestPlan>

LoadRunner

Point to Point Test

Sender

/* * LoadRunner Java script. (Build: 946) * * Script Description: * */

import lrapi.lr;import javax.jms.*;import javax.naming.*;import java.util.Hashtable;

public class Actions{

Hashtable env; Context ctx = null; Session session=null; Connection connection=null; ConnectionFactory cf = null; Destination destination=null; MessageProducer producer=null;

public int init() throws Throwable {env = new Hashtable();

// Store the environment variables that tell JNDI which initial context// to use and where to find the provider.

env.put(Context.PROVIDER_URL,"ldap://localhost:389");

env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");

Page 16: JMS Performance Test Tool Evaluation

4/10/2023 Page 16 of 29

env.put(Context.SECURITY_PRINCIPAL,"cn=Directory Manager");env.put(Context.SECURITY_CREDENTIALS,"admin");

try { // Create the initial context. ctx = new InitialContext(env);} catch (NamingException ex) { ex.printStackTrace(); System.exit(-1);}

// creating a connection factory

try {// Lookup my connection factory from the admin object store.// The name used here here must match the lookup name// used when the admin object was stored.cf = (javax.jms.ConnectionFactory)

ctx.lookup("cn=QCF;dc=example;dc=com");System.out.println("Connection Factory object found.");

} catch (NamingException ne) {System.err.println("Failed to lookup Connection Factory object.");ne.printStackTrace();System.exit(-1);

}

// create a consnection connection = cf.createConnection();

// create a session session = connection.createSession(

false /* not transacted */, Session.AUTO_ACKNOWLEDGE);

// create destination HelloWorld destination = session.createQueue("Q1");

return 0; }//end of init

public int action() throws Throwable {

try{

Page 17: JMS Performance Test Tool Evaluation

4/10/2023 Page 17 of 29

// create a producer producer = session.createProducer(destination);

// now that everything is ready to go, start the connection connection.start();

// create our message to send TextMessage message = session.createTextMessage(); message.setText("Hello World");

// send the message to Queue HelloWorld System.out.println("Sending Hello World"); producer.send(message);

} catch (JMSException ex) { System.out.println("Error running program"); ex.printStackTrace(); }

return 0;}//end of action

public int end() throws Throwable { // close everything producer.close(); session.close(); connection.close();

return 0;}//end of end

}

Receiver

/* * LoadRunner Java script. (Build: 946) * * Script Description: * */

Page 18: JMS Performance Test Tool Evaluation

4/10/2023 Page 18 of 29

import lrapi.lr;import javax.jms.*;import javax.naming.*;import java.util.Hashtable;

public class Actions{

Hashtable env; Context ctx = null; Session session=null; Connection connection=null; ConnectionFactory cf = null; Destination destination=null; MessageConsumer consumer=null;

public int init() throws Throwable { env = new Hashtable();

// Store the environment variables that tell JNDI which initial context // to use and where to find the provider.

env.put(Context.PROVIDER_URL,"ldap://localhost:389");

env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.SECURITY_PRINCIPAL,"cn=Directory Manager"); env.put(Context.SECURITY_CREDENTIALS,"admin");

try { // Create the initial context. ctx = new InitialContext(env);

} catch (NamingException ex) {ex.printStackTrace();System.exit(-1);

}

// creating a connection factory

try { // Lookup my connection factory from the admin object store. // The name used here here must match the lookup name // used when the admin object was stored. cf = (javax.jms.ConnectionFactory)

ctx.lookup("cn=QCF;dc=example;dc=com"); System.out.println("Connection Factory object found.");

Page 19: JMS Performance Test Tool Evaluation

4/10/2023 Page 19 of 29

} catch (NamingException ne) { System.err.println("Failed to lookup Connection Factory object."); ne.printStackTrace(); System.exit(-1);

}

// create a consnection connection = cf.createConnection();

// create a session session = connection.createSession(

false /* not transacted */, Session.AUTO_ACKNOWLEDGE);

// create destination HelloWorld destination = session.createQueue("Q1");

return 0;}//end of init

public int action() throws Throwable {

try {

// create a consumer consumer = session.createConsumer(destination);

// now that everything is ready to go, start the connection connection.start();

// receive our message TextMessage m = (TextMessage)consumer.receive();

System.out.println(m.getText());

} catch (JMSException ex) { System.out.println("Error running program"); ex.printStackTrace(); }

Page 20: JMS Performance Test Tool Evaluation

4/10/2023 Page 20 of 29

return 0;}//end of action

public int end() throws Throwable { // close everything consumer.close(); session.close(); connection.close();

return 0;}//end of end

}

Publish – Subscribe Test

Publisher

/* * LoadRunner Java script. (Build: 946) * * Script Description: * */

import lrapi.lr;import javax.jms.*;import javax.naming.*;import java.util.Hashtable;

public class Actions{

Hashtable env; Context ctx = null; Session session=null; Connection connection=null; ConnectionFactory cf = null;

Destination destination=null; TopicPublisher publisher=null;

Page 21: JMS Performance Test Tool Evaluation

4/10/2023 Page 21 of 29

public int init() throws Throwable {env = new Hashtable();

// Store the environment variables that tell JNDI which initial context// to use and where to find the provider.

env.put(Context.PROVIDER_URL,"ldap://localhost:389");

env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.SECURITY_PRINCIPAL,"cn=Directory Manager");env.put(Context.SECURITY_CREDENTIALS,"admin");

try { // Create the initial context. ctx = new InitialContext(env);} catch (NamingException ex) { ex.printStackTrace(); System.exit(-1);}

// creating a connection factory

try {// Lookup my connection factory from the admin object store.// The name used here here must match the lookup name// used when the admin object was stored.cf = (javax.jms.ConnectionFactory)

ctx.lookup("cn=TCF;dc=example;dc=com");System.out.println("Connection Factory object found." +cf.toString());

} catch (NamingException ne) {System.err.println("Failed to lookup Connection Factory object.");ne.printStackTrace();System.exit(-1);

}

// create a consnection connection = cf.createConnection();

// create a session session = connection.createSession(

false /* not transacted */, Session.AUTO_ACKNOWLEDGE);

// create destination HelloWorld destination = session.createTopic("T1");

Page 22: JMS Performance Test Tool Evaluation

4/10/2023 Page 22 of 29

return 0; }//end of init

public int action() throws Throwable {

try{

// create a publisher publisher = (TopicPublisher)session.createProducer(destination);

// now that everything is ready to go, start the connection connection.start();

// create our message to send TextMessage message = session.createTextMessage(); message.setText("Hello World");

// send the message publisher.publish(message);

System.out.println("Sent Hello World" + publisher);

} catch (JMSException ex) { System.out.println("Error running program"); ex.printStackTrace(); }

return 0;}//end of action

public int end() throws Throwable { // close everything publisher.close(); session.close(); connection.close();

publisher=null; session=null; connection=null;

Page 23: JMS Performance Test Tool Evaluation

4/10/2023 Page 23 of 29

return 0;}//end of end

}

Subscriber

/* * LoadRunner Java script. (Build: 946) * * Script Description: * */

import lrapi.lr;import javax.jms.*;import javax.naming.*;import java.util.Hashtable;

public class Actions{

Hashtable env; Context ctx = null; Session session=null; Connection connection=null; ConnectionFactory cf = null; Destination destination=null; MessageConsumer consumer=null;

public int init() throws Throwable { env = new Hashtable();

// Store the environment variables that tell JNDI which initial context // to use and where to find the provider.

env.put(Context.PROVIDER_URL,"ldap://localhost:389");

env.put(Context.INITIAL_CONTEXT_FACTORY,"com.sun.jndi.ldap.LdapCtxFactory");

env.put(Context.SECURITY_PRINCIPAL,"cn=Directory Manager"); env.put(Context.SECURITY_CREDENTIALS,"admin");

try { // Create the initial context. ctx = new InitialContext(env);

Page 24: JMS Performance Test Tool Evaluation

4/10/2023 Page 24 of 29

} catch (NamingException ex) {ex.printStackTrace();System.exit(-1);

}

// creating a connection factory

try { // Lookup my connection factory from the admin object store. // The name used here here must match the lookup name // used when the admin object was stored. cf = (javax.jms.ConnectionFactory)

ctx.lookup("cn=QCF;dc=example;dc=com"); System.out.println("Connection Factory object found.");

} catch (NamingException ne) { System.err.println("Failed to lookup Connection Factory object."); ne.printStackTrace(); System.exit(-1);

}

// create a consnection connection = cf.createConnection();

// create a session session = connection.createSession(

false /* not transacted */, Session.AUTO_ACKNOWLEDGE);

// create destination HelloWorld destination = session.createQueue("Q1");

return 0;}//end of init

public int action() throws Throwable {

try {

// create a consumer consumer = session.createConsumer(destination);

// now that everything is ready to go, start the connection

Page 25: JMS Performance Test Tool Evaluation

4/10/2023 Page 25 of 29

connection.start();

// receive our message TextMessage m = (TextMessage)consumer.receive();

System.out.println(m.getText());

} catch (JMSException ex) { System.out.println("Error running program"); ex.printStackTrace(); }

return 0;}//end of action

public int end() throws Throwable { // close everything consumer.close(); session.close(); connection.close();

return 0;}//end of end

}

Grinder

Point to Point Test

# Java Message Service - Queue Sender## JMS objects are looked up and messages are created once during# initialisation. This default JNDI names are for the WebLogic Server# 7.0 examples domain - change accordingly.## Each worker thread:# - Creates a queue session# - Sends ten messages# - Closes the queue session

from net.grinder.script.Grinder import grinderfrom net.grinder.script import Test

Page 26: JMS Performance Test Tool Evaluation

4/10/2023 Page 26 of 29

from jarray import zerosfrom java.util import Properties, Randomfrom javax.jms import Sessionfrom javax.naming import Context, InitialContext

# Look up connection factory and queue in JNDI.properties = Properties()properties[Context.PROVIDER_URL] = "ldap://localhost:389"properties[Context.INITIAL_CONTEXT_FACTORY] = "com.sun.jndi.ldap.LdapCtxFactory"properties[Context.SECURITY_PRINCIPAL] = "cn=Directory Manager"properties[Context.SECURITY_CREDENTIALS] = "admin"

initialContext = InitialContext(properties)

connectionFactory = initialContext.lookup("cn=QCF;dc=example;dc=com")queue = initialContext.lookup("cn=Q1;dc=example;dc=com")initialContext.close()

# Create a connection.connection = connectionFactory.createQueueConnection()connection.start()

random = Random()

def createBytesMessage(session, size): bytes = zeros(size, 'b') random.nextBytes(bytes) message = session.createBytesMessage() message.writeBytes(bytes) return message

class TestRunner: def __call__(self): log = grinder.logger.output

log("Creating queue session") session = connection.createQueueSession(0, Session.AUTO_ACKNOWLEDGE)

sender = session.createSender(queue) instrumentedSender = Test(1, "Send a message").wrap(sender)

message = createBytesMessage(session, 100)

log("Sending ten messages")

Page 27: JMS Performance Test Tool Evaluation

4/10/2023 Page 27 of 29

for i in range(0, 10): instrumentedSender.send(message) grinder.sleep(100)

log("Closing queue session") session.close()

Publish – Subscribe Test

# Java Message Service - Queue Receiver## JMS objects are looked up and messages are created once during# initialisation. This default JNDI names are for the WebLogic Server# 7.0 examples domain - change accordingly.## Each worker thread:# - Creates a queue session# - Receives ten messages# - Closes the queue session## This script demonstrates the use of The Grinder statistics API to# record a "delivery time" custom statistic.## Copyright (C) 2003, 2004, 2005, 2006 Philip Aston# Copyright (C) 2005 Dietrich Bollmann# Distributed under the terms of The Grinder license.

from java.lang import Systemfrom java.util import Propertiesfrom javax.jms import MessageListener, Sessionfrom javax.naming import Context, InitialContextfrom net.grinder.script.Grinder import grinderfrom net.grinder.script import Testfrom threading import Condition

# Look up connection factory and queue in JNDI.properties = Properties()properties[Context.PROVIDER_URL] = "ldap://localhost:389"properties[Context.INITIAL_CONTEXT_FACTORY] = "com.sun.jndi.ldap.LdapCtxFactory"properties[Context.SECURITY_PRINCIPAL] = "cn=Directory Manager"properties[Context.SECURITY_CREDENTIALS] = "admin"

initialContext = InitialContext(properties)

Page 28: JMS Performance Test Tool Evaluation

4/10/2023 Page 28 of 29

connectionFactory = initialContext.lookup("cn=QCF;dc=example;dc=com")queue = initialContext.lookup("cn=Q1;dc=example;dc=com")initialContext.close()

# Create a connection.connection = connectionFactory.createQueueConnection()connection.start()

# Add two statistics expressions:# 1. Delivery time:- the mean time taken between the server sending# the message and the receiver receiving the message.# 2. Mean delivery time:- the delivery time averaged over all tests.# We use the userLong0 statistic to represent the "delivery time".

grinder.statistics.registerDataLogExpression("Delivery time", "userLong0")

#grinder.statistics.registerSummaryExpression(# "Mean delivery time",# "(/ userLong0(+ timedTests untimedTests))")

# We record each message receipt against a single test. The# test time is meaningless.def recordDeliveryTime(deliveryTime): grinder.statistics.forCurrentTest.setValue("userLong0", deliveryTime)

recordTest = Test(1, "Receive messages").wrap(recordDeliveryTime)

class TestRunner(MessageListener):

def __init__(self): self.messageQueue = [] # Queue of received messages not yet recorded. self.cv = Condition() # Used to synchronise thread activity.

def __call__(self): log = grinder.logger.output

log("Creating queue session and a receiver") session = connection.createQueueSession(0, Session.AUTO_ACKNOWLEDGE)

receiver = session.createReceiver(queue) receiver.messageListener = self

Read 10 messages from the queue. for i in range(0, 10):

Page 29: JMS Performance Test Tool Evaluation

4/10/2023 Page 29 of 29

# Wait until we have received a message. self.cv.acquire() #while not self.messageQueue: self.cv.wait() # Pop delivery time from first message in message queue deliveryTime = messageQueue.pop(0) self.cv.release()

log("Received message")

# We record the test a here rather than in onMessage # because we must do so from a worker thread. recordTest(deliveryTime)

log("Closing queue session") session.close()

# Rather than over complicate things with explict message # acknowledgement, we simply discard any additional messages # we may have read. log("Received %d additional messages" % len(self.messageQueue))

# Called asynchronously by JMS when a message arrives. def onMessage(self, message): self.cv.acquire()

# In WebLogic Server JMS, the JMS timestamp is set by the # sender session. All we need to do is ensure our clocks are # synchronised... deliveryTime = System.currentTimeMillis() - message.getJMSTimestamp()

self.messageQueue.append(deliveryTime)

self.cv.notifyAll() self.cv.release()