hc-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ol...@apache.org
Subject svn commit: r232899 - in /jakarta/httpclient/trunk/coyote-httpconnector/src/tests: ./ server.xml tests/ tests/peformance/ tests/peformance/PerformanceTest.java
Date Mon, 15 Aug 2005 22:20:47 GMT
Author: olegk
Date: Mon Aug 15 15:20:39 2005
New Revision: 232899

URL: http://svn.apache.org/viewcvs?rev=232899&view=rev
Log:
Added performance test app

Added:
    jakarta/httpclient/trunk/coyote-httpconnector/src/tests/
    jakarta/httpclient/trunk/coyote-httpconnector/src/tests/server.xml   (with props)
    jakarta/httpclient/trunk/coyote-httpconnector/src/tests/tests/
    jakarta/httpclient/trunk/coyote-httpconnector/src/tests/tests/peformance/
    jakarta/httpclient/trunk/coyote-httpconnector/src/tests/tests/peformance/PerformanceTest.java
  (with props)

Added: jakarta/httpclient/trunk/coyote-httpconnector/src/tests/server.xml
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/tests/server.xml?rev=232899&view=auto
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/tests/server.xml (added)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/tests/server.xml Mon Aug 15 15:20:39
2005
@@ -0,0 +1,42 @@
+<Server port="8005" shutdown="SHUTDOWN">
+
+  <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" />
+  <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
+  <Listener className="org.apache.catalina.storeconfig.StoreConfigLifecycleListener"/>
+
+  <GlobalNamingResources>
+
+    <Resource name="UserDatabase" auth="Container"
+              type="org.apache.catalina.UserDatabase"
+       description="User database that can be updated and saved"
+           factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
+          pathname="conf/tomcat-users.xml" />
+
+  </GlobalNamingResources>
+
+  <Service name="Catalina">
+
+    <Connector port="8080" 
+               maxHttpHeaderSize="8192" minSpareThreads="25" maxThreads="150"
+               enableLookups="false" acceptCount="100"
+               connectionTimeout="20000" disableUploadTimeout="true" 
+               compression="off" maxKeepAliveRequests="10000"
+               tcpNoDelay="true"/>
+
+    <Connector port="8888" protocol="org.apache.http.coyote.HttpProtocolHandler"
+               minThreads="25" maxThreads="150" socketTimeout="20000"/>
+
+    <Engine name="Catalina" defaultHost="localhost">
+
+      <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
+             resourceName="UserDatabase" />
+
+      <Host name="localhost" appBase="webapps"
+       unpackWARs="true" autoDeploy="true"
+       xmlValidation="false" xmlNamespaceAware="false"/>
+
+    </Engine>
+
+  </Service>
+
+</Server>

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/tests/server.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/tests/server.xml
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/tests/server.xml
------------------------------------------------------------------------------
    svn:mime-type = text/xml

