I've run your tests with small modifications (see attached).  As suggested by Kevin 
Lynn, the results you are seeing are almost certainly related to the use of NT 
Workstation.  By adding the backlog parameter to Tomcat's servlet.xml, I was able to 
successfully handle 500 client threads on NT 4 server and Win2k server.  When running 
NT 4 Workstation, I got connection refused errors consistently for any number of 
threads greater than 13.

Scott

server.xml excerpt:

        <!-- Normal HTTP -->
        <Connector className="org.apache.tomcat.service.PoolTcpConnector">
            <Parameter name="handler" 
                value="org.apache.tomcat.service.http.HttpConnectionHandler"/>
            <Parameter name="port" 
                value="8080"/>
            <Parameter name="backlog" value="500"/>
        </Connector>

//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))); 
   } 
	public static void main(String[] args) {
		SumServer ss = new SumServer();
		long t0 = System.currentTimeMillis();
		String s = "";
		for (int i = 0; i < 100; i++)
			s += ss.findSum("1", "2");
		long t1 = System.currentTimeMillis();
		System.out.println("Elapsed millis for 100 loops: " + (t1 - t0));
		System.out.println(s);
	}
}
<isd:service xmlns:isd="http://xml.apache.org/xml-soap/deployment";
             id="urn:Sum">
  <isd:provider type="java"
                scope="Application"
                methods="findSum">
    <isd:java class="SumServer" static="false"/>
  </isd:provider>

  <isd:faultListener>org.apache.soap.server.DOMFaultListener</isd:faultListener>

  <isd:mappings>
  </isd:mappings>    
</isd:service>
//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)
	{ 
		try 
		{ 
			URL url = null;
			int threads = 500;
			if(args.length >= 1 && !args[0].equals("-?")) 
			{ 
				url = new URL(args[0]);
				if (args.length >= 2)
					threads = Integer.parseInt(args[1]);
			} 
			else if (args.length == 0)
			{ 
				url = new URL("http://localhost:8080/soap/servlet/rpcrouter";); 
			}
			else
			{
				System.err.println("Usage: java Client [SOAP-router-URL] [threads]"); 
				System.exit (1); 
			}
			ClientThread ct[] = new ClientThread[threads]; 
			for (int i = 0; i < threads; i++)
			{
				ct[i] = new ClientThread(i, url);
				ct[i].start();
			} 
		}
		catch(Exception e) 
		{ 
			e.printStackTrace(); 
		} 
	} 
} 

class ClientThread extends Thread
{
	public int i;
	int count = 0;
	URL url;
	public ClientThread(int i, URL url)
	{
		this.i = i;
		this.url = url;
	}
	public void run()
	{
		// Build the call. 
		String op1 = "10";
		String op2 = "10";
		try {
			System.out.println("starting thread " + i);
			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.out.println("ending thread " + i + ": Caught SOAPException (" + e.getFaultCode() + "): " + 
					e.getMessage());
				return;
			}

			// Check the response. 
			if( !resp.generatedFault() ) 
			{ 
				Parameter ret = resp.getReturnValue(); 
				Object value = ret.getValue(); 
				Date tempdate = new Date();
				long elaptime = -(date.getTime()-tempdate.getTime());
				System.out.println("ending thread " + i + " sum = " + value + " 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();
		}
	}
}

Reply via email to