[jboss-cvs] JBossAS SVN: r69009 - projects/cluster/varia/sessionstress.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 15 23:48:21 EST 2008


Author: bstansberry at jboss.com
Date: 2008-01-15 23:48:21 -0500 (Tue, 15 Jan 2008)
New Revision: 69009

Modified:
   projects/cluster/varia/sessionstress/ConnPerClientPerfTest.java
Log:
Release conn every 10 requests

Modified: projects/cluster/varia/sessionstress/ConnPerClientPerfTest.java
===================================================================
--- projects/cluster/varia/sessionstress/ConnPerClientPerfTest.java	2008-01-16 04:18:32 UTC (rev 69008)
+++ projects/cluster/varia/sessionstress/ConnPerClientPerfTest.java	2008-01-16 04:48:21 UTC (rev 69009)
@@ -14,6 +14,8 @@
 import java.text.NumberFormat;
 import java.util.concurrent.BrokenBarrierException;
 import java.util.concurrent.CyclicBarrier;
+import java.util.HashSet;
+import java.util.Set;
 import java.util.concurrent.TimeUnit;
 
 /**
@@ -54,10 +56,22 @@
             clients[i]=client;
             client.start();
         }
-
+        
+        System.out.println("Waiting for clients to initialize");
+        barrier.await();
+        
+        Reaper reaper = new Reaper(clients);
+        reaper.start();
+        if (reaper.isAlive())
+           reaper.interrupt();
+        
         System.out.println("Waiting for clients to complete");
         barrier.await();
 
+        reaper.terminate();
+        reaper.join(2000);
+        reaper.reap();
+        
         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;
 
@@ -202,6 +216,27 @@
         new ConnPerClientPerfTest().start(host, setup_url, read_url, write_url, destroy_url, num_threads, num_requests, num_attrs, size, write_percentage);
     }
 
+    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;
+    }
+
     private static void help() {
         System.out.println("PerfTest [-host <host[:port] of apache>] [-read_url <URL>] " +
                 "[-num_threads <number of client sessions>] " +
@@ -209,16 +244,58 @@
                 "[-num_attrs <attrs>] [-size <bytes>] [-write_percentage <percentage, 0-100>]");
     }
 
+    private static class Reaper extends Thread {
+       
+       private final Client[] clients;
+       private boolean stopped;
+       
+       private Reaper(Client[] clients) {
+          this.clients = clients;
+       }
+       
+       public void run() {
+          while (!stopped) {
+             reap();
+             try {
+                Thread.sleep(15000);
+             }
+             catch (InterruptedException ie) {
+                break;
+             }
+          }
+       }
+       
+       public void reap() {
+          for (Client client : clients) {
+             Set<SimpleHttpConnectionManager> oldMgrs = new HashSet<SimpleHttpConnectionManager>(client.oldManagers);
+             client.oldManagers.clear();
+             for (SimpleHttpConnectionManager mgr : oldMgrs) {
+                try {
+                   mgr.shutdown();
+                }
+                catch (Exception e) {
+                   error("Failed shutting down manager", e);
+                }
+             }
+          }
+       }
+       
+       public void terminate() {
+          stopped = true;
+       }
+       
+    }
 
     private static class Client extends Thread {
         private final int           read_percentage;
         private final int           num_requests, num_attrs, size;
-        private final HttpClient    session;
+        private SimpleHttpConnectionManager connManager;
+        private HttpClient    session;
         private final GetMethod     setup_method, destroy_method;
         private final String        read_url;
         private final String        write_url;
         private final CyclicBarrier barrier;
-
+        private final Set<SimpleHttpConnectionManager> oldManagers = new HashSet<SimpleHttpConnectionManager>();
         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;
@@ -239,20 +316,31 @@
             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);
+            createClient();
         }
+        
+        void createClient() {
+           if (this.connManager != null)
+              oldManagers.add(connManager);
+           connManager = new SimpleHttpConnectionManager();
+           connManager.getParams().setStaleCheckingEnabled(true);
+           this.session = new HttpClient(connManager);
+        }
 
         public void run() {
+            boolean inited = false;
             try {
                 init(num_attrs, size);
+                log("inited: " + barrier.getNumberWaiting() + " threads waiting");
+                try { barrier.await(); } finally { inited = true; }
                 start=System.currentTimeMillis();
                 loop(num_requests);
             }
             catch(Exception e) {
                 error("failure", e);
                 successful=false;
+                if (!inited)
+                   try { barrier.await(); }  catch(Exception e1) {}
             }
             finally {
                 stop=System.currentTimeMillis();
@@ -348,6 +436,9 @@
                      else {
                          failed_writes++;
                      }
+                     
+                     // create a new client
+                     createClient();
                 }
                 total++;
                 if(total % print == 0)
@@ -370,31 +461,6 @@
            }
         }
 
-        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;
-        }
-
-
-
-
-
     }
 
 




More information about the jboss-cvs-commits mailing list