Added: jakarta/httpclient/trunk/coyote-httpconnector/src/tests/tests/peformance/PerformanceTest.java
URL: http://svn.apache.org/viewcvs/jakarta/httpclient/trunk/coyote-httpconnector/src/tests/tests/peformance/PerformanceTest.java?rev=232899&view=auto
==============================================================================
--- jakarta/httpclient/trunk/coyote-httpconnector/src/tests/tests/peformance/PerformanceTest.java
(added)
+++ jakarta/httpclient/trunk/coyote-httpconnector/src/tests/tests/peformance/PerformanceTest.java
Mon Aug 15 15:20:39 2005
@@ -0,0 +1,117 @@
+package tests.peformance;
+
+import java.io.IOException;
+import java.util.Random;
+
+import org.apache.http.HttpClientConnection;
+import org.apache.http.HttpException;
+import org.apache.http.HttpHost;
+import org.apache.http.HttpMutableRequest;
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpVersion;
+import org.apache.http.Protocol;
+import org.apache.http.entity.ByteArrayEntity;
+import org.apache.http.entity.EntityConsumer;
+import org.apache.http.executor.HttpRequestExecutor;
+import org.apache.http.impl.DefaultHttpClientConnection;
+import org.apache.http.impl.DefaultHttpParams;
+import org.apache.http.impl.HttpGetRequest;
+import org.apache.http.impl.HttpPostRequest;
+import org.apache.http.impl.io.NIOSocketFactory;
+import org.apache.http.io.SocketFactory;
+import org.apache.http.params.HttpParams;
+import org.apache.http.params.HttpProtocolParams;
+import org.apache.http.protocol.RequestConnControl;
+import org.apache.http.protocol.RequestContent;
+import org.apache.http.protocol.RequestExpectContinue;
+import org.apache.http.protocol.RequestTargetHost;
+import org.apache.http.protocol.RequestUserAgent;
+
+public class PerformanceTest {
+
+	private final HttpRequestExecutor httpexecutor;
+	
+	private PerformanceTest() {
+		super();
+		this.httpexecutor = createExecutor();
+	}
+	
+	private static HttpRequestExecutor createExecutor() {
+        HttpParams params = new DefaultHttpParams(null);
+        params.setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1)
+        	.setParameter(HttpProtocolParams.HTTP_CONTENT_CHARSET, "UTF-8")
+        	.setParameter(HttpProtocolParams.USER_AGENT, "Jakarta HTTP")
+        	.setBooleanParameter(HttpProtocolParams.USE_EXPECT_CONTINUE, true);
+        	
+        HttpRequestExecutor httpexecutor = new HttpRequestExecutor();
+        httpexecutor.setParams(params);
+        
+        // Required request interceptors
+        httpexecutor.addRequestInterceptor(new RequestContent());
+        httpexecutor.addRequestInterceptor(new RequestTargetHost());
+        // Recommended request interceptors
+        httpexecutor.addRequestInterceptor(new RequestConnControl());
+        httpexecutor.addRequestInterceptor(new RequestUserAgent());
+        httpexecutor.addRequestInterceptor(new RequestExpectContinue());
+        return httpexecutor;
+	}
+
+	private static HttpMutableRequest[] generateRequests() {
+		HttpGetRequest  r1 = new HttpGetRequest("/tomcat-docs/changelog.html"); 
+		HttpGetRequest  r2 = new HttpGetRequest("/servlets-examples/servlet/RequestInfoExample");

+		HttpPostRequest r3 = new HttpPostRequest("/servlets-examples/servlet/RequestInfoExample");
+		byte[] stuff = new byte[1000000];
+		Random rnd = new Random();
+		rnd.nextBytes(stuff);
+		ByteArrayEntity entity = new ByteArrayEntity(stuff);
+		r3.setEntity(entity);
+		return new HttpMutableRequest[] { r1, r2, r3};
+	}
+	
+	private void execute(
+			final HttpRequest request, 
+			final HttpClientConnection conn, 
+			int repeatCount) throws IOException, HttpException {
+		long total = 0;
+        for (int i = 0; i < repeatCount; i++) {
+        	long start = System.nanoTime();
+            HttpResponse response = this.httpexecutor.execute(request, conn);
+            // Consume as string
+            EntityConsumer.toString(response.getEntity());
+        	long t = System.nanoTime() - start;
+        	total += t;
+        }
+    	System.out.println("Request: " + request.getRequestLine());
+    	System.out.println("Average (nanosec): " + (total / repeatCount));
+	}
+
+	public static void main(String[] args) throws Exception {
+		if (args.length != 2) {
+			System.out.println("Usage tests.performance.PerformanceTest <port> <count>");
+			System.exit(1);
+		}
+		PerformanceTest test = new PerformanceTest();
+		
+		int port = Integer.parseInt(args[0]);
+		int count = Integer.parseInt(args[1]);
+		
+        SocketFactory socketfactory = NIOSocketFactory.getSocketFactory();
+        Protocol http = new Protocol("http", socketfactory, 80);
+        HttpHost host = new HttpHost("localhost", port, http);
+
+        HttpRequest[] requests = generateRequests();
+        
+        Thread.sleep(1000);
+        
+        HttpClientConnection conn = new DefaultHttpClientConnection(host);
+        try {
+        	for (int i = 0; i < requests.length; i++) {
+            	test.execute(requests[i], conn, count);
+        	}
+        } finally {
+        	conn.close();
+        }
+	}
+	
+}

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/tests/tests/peformance/PerformanceTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/tests/tests/peformance/PerformanceTest.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Propchange: jakarta/httpclient/trunk/coyote-httpconnector/src/tests/tests/peformance/PerformanceTest.java
------------------------------------------------------------------------------
    svn:mime-type = text/plain



Mime
View raw message