created separate test package for benchmarks
This commit is contained in:
parent
b7d6b960ed
commit
98f7acce97
3 changed files with 305 additions and 0 deletions
104
src/helma/xmlrpc/test/AsyncBenchmark.java
Normal file
104
src/helma/xmlrpc/test/AsyncBenchmark.java
Normal file
|
@ -0,0 +1,104 @@
|
|||
/**
|
||||
* Copyright 1999 Hannes Wallnoefer
|
||||
*/
|
||||
|
||||
package helma.xmlrpc.test;
|
||||
|
||||
import helma.xmlrpc.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
import java.net.URL;
|
||||
|
||||
public class AsyncBenchmark implements Runnable {
|
||||
|
||||
XmlRpcClient client;
|
||||
static String url;
|
||||
static int clients = 16;
|
||||
static int loops = 100;
|
||||
|
||||
int calls = 0;
|
||||
|
||||
int gCalls = 0, gErrors = 0;
|
||||
long start;
|
||||
|
||||
|
||||
public AsyncBenchmark () throws Exception {
|
||||
client = new XmlRpcClientLite (url);
|
||||
|
||||
Vector args = new Vector ();
|
||||
// Some JITs (Symantec, IBM) have problems with several Threads
|
||||
// starting all at the same time.
|
||||
// This initial XML-RPC call seems to pacify them.
|
||||
args.addElement (new Integer (123));
|
||||
client.execute ("math.abs", args);
|
||||
|
||||
start = System.currentTimeMillis ();
|
||||
|
||||
for (int i=0; i<clients; i++)
|
||||
new Thread (this).start ();
|
||||
}
|
||||
|
||||
public void run () {
|
||||
int calls = 0;
|
||||
long start = System.currentTimeMillis ();
|
||||
|
||||
for (int i=0; i<loops; i++) {
|
||||
|
||||
Vector args = new Vector ();
|
||||
Integer n = new Integer (Math.round ((int)(Math.random ()*-1000)));
|
||||
args.addElement (n);
|
||||
client.executeAsync ("math.abs", args, new Callback (n));
|
||||
calls += 1;
|
||||
}
|
||||
int millis = (int) (System.currentTimeMillis () - start);
|
||||
System.err.println ("Benchmark thread finished: "+calls+" calls in "+millis+" milliseconds.");
|
||||
}
|
||||
|
||||
public static void main (String args[]) throws Exception {
|
||||
if (args.length > 0 && args.length < 3) {
|
||||
url = args[0];
|
||||
XmlRpc.setKeepAlive (true);
|
||||
if (args.length == 2)
|
||||
XmlRpc.setDriver (args[1]);
|
||||
new AsyncBenchmark ();
|
||||
} else {
|
||||
System.err.println ("Usage: java helma.xmlrpc.Benchmark URL [SAXDriver]");
|
||||
}
|
||||
}
|
||||
|
||||
class Callback implements AsyncCallback {
|
||||
|
||||
|
||||
int n;
|
||||
|
||||
public Callback (Integer n) {
|
||||
this.n = Math.abs (n.intValue());
|
||||
}
|
||||
|
||||
public synchronized void handleResult (Object result, URL url, String method) {
|
||||
if (n == ((Integer) result).intValue ())
|
||||
gCalls += 1;
|
||||
else
|
||||
gErrors += 1;
|
||||
if (gCalls + gErrors >= clients*loops)
|
||||
printStats ();
|
||||
}
|
||||
|
||||
public synchronized void handleError (Exception exception, URL url, String method) {
|
||||
System.err.println (exception);
|
||||
exception.printStackTrace ();
|
||||
gErrors += 1;
|
||||
if (gCalls + gErrors >= clients*loops)
|
||||
printStats ();
|
||||
}
|
||||
|
||||
public void printStats () {
|
||||
System.err.println ("");
|
||||
System.err.println (gCalls+" calls, "+gErrors+" errors in "+(System.currentTimeMillis()-start)+" millis");
|
||||
System.err.println ((1000*(gCalls+gErrors)/(System.currentTimeMillis()-start))+" calls per second");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
107
src/helma/xmlrpc/test/Benchmark.java
Normal file
107
src/helma/xmlrpc/test/Benchmark.java
Normal file
|
@ -0,0 +1,107 @@
|
|||
/**
|
||||
* Copyright 1999 Hannes Wallnoefer
|
||||
*/
|
||||
|
||||
package helma.xmlrpc.test;
|
||||
|
||||
import helma.xmlrpc.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class Benchmark implements Runnable {
|
||||
|
||||
XmlRpcClient client;
|
||||
static String url;
|
||||
static int clients = 16;
|
||||
static int loops = 100;
|
||||
|
||||
int gCalls = 0, gErrors = 0;
|
||||
|
||||
Date date;
|
||||
|
||||
public Benchmark () throws Exception {
|
||||
client = new XmlRpcClientLite (url);
|
||||
|
||||
Vector args = new Vector ();
|
||||
// Some JITs (Symantec, IBM) have problems with several Threads
|
||||
// starting all at the same time.
|
||||
// This initial XML-RPC call seems to pacify them.
|
||||
args.addElement (new Integer (123));
|
||||
client.execute ("math.abs", args);
|
||||
date = new Date ();
|
||||
date = new Date ((date.getTime()/1000)*1000);
|
||||
|
||||
for (int i=0; i<clients; i++)
|
||||
new Thread (this).start ();
|
||||
}
|
||||
|
||||
public void run () {
|
||||
int errors = 0;
|
||||
int calls = 0;
|
||||
long start = System.currentTimeMillis ();
|
||||
try {
|
||||
int val = (int) (-100 * Math.random ());
|
||||
Vector args = new Vector ();
|
||||
|
||||
// ECHO STRING
|
||||
// args.addElement (Integer.toString (val));
|
||||
// ABS INT
|
||||
args.addElement (new Integer (val));
|
||||
// ECHO DATE
|
||||
// args.addElement (date);
|
||||
|
||||
for (int i=0; i<loops; i++) {
|
||||
|
||||
// ABS INT
|
||||
Integer ret = (Integer) client.execute ("math.abs", args);
|
||||
// ECHO
|
||||
// Vector v = (Vector) client.execute ("echo", args);
|
||||
// ECHO DATE
|
||||
// Date d = (Date) v.elementAt (0);
|
||||
|
||||
// ABS INT
|
||||
if (ret.intValue () != Math.abs (val)) {
|
||||
// ECHO DATE
|
||||
// if (date.getTime() != d.getTime()) {
|
||||
// ECHO STRING
|
||||
// if (!Integer.toString(val).equals (v.elementAt (0))) {
|
||||
errors += 1;
|
||||
}
|
||||
calls += 1;
|
||||
}
|
||||
} catch (IOException x) {
|
||||
System.err.println ("Exception in client: "+x);
|
||||
x.printStackTrace ();
|
||||
} catch (XmlRpcException x) {
|
||||
System.err.println ("Server reported error: "+x);
|
||||
} catch (Exception other) {
|
||||
System.err.println ("Exception in Benchmark client: "+other);
|
||||
}
|
||||
int millis = (int) (System.currentTimeMillis () - start);
|
||||
checkout (calls, errors, millis);
|
||||
}
|
||||
|
||||
private synchronized void checkout (int calls, int errors, int millis) {
|
||||
clients--;
|
||||
gCalls += calls;
|
||||
gErrors += errors;
|
||||
System.err.println ("Benchmark thread finished: "+calls+" calls, "+errors+" errors in "+millis+" milliseconds.");
|
||||
if (clients == 0) {
|
||||
System.err.println ("");
|
||||
System.err.println ("Benchmark result: "+(1000*gCalls/millis)+" calls per second.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main (String args[]) throws Exception {
|
||||
if (args.length > 0 && args.length < 3) {
|
||||
url = args[0];
|
||||
XmlRpc.setKeepAlive (true);
|
||||
if (args.length == 2)
|
||||
XmlRpc.setDriver (args[1]);
|
||||
new Benchmark ();
|
||||
} else {
|
||||
System.err.println ("Usage: java helma.xmlrpc.Benchmark URL [SAXDriver]");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
94
src/helma/xmlrpc/test/TestBase64.java
Normal file
94
src/helma/xmlrpc/test/TestBase64.java
Normal file
|
@ -0,0 +1,94 @@
|
|||
/**
|
||||
* Copyright 1999 Hannes Wallnoefer
|
||||
*/
|
||||
|
||||
package helma.xmlrpc.test;
|
||||
|
||||
import helma.xmlrpc.*;
|
||||
import java.util.*;
|
||||
import java.io.IOException;
|
||||
|
||||
public class TestBase64 implements Runnable {
|
||||
|
||||
XmlRpcClient client;
|
||||
static String url;
|
||||
static int clients = 1; // 6;
|
||||
static int loops = 1; //00;
|
||||
|
||||
int gCalls = 0, gErrors = 0;
|
||||
|
||||
byte[] data;
|
||||
|
||||
public TestBase64 () throws Exception {
|
||||
client = new XmlRpcClientLite (url);
|
||||
|
||||
Vector args = new Vector ();
|
||||
// Some JITs (Symantec, IBM) have problems with several Threads
|
||||
// starting all at the same time.
|
||||
// This initial XML-RPC call seems to pacify them.
|
||||
args.addElement (new Integer (123));
|
||||
client.execute ("math.abs", args);
|
||||
|
||||
data = new byte[20000];
|
||||
for (int j=0; j<data.length; j++)
|
||||
data[j] = (byte) j;
|
||||
|
||||
for (int i=0; i<clients; i++)
|
||||
new Thread (this).start ();
|
||||
}
|
||||
|
||||
public void run () {
|
||||
int errors = 0;
|
||||
int calls = 0;
|
||||
long start = System.currentTimeMillis ();
|
||||
try {
|
||||
int val = (int) (-100 * Math.random ());
|
||||
Vector args = new Vector ();
|
||||
|
||||
args.addElement (data);
|
||||
|
||||
for (int i=0; i<loops; i++) {
|
||||
|
||||
Vector v = (Vector) client.execute ("echo", args);
|
||||
byte[] d = (byte[]) v.elementAt (0);
|
||||
for (int j=0; j<d.length; j++)
|
||||
if (d[j] != (byte) j) errors += 1;
|
||||
calls += 1;
|
||||
}
|
||||
} catch (IOException x) {
|
||||
System.err.println ("Exception in client: "+x);
|
||||
x.printStackTrace ();
|
||||
} catch (XmlRpcException x) {
|
||||
System.err.println ("Server reported error: "+x);
|
||||
} catch (Exception other) {
|
||||
System.err.println ("Exception in Benchmark client: "+other);
|
||||
}
|
||||
int millis = (int) (System.currentTimeMillis () - start);
|
||||
checkout (calls, errors, millis);
|
||||
}
|
||||
|
||||
private synchronized void checkout (int calls, int errors, int millis) {
|
||||
clients--;
|
||||
gCalls += calls;
|
||||
gErrors += errors;
|
||||
System.err.println ("Benchmark thread finished: "+calls+" calls, "+errors+" errors in "+millis+" milliseconds.");
|
||||
if (clients == 0) {
|
||||
System.err.println ("");
|
||||
System.err.println ("Benchmark result: "+(1000*gCalls/millis)+" calls per second.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void main (String args[]) throws Exception {
|
||||
if (args.length > 0 && args.length < 3) {
|
||||
url = args[0];
|
||||
XmlRpc.setKeepAlive (true);
|
||||
// XmlRpc.setDebug (true);
|
||||
if (args.length == 2)
|
||||
XmlRpc.setDriver (args[1]);
|
||||
new TestBase64 ();
|
||||
} else {
|
||||
System.err.println ("Usage: java helma.xmlrpc.Benchmark URL [SAXDriver]");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Reference in a new issue