You are viewing a plain text version of this content. The canonical link for it is here.
Posted to wsif-dev@ws.apache.org by an...@apache.org on 2003/01/31 18:34:31 UTC
cvs commit: xml-axis-wsif/java/test/performance JavaPerfTest.java Monitor.java
antelder 2003/01/31 09:34:31
Modified: java/test/performance Monitor.java
Added: java/test/performance JavaPerfTest.java
Log:
Update Monitor to include a weighting so you can see where the time really is.
Commit the performance test I use for the Java provider
Revision Changes Path
1.7 +39 -6 xml-axis-wsif/java/test/performance/Monitor.java
Index: Monitor.java
===================================================================
RCS file: /home/cvs/xml-axis-wsif/java/test/performance/Monitor.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- Monitor.java 9 Dec 2002 16:43:21 -0000 1.6
+++ Monitor.java 31 Jan 2003 17:34:30 -0000 1.7
@@ -59,6 +59,7 @@
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Collections;
+import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
@@ -70,7 +71,21 @@
public class Monitor {
static HashMap timers = new HashMap();
+ static long start;
+ static long stop;
+ public static void start() {
+ start = System.currentTimeMillis();
+ }
+
+ public static void stop() {
+ stop = System.currentTimeMillis();
+ }
+
+ public static long getTotalTime() {
+ return stop - start;
+ }
+
public static void start(String s) {
Timer t = (Timer)timers.get( s );
if ( t == null ) {
@@ -101,6 +116,7 @@
public static void clear() {
timers = new HashMap();
+ start = System.currentTimeMillis();
}
public static HashMap getAvgResults() {
@@ -123,24 +139,37 @@
float value;
ArrayList l = new ArrayList();
for (Iterator i = timers.keySet().iterator(); i.hasNext(); ) {
+ l.add( timers.get((String)i.next()) );
+ }
+ Collections.sort( l, new Comparator() {
+ public int compare(Object o1, Object o2) {
+ return Math.round(((Timer)o1).getTotalTime() - ((Timer)o2).getTotalTime());
+ }
+ } );
+ long maxWeight = ((Timer) l.get(l.size()-1)).getTotalTime();
+
+ l = new ArrayList();
+ for (Iterator i = timers.keySet().iterator(); i.hasNext(); ) {
l.add( i.next() );
}
+ Collections.sort( l);
- Collections.sort( l );
- DecimalFormat formatter = new DecimalFormat("#0.00000");
+ System.out.println( "\n=== Monitor Results === (total time= " + getTotalTime() + " msecs)\n" );
+ System.out.println(
+ "Test Name Weight Avg Time Total count");
- System.out.println( "\n=== Monitor Results ===\n" );
+ DecimalFormat formatter = new DecimalFormat("#0.00000");
for (Iterator i = l.iterator(); i.hasNext(); ) {
testName = (String)i.next();
t = (Timer)timers.get( testName );
- //value = ((float)Math.round( t.getAvgTime() * 10000 ) / 10000 );
- System.out.println( pad(testName,40) +
+ int weight = Math.round((float)t.getTotalTime() / maxWeight * 100);
+ System.out.println( pad(testName,50) + lpad( ""+weight, 8 ) +
" value=" + lpad(formatter.format( t.getAvgTime() ),8) + " msecs" +
", samples= " + lpad( ""+t.getIterations(), 8 ) );
}
System.out.println();
}
-
+
public static String pad(String s, int pad) {
if ( s==null ) s = "";
StringBuffer sb = new StringBuffer( pad );
@@ -220,6 +249,10 @@
public int getIterations() {
return startCount;
+ }
+
+ public long getTotalTime() {
+ return totalTime;
}
}
1.1 xml-axis-wsif/java/test/performance/JavaPerfTest.java
Index: JavaPerfTest.java
===================================================================
/*
* The Apache Software License, Version 1.1
*
*
* Copyright (c) 2002 The Apache Software Foundation. All rights
* reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in
* the documentation and/or other materials provided with the
* distribution.
*
* 3. The end-user documentation included with the redistribution,
* if any, must include the following acknowledgment:
* "This product includes software developed by the
* Apache Software Foundation (http://www.apache.org/)."
* Alternately, this acknowledgment may appear in the software itself,
* if and wherever such third-party acknowledgments normally appear.
*
* 4. The names "WSIF" and "Apache Software Foundation" must
* not be used to endorse or promote products derived from this
* software without prior written permission. For written
* permission, please contact apache@apache.org.
*
* 5. Products derived from this software may not be called "Apache",
* nor may "Apache" appear in their name, without prior written
* permission of the Apache Software Foundation.
*
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
* ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
* USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
* OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
* ====================================================================
*
* This software consists of voluntary contributions made by many
* individuals on behalf of the Apache Software Foundation and was
* originally based on software copyright (c) 2001, 2002, International
* Business Machines, Inc., http://www.apache.org. For more
* information on the Apache Software Foundation, please see
* <http://www.apache.org/>.
*/
package performance;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Properties;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.wsif.WSIFMessage;
import org.apache.wsif.WSIFOperation;
import org.apache.wsif.WSIFPort;
import org.apache.wsif.WSIFService;
import org.apache.wsif.WSIFServiceFactory;
import org.apache.wsif.base.WSIFServiceImpl;
import util.AddressUtility;
import util.TestUtilities;
import addressbook.wsifservice.AddressBook;
import addressbook.wsiftypes.Address;
import addressbook.wsiftypes.Phone;
/**
* Junit test to measure the performance of the WSIF Java provider.
*
* based on the SpeedTest testcase.
*
* @author <a href="mailto:antelder@apache.org">Ant Elder</a>
*/
public class JavaPerfTest extends TestCase {
static final int DEFAULT_ITERATIONS = 1000000;
static final String wsdlLocation =
TestUtilities.getWsdlPath("java\\test\\addressbook\\wsifservice")
+ "AddressBook.wsdl";
static String name1 = "Purdue Boilermaker";
static Address addr1 =
new Address(
1,
"University Drive",
"West Lafayette",
"IN",
47907,
new Phone(765, "494", "4900"));
static String firstName2 = "Someone";
static String lastName2 = "Else";
static Address addr2 =
new Address(
0,
"Somewhere Else",
"No Where",
"NO",
71983,
new Phone(600, "391", "5682"));
public JavaPerfTest(String name) {
super(name);
}
public static void main(String[] args) {
// TestUtilities.startListeners();
junit.textui.TestRunner.run (suite());
// TestUtilities.stopListeners();
}
public static Test suite() {
TestSuite suite = new TestSuite("Speed Tests");
suite.addTest(new TestSuite(JavaPerfTest.class) );
//suite.addTest(new TestSuite(SpeedTest.class) );
//suite.addTest(new TestSuite(SpeedTest.class) );
return suite;
}
public void setUp() {
TestUtilities.setUpExtensionsAndProviders();
Monitor.clear();
}
public void testJavaDyn() {
doitDyn("JavaPort", "java");
}
public void testJavaDynTotal() {
doitDynTotal("JavaPort", "java");
}
public void testJavaStub() {
doitStub("JavaPort", "java");
}
public void testJavaStubTotal() {
doitStubTotal("JavaPort", "java");
}
private void doitDyn(String portName, String protocol) {
int iterations;
String testName;
// String testNamePrefix = "doitDyn" + protocol + "." + portName;
String testNamePrefix = "doitDyn";
Monitor.clear();
if (portName.toUpperCase().indexOf("JMS") != -1
&& !TestUtilities.areWeTesting("jms"))
return;
TestUtilities.setProviderForProtocol( protocol );
try {
WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
WSIFService service = factory.getService(wsdlLocation, null, // serviceNS
null, // serviceName
"http://wsifservice.addressbook/", // portTypeNS
"AddressBook"); // portTypeName
service.mapType(
new javax.xml.namespace.QName(
"http://wsiftypes.addressbook/",
"address"),
Class.forName("addressbook.wsiftypes.Address"));
service.mapType(
new javax.xml.namespace.QName(
"http://wsiftypes.addressbook/",
"phone"),
Class.forName("addressbook.wsiftypes.Phone"));
WSIFPort port = null;
port = service.getPort(portName);
Monitor.start();
/*
* Run iterations of getPort
*/
testName = testNamePrefix + ".getPort";
iterations = DEFAULT_ITERATIONS;
// iterations = 1;
System.out.println( "running " + iterations + " " + testName + " iterations..." );
for (int i = 0; i < iterations; i++ ) {
Monitor.start( testName );
port = service.getPort(portName);
Monitor.stop( testName );
}
WSIFOperation operation =
port.createOperation("addEntry", "AddEntryWholeNameRequest", null);
WSIFMessage inputMessage = operation.createInputMessage();
WSIFMessage outputMessage = operation.createOutputMessage();
WSIFMessage faultMessage = operation.createFaultMessage();
// Create a name and address to add to the addressbook
String nameToAdd = "Chris P. Bacon";
Address addressToAdd =
new Address(
1,
"The Waterfront",
"Some City",
"NY",
47907,
new Phone(765, "494", "4900"));
// Add the name and address to the input message
inputMessage.setObjectPart("name", nameToAdd);
inputMessage.setObjectPart("address", addressToAdd);
// Execute the operation, obtaining a flag to indicate its success
boolean ok=
operation.executeRequestResponseOperation(
inputMessage,
outputMessage,
faultMessage);
assertTrue( "failed to add name and address!!", ok );
/*
* Run iterations of createOperation
*/
testName = testNamePrefix + ".createOperation";
iterations = DEFAULT_ITERATIONS;
// iterations = 1;
System.out.println( "running " + iterations + " " + testName + " iterations..." );
for (int i = 0; i < iterations; i++ ) {
Monitor.start( testName );
operation = port.createOperation("getAddressFromName");
Monitor.stop( testName );
}
/*
* Run iterations of executeRequestResponseOperation
*/
testName = testNamePrefix + ".getAddressFromName";
iterations = DEFAULT_ITERATIONS;
// iterations = 1;
System.out.println( "running " + iterations + " " + testName + " iterations..." );
for (int i = 0; i < iterations; i++ ) {
operation = port.createOperation("getAddressFromName");
inputMessage = operation.createInputMessage();
outputMessage = operation.createOutputMessage();
faultMessage = operation.createFaultMessage();
inputMessage.setObjectPart("name", nameToAdd);
Monitor.start( testName );
boolean operationSucceeded =
operation.executeRequestResponseOperation(
inputMessage,
outputMessage,
faultMessage);
Monitor.stop( testName );
if (!operationSucceeded) {
System.out.println("Failed to lookup name in addressbook");
assertTrue("executing op returned false!!", false);
}
}
// make sure it all worked
Address addressFound =
(Address) outputMessage.getObjectPart("address");
assertTrue( "returned address not correct!!",
addressToAdd.equals( addressFound) );
Monitor.stop();
Monitor.printResults();
} catch (Exception ex) {
ex.printStackTrace();
assertTrue("exception executing op!!", false);
}
}
private void doitDynTotal(String portName, String protocol) {
int iterations;
String testName;
// String testNamePrefix = "doitDyn" + protocol + "." + portName;
String testNamePrefix = "doitDynTotal";
Monitor.clear();
if (portName.toUpperCase().indexOf("JMS") != -1
&& !TestUtilities.areWeTesting("jms"))
return;
TestUtilities.setProviderForProtocol( protocol );
try {
WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
WSIFService service = factory.getService(wsdlLocation, null, // serviceNS
null, // serviceName
"http://wsifservice.addressbook/", // portTypeNS
"AddressBook"); // portTypeName
service.mapType(
new javax.xml.namespace.QName(
"http://wsiftypes.addressbook/",
"address"),
Class.forName("addressbook.wsiftypes.Address"));
service.mapType(
new javax.xml.namespace.QName(
"http://wsiftypes.addressbook/",
"phone"),
Class.forName("addressbook.wsiftypes.Phone"));
// Create a name and address to add to the addressbook
String nameToAdd = "Chris P. Bacon";
Address addressToAdd =
new Address(
1,
"The Waterfront",
"Some City",
"NY",
47907,
new Phone(765, "494", "4900"));
WSIFPort port = null;
WSIFMessage inputMessage = null;
WSIFMessage outputMessage = null;
WSIFMessage faultMessage = null;
Monitor.start();
/*
* Run iterations
*/
testName = testNamePrefix + ".total";
iterations = DEFAULT_ITERATIONS;
// iterations = 1;
System.out.println( "running " + iterations + " " + testName + " iterations..." );
for (int i = 0; i < iterations; i++ ) {
Monitor.start(testNamePrefix + ".total");
testName = testNamePrefix + ".getPort";
Monitor.start( testName );
port = service.getPort(portName);
Monitor.stop( testName );
testName = testNamePrefix + ".addEntry.ceateOperation";
Monitor.start( testName );
WSIFOperation operation =
port.createOperation("addEntry", "AddEntryWholeNameRequest", null);
Monitor.stop( testName );
testName = testNamePrefix + ".addEntry.createMessages";
Monitor.start( testName );
inputMessage = operation.createInputMessage();
outputMessage = operation.createOutputMessage();
faultMessage = operation.createFaultMessage();
Monitor.stop( testName );
// Add the name and address to the input message
inputMessage.setObjectPart("name", nameToAdd);
inputMessage.setObjectPart("address", addressToAdd);
testName = testNamePrefix + ".addEntry.execute";
Monitor.start( testName );
// Execute the operation, obtaining a flag to indicate its success
boolean ok=
operation.executeRequestResponseOperation(
inputMessage,
outputMessage,
faultMessage);
Monitor.stop( testName );
assertTrue( "failed to add name and address!!", ok );
testName = testNamePrefix + ".getAddressFromName.createOperation";
Monitor.start( testName );
operation = port.createOperation("getAddressFromName");
Monitor.stop( testName );
testName = testNamePrefix + ".getAddressFromName.createMessages";
Monitor.start( testName );
operation = port.createOperation("getAddressFromName");
inputMessage = operation.createInputMessage();
outputMessage = operation.createOutputMessage();
faultMessage = operation.createFaultMessage();
Monitor.stop( testName );
inputMessage.setObjectPart("name", nameToAdd);
testName = testNamePrefix + ".getAddressFromName.execute";
Monitor.start( testName );
boolean operationSucceeded =
operation.executeRequestResponseOperation(
inputMessage,
outputMessage,
faultMessage);
Monitor.stop( testName );
if (!operationSucceeded) {
System.out.println("Failed to lookup name in addressbook");
assertTrue("executing op returned false!!", false);
}
Monitor.stop(testNamePrefix + ".total");
}
Monitor.stop();
Monitor.printResults();
// make sure it all worked
Address addressFound =
(Address) outputMessage.getObjectPart("address");
assertTrue( "returned address not correct!!",
addressToAdd.equals( addressFound) );
} catch (Exception ex) {
ex.printStackTrace();
assertTrue("exception executing op!!", false);
}
}
private void doitStub(String portName, String protocol) {
int iterations;
String testName;
// String testNamePrefix = "doitDyn" + protocol + "." + portName;
String testNamePrefix = "doitStub";
Monitor.clear();
if (portName.toUpperCase().indexOf("JMS") != -1
&& !TestUtilities.areWeTesting("jms"))
return;
TestUtilities.setProviderForProtocol( protocol );
try {
WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
WSIFService service = factory.getService(
wsdlLocation,
null, // serviceNS
null, // serviceName
"http://wsifservice.addressbook/", // portTypeNS
"AddressBook"); // portTypeName
Monitor.start();
Monitor.start( testNamePrefix + ".total" );
/*
* Run iterations of getStub
*/
AddressBook abStub = null;
testName = testNamePrefix + ".getStub";
iterations = DEFAULT_ITERATIONS;
// iterations = 1;
System.out.println( "running " + iterations + " " + testName + " iterations..." );
for (int i = 0; i < iterations; i++ ) {
Monitor.start( testName );
abStub = (AddressBook) service.getStub(portName, AddressBook.class);
Monitor.stop( testName );
}
/*
* Run iterations of addEntry
*/
testName = testNamePrefix + ".addEntry";
iterations = DEFAULT_ITERATIONS;
// iterations = 1;
System.out.println( "running " + iterations + " " + testName + " iterations..." );
for (int i = 0; i < iterations; i++ ) {
Monitor.start( testName );
abStub.addEntry(name1, addr1);
Monitor.stop( testName );
}
/*
* Run iterations of getAddressFromName
*/
testName = testNamePrefix + ".getAddressFromName";
iterations = DEFAULT_ITERATIONS;
// iterations = 1;
System.out.println( "running " + iterations + " " + testName + " iterations..." );
for (int i = 0; i < iterations; i++ ) {
Address resp1 = null;
Monitor.start( testName );
resp1 = abStub.getAddressFromName(name1);
Monitor.stop( testName );
assertTrue(new AddressUtility(addr1).equals(resp1));
}
Monitor.start( testNamePrefix + ".total" );
Monitor.stop();
Monitor.printResults();
} catch (Exception ex) {
ex.printStackTrace();
assertTrue("exception executing op!!", false);
}
}
private void doitStubTotal(String portName, String protocol) {
int iterations;
String testName;
// String testNamePrefix = "doitDyn" + protocol + "." + portName;
String testNamePrefix = "doitStubTotal";
Monitor.clear();
if (portName.toUpperCase().indexOf("JMS") != -1
&& !TestUtilities.areWeTesting("jms"))
return;
TestUtilities.setProviderForProtocol( protocol );
try {
WSIFServiceFactory factory = WSIFServiceFactory.newInstance();
WSIFService service = factory.getService(
wsdlLocation,
null, // serviceNS
null, // serviceName
"http://wsifservice.addressbook/", // portTypeNS
"AddressBook"); // portTypeName
testName = testNamePrefix + ".total";
iterations = DEFAULT_ITERATIONS;
// iterations = 1;
System.out.println( "running " + iterations + " " + testName + " iterations..." );
Monitor.start();
for (int j = 0; j < iterations; j++ ) {
Monitor.start( testNamePrefix + ".total" );
AddressBook abStub = null;
testName = testNamePrefix + ".getStub";
Monitor.start( testName );
abStub = (AddressBook) service.getStub(portName, AddressBook.class);
Monitor.stop( testName );
testName = testNamePrefix + ".addEntry";
Monitor.start( testName );
abStub.addEntry(name1, addr1);
Monitor.stop( testName );
testName = testNamePrefix + ".getAddressFromName";
Address resp1 = null;
Monitor.start( testName );
resp1 = abStub.getAddressFromName(name1);
Monitor.stop( testName );
assertTrue(new AddressUtility(addr1).equals(resp1));
Monitor.stop( testNamePrefix + ".total" );
}
Monitor.stop();
Monitor.printResults();
} catch (Exception ex) {
ex.printStackTrace();
assertTrue("exception executing op!!", false);
}
}
}