Hi,
The files are client.java and server.java
client.java has some redundant code
anyway run as >java client 10 10
those 10 and 10 donot have any significance for benchmarking .. just adding two
integers.
client.java
-----------
package sum;
import java.net.URL;
import java.util.Vector;
import java.util.*;
import org.apache.soap.SOAPException;
import org.apache.soap.Constants;
import org.apache.soap.Fault;
import org.apache.soap.rpc.Call;
import org.apache.soap.rpc.Parameter;
import org.apache.soap.rpc.Response;
public class Client
{
public static void main(String[] args) throws Exception
{
if(args.length == 0)
{
System.err.println("Usage: java hello.Client [SOAP-router-URL] ");
System.exit (1);
}
try
{
URL url = null;
String op1 = null;
String op2 = null;
if(args.length == 3)
{
url = new URL(args[0]);
op1 = args[1];
op2 = args[2];
}
else
{
url = new URL("http://localhost:8080/soap/servlet/rpcrouter");
op1 = args[0];
op2 = args[1];
}
ClientThread ct[] = new ClientThread[500];
Date date = new Date(0);
for(int i=0;i<500;i++)
{
ct[i] = new ClientThread(i,date);
ct[i].start();
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
class ClientThread extends Thread
{
public int i;
int count=0;
public ClientThread(int i,Date date)
{
this.i = i;
}
public void run()
{
// Build the call.
String op1 = "10";
String op2 = "10";
try{
URL url = new URL("http://localhost:8080/soap/servlet/rpcrouter");
System.out.println("Building call object...");
Call call = new Call();
call.setTargetObjectURI("urn:Sum");
call.setMethodName("findSum");
call.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC);
Vector params = new Vector();
params.addElement(new Parameter("op1", String.class, op1, null));
params.addElement(new Parameter("op2", String.class, op2, null));
call.setParams(params);
// Invoke the call.
Response resp = null;
Date date = new Date();
try
{
resp = call.invoke(url, "");
}
catch( SOAPException e )
{
System.err.println("Caught SOAPException (" + e.getFaultCode() + "): " +
e.getMessage());
System.out.println("exception at no. "+i);
this.stop();
}
// Check the response.
if( !resp.generatedFault() )
{
Parameter ret = resp.getReturnValue();
Object value = ret.getValue();
System.out.println("The sum of numbers is");
System.out.println(value);
System.out.println("ending thread"+ i);
Date tempdate = new Date();
long elaptime = -(date.getTime()-tempdate.getTime());
System.out.println("time elapsed = "+ elaptime);
}
else
{
Fault fault = resp.getFault();
System.err.println("Generated fault: ");
System.out.println (" Fault Code = " + fault.getFaultCode());
System.out.println (" Fault String = " + fault.getFaultString());
}
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
sumserver.java
--------------
package sum;
import java.util.*;
public class SumServer
{
public int i = 0;
public String findSum(String op1,String op2)
{
int k=0;
for (int x=0;x<10000;x++)
for (int j =0;j<10000;j++)
{ k++; } //delay
return (""+(Integer.parseInt(op1) + Integer.parseInt(op2)));
}
I ran the two on the same machine. Presently I have set the no of threads spawned in
the client program to 500.
I tried also for 20 and 50 threads.
My benchmarking results were:
The result I was looking for was:
(i) the roundtrip delay for each request in milliseconds and
(ii) the number of successful connections to the server (i.e. out of the 'n' threads
that tried to connect to the server to make an RPC, not all managed to get a
connection: Most returned a SOAP exception which said -->
Caught SOAPException (SOAP-ENV:Client): error opening socket: Connection refused
: no further information ). This probably indicates some form of limitation on the
:number of simultaneous connections to the server.
The server program was running on the same machine as the client.
I tried for 3 different values of 'n' i.e. the number of threads on the client side
No. of successful threads Range of roundtrip delays in millisec
(min-max)
'n' = 50
---------
case 1 21 8297 - 13984
. 13 2125 - 5172
. 17 2109 - 6828
. 21 2500 - 7969
. 21 2234 - 8297
case 6 21 3656 - 7907
'n' = 20
---------
case 1 20 14204 - 15219
. 20 3422 - 7610
. 20 2032 - 7542
. 20 2828 - 7453
. 16 2671 - 6313
. 20 1703 - 7547
. 20 3953 - 7453
case 8 17 2797 - 6469
'n' = 500
---------
case 1 66 25640 - 69047
. 16 8265 - 11813
. 27 7969 - 15813
case 4 22 8422 - 12844
regards,
Siddharth
On Wed, 19 Sep 2001 Scott Nichol wrote :