[jboss-cvs] JBossAS SVN: r68992 - projects/cluster/varia/sessionstress.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Tue Jan 15 15:26:28 EST 2008
Author: bstansberry at jboss.com
Date: 2008-01-15 15:26:28 -0500 (Tue, 15 Jan 2008)
New Revision: 68992
Added:
projects/cluster/varia/sessionstress/ConnPerClientPerfTest.java
Modified:
projects/cluster/varia/sessionstress/run.sh
Log:
Restore the single-conn-per-client test
Added: projects/cluster/varia/sessionstress/ConnPerClientPerfTest.java
===================================================================
--- projects/cluster/varia/sessionstress/ConnPerClientPerfTest.java (rev 0)
+++ projects/cluster/varia/sessionstress/ConnPerClientPerfTest.java 2008-01-15 20:26:28 UTC (rev 68992)
@@ -0,0 +1,402 @@
+package multicast;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.HttpConnectionManager;
+import org.apache.commons.httpclient.HttpStatus;
+import org.apache.commons.httpclient.SimpleHttpConnectionManager;
+import org.apache.commons.httpclient.methods.GetMethod;
+
+import javax.naming.NamingException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.PrintWriter;
+import java.io.StringWriter;
+import java.text.NumberFormat;
+import java.util.concurrent.BrokenBarrierException;
+import java.util.concurrent.CyclicBarrier;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Bela Ban
+ * @version $Id$
+ */
+public class ConnPerClientPerfTest {
+ private Client[] clients;
+ private CyclicBarrier barrier;
+
+ static NumberFormat f;
+
+ static {
+ f=NumberFormat.getNumberInstance();
+ f.setGroupingUsed(false);
+ f.setMaximumFractionDigits(2);
+ }
+
+ // turn off httpclient logging
+ static
+ {
+ // turn off commons logging
+ System.setProperty(
+ "org.apache.commons.logging.Log","org.apache.commons.logging.impl.NoOpLog");
+ System.setProperty(
+ "org.apache.commons.logging.simplelog.showdatetime","true");
+ System.setProperty(
+ "org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient","error");
+ }
+
+ private void start(String host, String setup_url, String read_url, String write_url, String destroy_url, int num_threads, int num_requests, int num_attrs, int size, int write_percentage) throws NamingException, BrokenBarrierException, InterruptedException {
+ this.clients=new Client[num_threads];
+ this.barrier=new CyclicBarrier(num_threads + 1);
+ System.out.println("Starting " + num_threads + " clients");
+ for(int i=0; i < clients.length; i++) {
+ Client client=new Client(barrier, host, setup_url, read_url, write_url, destroy_url, write_percentage,
+ num_requests, num_attrs, size);
+ clients[i]=client;
+ client.start();
+ }
+
+ System.out.println("Waiting for clients to complete");
+ barrier.await();
+
+ long total_time=0, total_bytes_read=0, total_bytes_written=0;
+ int total_successful_reads=0, total_successful_writes=0, total_failed_reads=0, total_failed_writes=0;
+
+ int num_clients=0;
+ for(Client client: clients) {
+ if(!client.isSuccessful()) {
+ continue;
+ }
+ num_clients++;
+ total_time+=client.getTime();
+ total_bytes_read+=client.getBytesRead();
+ total_bytes_written+=client.getBytesWritten();
+ total_successful_reads+=client.getSuccessfulReads();
+ total_successful_writes+=client.getSuccessfulWrites();
+ total_failed_reads+=client.getFailedReads();
+ total_failed_writes+=client.getFailedWrites();
+ }
+
+ if(num_clients < 1) {
+ System.err.println("No client completed successfully, will not compute results");
+ return;
+ }
+
+ int failed_clients=num_threads - num_clients;
+ int total_requests=total_successful_reads + total_successful_writes;
+ double avg_time=total_time / num_clients;
+ double reqs_sec=total_requests / (avg_time / 1000.0);
+
+ System.out.println("\nTotal requests: " + total_requests + " in (avg) " + (avg_time / 1000.0) + " secs");
+ System.out.println("\n*** " + f.format(reqs_sec) + " requests/sec, requests/sec/client: " +
+ f.format((total_requests / num_clients) / (avg_time / 1000.0)) + " ***\n");
+
+ System.out.println("Successful reads: " + total_successful_reads + ", successful writes: " + total_successful_writes);
+ System.out.println("Failed reads: " + total_failed_reads + ", failed writes: " + total_failed_writes);
+ System.out.println("Bytes read: " + printBytes(total_bytes_read) + ", bytes written: " + printBytes(total_bytes_written));
+ System.out.println("Bytes read/sec: " + printBytes(total_bytes_read / (avg_time / 1000.0)) + ", bytes written/sec: " +
+ printBytes(total_bytes_written / (avg_time / 1000.0)));
+ System.out.println("Total client: " + num_clients + ", failed clients: " + failed_clients);
+ }
+
+ private static String printBytes(long bytes) {
+ double tmp;
+
+ if(bytes < 1000)
+ return bytes + "b";
+ if(bytes < 1000000) {
+ tmp=bytes / 1000.0;
+ return f.format(tmp) + "KB";
+ }
+ if(bytes < 1000000000) {
+ tmp=bytes / 1000000.0;
+ return f.format(tmp) + "MB";
+ }
+ else {
+ tmp=bytes / 1000000000.0;
+ return f.format(tmp) + "GB";
+ }
+ }
+
+ public static String printBytes(double bytes) {
+ double tmp;
+
+ if(bytes < 1000)
+ return bytes + "b";
+ if(bytes < 1000000) {
+ tmp=bytes / 1000.0;
+ return f.format(tmp) + "KB";
+ }
+ if(bytes < 1000000000) {
+ tmp=bytes / 1000000.0;
+ return f.format(tmp) + "MB";
+ }
+ else {
+ tmp=bytes / 1000000000.0;
+ return f.format(tmp) + "GB";
+ }
+ }
+
+
+
+ public static void main(String[] args) throws Exception {
+ int num_threads=1;
+ int num_requests=1000;
+ int num_attrs=25;
+ int size=1000;
+ int write_percentage=10; // percent
+ String host="localhost";
+ String setup_url="web/setup.jsp";
+ String read_url="web/read.jsp";
+ String write_url="web/write.jsp";
+ String destroy_url="web/destroy.jsp";
+
+ for(int i=0; i < args.length; i++) {
+ if(args[i].equals("-host")) {
+ host=args[++i];
+ continue;
+ }
+ if(args[i].equals("-setup_url")) {
+ setup_url=args[++i];
+ continue;
+ }
+ if(args[i].equals("-read_url")) {
+ read_url=args[++i];
+ continue;
+ }
+ if(args[i].equals("-write_url")) {
+ write_url=args[++i];
+ continue;
+ }
+ if(args[i].equals("-destroy_url")) {
+ destroy_url=args[++i];
+ continue;
+ }
+ if(args[i].equals("-num_threads")) {
+ num_threads=Integer.parseInt(args[++i]);
+ continue;
+ }
+ if(args[i].equals("-num_requests")) {
+ num_requests=Integer.parseInt(args[++i]);
+ continue;
+ }
+ if(args[i].equals("-num_attrs")) {
+ num_attrs=Integer.parseInt(args[++i]);
+ continue;
+ }
+ if(args[i].equals("-size")) {
+ size=Integer.parseInt(args[++i]);
+ continue;
+ }
+ if(args[i].equals("-write_percentage")) {
+ write_percentage=Integer.parseInt(args[++i]);
+ if(write_percentage < 0 || write_percentage > 100) {
+ System.err.println("write_percentage (" + write_percentage + ") has to be >= 0 && <= 100");
+ return;
+ }
+ continue;
+ }
+ help();
+ return;
+ }
+
+ new ConnPerClientPerfTest().start(host, setup_url, read_url, write_url, destroy_url, num_threads, num_requests, num_attrs, size, write_percentage);
+ }
+
+ private static void help() {
+ System.out.println("PerfTest [-host <host[:port] of apache>] [-read_url <URL>] " +
+ "[-num_threads <number of client sessions>] " +
+ "[-write_url <URL>] [-setup_url <URL>] [-num_requests <requests>] " +
+ "[-num_attrs <attrs>] [-size <bytes>] [-write_percentage <percentage, 0-100>]");
+ }
+
+
+ private static class Client extends Thread {
+ private final int read_percentage;
+ private final int num_requests, num_attrs, size;
+ private final HttpClient session;
+ private final GetMethod setup_method, destroy_method;
+ private final String read_url;
+ private final String write_url;
+ private final CyclicBarrier barrier;
+
+ private int successful_reads=0, failed_reads=0, successful_writes=0, failed_writes=0;
+ private long bytes_read=0, bytes_written=0;
+ private long start=0, stop=0;
+ private boolean successful=true;
+ private final byte[] buffer=new byte[1024];
+
+
+
+ private Client(CyclicBarrier barrier, String host, String setup_url, String read_url, String write_url,
+ String destroy_url, int write_percentage, int num_requests, int num_attrs, int size) {
+ this.barrier=barrier;
+ this.read_percentage=100 - write_percentage;
+ this.num_requests=num_requests;
+ this.num_attrs=num_attrs;
+ this.size=size;
+ String tmp="http://" + host + "/";
+ this.read_url=tmp + read_url + "?id=";
+ this.write_url=tmp + write_url + "?size=" + size + "&id=";
+ this.setup_method=new GetMethod(tmp + setup_url + "?num_attrs=" + num_attrs + "&size=" + size);
+ this.destroy_method=new GetMethod(tmp + destroy_url);
+ HttpConnectionManager mgr = new SimpleHttpConnectionManager();
+ mgr.getParams().setStaleCheckingEnabled(true);
+ this.session = new HttpClient(mgr);
+ }
+
+ public void run() {
+ try {
+ init(num_attrs, size);
+ start=System.currentTimeMillis();
+ loop(num_requests);
+ }
+ catch(Exception e) {
+ error("failure", e);
+ successful=false;
+ }
+ finally {
+ stop=System.currentTimeMillis();
+ try {terminate();} catch(IOException e) {}
+ log("barrier.await()");
+ try {barrier.await(120000, TimeUnit.MILLISECONDS);} catch(Exception e) {}
+ setup_method.releaseConnection();
+ }
+ }
+
+
+
+ public long getBytesRead() {
+ return bytes_read;
+ }
+
+ public long getBytesWritten() {
+ return bytes_written;
+ }
+
+ public int getFailedReads() {
+ return failed_reads;
+ }
+
+ public int getFailedWrites() {
+ return failed_writes;
+ }
+
+ public int getSuccessfulReads() {
+ return successful_reads;
+ }
+
+ public int getSuccessfulWrites() {
+ return successful_writes;
+ }
+
+ public long getTime() {
+ return stop - start;
+ }
+
+ public boolean isSuccessful() {
+ return successful;
+ }
+
+ /** Create NUM_SESSIONS sessions with NUM_ATTRS attributes of SIZE size. Total size is multiplication of the 3 */
+ private void init(int num_attrs, int size) throws IOException {
+ int rc=executeRequest(setup_method);
+ if(rc != HttpStatus.SC_OK) {
+ throw new RuntimeException("failed initializing session", null);
+ }
+ else {
+ log("successfully initialized session with " + num_attrs + " attrs of " + size + " bytes");
+ }
+ }
+
+ private void terminate() throws IOException {
+ int rc=executeRequest(destroy_method);
+ if(rc != HttpStatus.SC_OK) {
+ throw new RuntimeException("failed destroying session", null);
+ }
+ else {
+ log("destroyed session");
+ }
+ }
+
+ private void loop(int num_requests) throws IOException {
+ int random, id;
+ int print=num_requests / 10;
+
+ GetMethod read_method, write_method;
+ int rc, total=0;
+
+ for(int i=0; i < num_requests; i++) {
+ random=(int)random(100);
+ id=(int)random(num_attrs -1);
+ if(random <= read_percentage) { // read
+ read_method=new GetMethod(read_url + id);
+ rc=session.executeMethod(read_method);
+ if(rc == HttpStatus.SC_OK) {
+ successful_reads++;
+ bytes_read+=size; // bytes read from the session, not by the HttpClient !
+ }
+ else {
+ failed_reads++;
+ }
+ }
+ else { // write
+ write_method=new GetMethod(write_url + id);
+ rc=executeRequest(write_method);
+ if(rc == HttpStatus.SC_OK) {
+ successful_writes++;
+ bytes_written+=size; // bytes read from the session, not by the HttpClient !
+ }
+ else {
+ failed_writes++;
+ }
+ }
+ total++;
+ if(total % print == 0)
+ log(total + " / " + num_requests);
+ }
+ }
+
+ private int executeRequest(GetMethod method) throws IOException {
+ try {
+ int rc = session.executeMethod(method);
+ InputStream input=method.getResponseBodyAsStream();
+ while ((input.read(buffer)) != -1) {
+ ;
+ }
+ input.close();
+ return rc;
+ }
+ finally {
+ method.releaseConnection();
+ }
+ }
+
+ private synchronized static void log(String msg) {
+ System.out.println("[thread-" + Thread.currentThread().getId() + "]: " + msg);
+ }
+
+ private static void error(String msg, Throwable th) {
+ String tmp="[thread-" + Thread.currentThread().getId() + "]: " + msg;
+ if(th != null) {
+ tmp+=", ex: " + th + "\n";
+ StringWriter writer = new StringWriter();
+ PrintWriter pw = new PrintWriter(writer);
+ th.printStackTrace(pw);
+ pw.flush();
+ tmp+= writer.toString();
+ }
+ System.err.println(tmp);
+ }
+
+ private static long random(long range) {
+ return (long)((Math.random() * 100000) % range) + 1;
+ }
+
+
+
+
+
+ }
+
+
+}
Property changes on: projects/cluster/varia/sessionstress/ConnPerClientPerfTest.java
___________________________________________________________________
Name: svn:executable
+ *
Modified: projects/cluster/varia/sessionstress/run.sh
===================================================================
--- projects/cluster/varia/sessionstress/run.sh 2008-01-15 20:05:43 UTC (rev 68991)
+++ projects/cluster/varia/sessionstress/run.sh 2008-01-15 20:26:28 UTC (rev 68992)
@@ -8,4 +8,4 @@
OPTS="-server -Xmn200M -Xmx300M -Xms300M -XX:ThreadStackSize=8k -XX:CompileThreshold=100 -XX:SurvivorRatio=8 -XX:TargetSurvivorRatio=90 -XX:MaxTenuringThreshold=31"
-java -classpath $CP $OPTS multicast.PerfTest -host localhost:8000 $*
+java -classpath $CP $OPTS multicast.ConnPerClientPerfTest -host localhost:8000 $*
More information about the jboss-cvs-commits
mailing list