Subversion Repositories general

Compare Revisions

No changes between revisions

Ignore whitespace Rev 1126 → Rev 1127

/httpbench/trunk/build.xml
0,0 → 1,48
<project name="httpbench" default="compile" basedir=".">
 
<!--property name="build.compiler" value="jikes" /-->
 
<property name="src" location="src" />
<property name="conf" location="conf" />
<property name="classes" location="classes" />
<property name="lib" location="lib" />
 
<path id="classpath">
<fileset dir="${lib}">
<include name="*.jar" />
</fileset>
</path>
 
<path id="run.classpath">
<path refid="classpath" />
<pathelement path="${classes}" />
</path>
 
<target name="compile">
<mkdir dir="${classes}" />
 
<javac
srcdir="${src}"
destdir="${classes}"
classpathref="classpath"
debug="on"
nowarn="on"
/>
 
<copy file="${conf}/log4j.properties" todir="${classes}" />
</target>
 
<target name="clean">
<delete dir="${classes}"/>
<delete dir="${classes.deploy}"/>
</target>
 
<target name="run" depends="compile">
<java classname="ak.httpbench.HttpBench" fork="yes">
<classpath refid="run.classpath" />
</java>
</target>
 
<target name="all" depends="clean,compile" />
 
</project>
/httpbench/trunk/conf/log4j.properties
0,0 → 1,8
log4j.rootLogger=warn, stdout
 
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%t] %-5p %c - %m%n
 
log4j.logger.ak=info
 
/httpbench/trunk/lib/commons-httpclient-3.0-rc4.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/httpbench/trunk/lib/commons-logging.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/httpbench/trunk/lib/log4j.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/httpbench/trunk/lib/commons-codec-1.3.jar
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
Property changes:
Added: svn:mime-type
+application/octet-stream
\ No newline at end of property
/httpbench/trunk/src/ak/httpbench/HttpBench.java
0,0 → 1,147
package ak.httpbench;
 
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
 
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.GetMethod;
 
public class HttpBench
{
public static void main(String[] args)
throws Exception
{
(new HttpThread(null, new String[] { "http://sun/" } )).run();
}
}
 
class HttpThread
{
private static int threadCount = 0;
private static Log log = LogFactory.getLog(HttpThread.class);
 
private int id;
private String firstUrl; // is used one time only, may be null
private String[] urls;
private int requestNumber = 1;
private int requestPerConnection = 0; // 0 == all
private int sleepMin = 0;
private int sleepMax = 0;
 
public HttpThread(String firstUrl, String[] urls)
{
id = threadCount++;
this.firstUrl = firstUrl;
this.urls = urls;
}
 
public int getId()
{
return id;
}
 
public int getRequestNumber()
{
return requestNumber;
}
 
public void setRequestNumber(int requestNumber)
{
this.requestNumber = requestNumber;
}
 
public int getRequestPerConnection()
{
return requestPerConnection;
}
 
public void setRequestPerConnection(int requestPerConnection)
{
this.requestPerConnection = requestPerConnection;
}
 
public int getSleepMin()
{
return sleepMin;
}
 
public void setSleepMin(int sleepMin)
{
this.sleepMin = sleepMin;
}
 
public int getSleepMax()
{
return sleepMax;
}
 
public void setSleepMax(int sleepMax)
{
this.sleepMax = sleepMax;
}
 
public void run()
{
long startTime = 0;
long stopTime = 0;
long sumSleep = 0;
 
log.info(Integer.toString(id) + ": start");
 
try {
HttpClient client = new HttpClient();
 
startTime = System.currentTimeMillis();
for(int i = 0; i < requestNumber; i++) {
String url;
if(i == 0 && firstUrl != null)
url = firstUrl;
else
url = urls[(firstUrl == null ? i : i-1) % urls.length];
 
GetMethod get = new GetMethod(url);
 
try {
int result = client.executeMethod(get);
if(log.isTraceEnabled()) {
String response = get.getResponseBodyAsString();
log.trace(Integer.toString(id) + ": got " + result + "\n'"
+ response.substring(0, 100) + "'");
}
else if(log.isDebugEnabled()) {
log.debug(Integer.toString(id) + ": got " + result);
}
}
finally {
get.releaseConnection();
}
 
if(requestPerConnection > 0 && (i+1) % requestPerConnection == 0
&& i < requestNumber-1)
{
log.debug(Integer.toString(id)
+ ": request per connection limit reached at " + i);
client.getHttpConnectionManager().closeIdleConnections(0);
}
 
if(sleepMax > 0 && i < requestNumber-1) {
long sleep = (long)(Math.random() * (sleepMax - sleepMin)) + sleepMin;
log.debug(Integer.toString(id) + ": sleep for " + sleep + "ms");
Thread.currentThread().sleep(sleep);
sumSleep += sleep;
}
}
 
client.getHttpConnectionManager().closeIdleConnections(0);
stopTime = System.currentTimeMillis();
}
catch(Exception ex) {
log.warn(Integer.toString(id), ex);
}
 
log.info(Integer.toString(id) + ": done" + (stopTime > 0 ? " in " + (stopTime - startTime)
+ "ms, sleeped for " + sumSleep + " ms" : ""));
}
}
 
/httpbench/trunk
Property changes:
Added: svn:ignore
+classes