commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pste...@apache.org
Subject svn commit: r641124 - in /commons/sandbox/performance/trunk/src/java/org/apache/commons/performance: ClientThread.java LoadGenerator.java Statistics.java
Date Wed, 26 Mar 2008 02:56:39 GMT
Author: psteitz
Date: Tue Mar 25 19:56:37 2008
New Revision: 641124

URL: http://svn.apache.org/viewvc?rev=641124&view=rev
Log:
Completed implementation of statistics aggregators.

Modified:
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ClientThread.java
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/LoadGenerator.java
    commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java

Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ClientThread.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ClientThread.java?rev=641124&r1=641123&r2=641124&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ClientThread.java
(original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/ClientThread.java
Tue Mar 25 19:56:37 2008
@@ -179,12 +179,16 @@
             return;
         }
         
-        // Report statistics
-        logger.info(stats.toString() + 
+        // Use thread name as process name
+        String process = Thread.currentThread().getName();
+        
+        // Record latency statistics
+        stats.addStatistics(responseStats, process, "latency");
+        
+        // Log accumulated statistics for this thread
+        logger.info(stats.displayProcessStatistics(process) + 
           "Number of misses: " + numMisses + "\n" +
-          "Number or errors: " + numErrors + "\n");
-        stats.addStatistics(
-                responseStats, Thread.currentThread().getName(), "latency");
+          "Number or errors: " + numErrors + "\n"); 
     }
     
     /** Executed once at the beginning of the run */

Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/LoadGenerator.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/LoadGenerator.java?rev=641124&r1=641123&r2=641124&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/LoadGenerator.java
(original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/LoadGenerator.java
Tue Mar 25 19:56:37 2008
@@ -109,21 +109,8 @@
         // TODO: make this configurable
         ex.awaitTermination(60 * 60 * 24, TimeUnit.SECONDS);
         
-        // Compute and log summary statistics for accumulated metrics
-        Iterator<String> metricsIterator = stats.getTypes().iterator();
-        while (metricsIterator.hasNext()) {
-            String metric = metricsIterator.next();
-            logger.info("********** " + metric.toUpperCase() + " **********");
-            logger.info("Overall statistics for the mean " + metric);
-            logger.info(stats.getMeanSummary(metric).toString());
-            logger.info("Overall statistics for the standard deviation " 
-                    + metric);
-            logger.info(stats.getStdSummary(metric).toString());
-            logger.info("Overall statistics for the min " + metric);
-            logger.info(stats.getMinSummary(metric).toString());
-            logger.info("Overall statistics for the max " + metric);
-            logger.info(stats.getMaxSummary(metric).toString());      
-        }
+        // Log summary statistics for accumulated metrics
+        logger.info(stats.displayOverallSummary());
 	}
     
     protected abstract ClientThread makeClientThread(

Modified: commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java
URL: http://svn.apache.org/viewvc/commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java?rev=641124&r1=641123&r2=641124&view=diff
==============================================================================
--- commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java
(original)
+++ commons/sandbox/performance/trunk/src/java/org/apache/commons/performance/Statistics.java
Tue Mar 25 19:56:37 2008
@@ -29,53 +29,53 @@
  * <p>Maintains a HashMap of SummaryStatistics instances with a composite
  * key of the form <process,type>.  "Process" typically identifies the client
  * thread and "type" identifies the metric - e.g., "latency", "numActive."</p>
- * 
- * <p>NOTE: None of the methods of this class are synchronized.  For general
- * use outside of Commons Performance, synchronization (if necessary) must be
- * handled by client code.</p>
  *
  */
 public class Statistics {
     private HashMap<StatisticsKey,SummaryStatistics> data = 
         new HashMap <StatisticsKey,SummaryStatistics>();
-   
+    
     /**
-     * Adds a SummaryStatistics instance with key = <process,type>
+     * Adds the results of the given SummaryStatistics instance under
+     * the key <process,type>
      * 
-     * @param stats the SummaryStatistics to add
+     * @param stats the SummaryStatistics whose results we are adding
      * @param process name of the associated process
      * @param type description of the associated metric
      */
-    public void addStatistics(SummaryStatistics stats, String process, String type) {
+    public synchronized void addStatistics(SummaryStatistics stats,
+            String process, String type) {
         StatisticsKey key = new StatisticsKey(process, type);
         data.put(key, stats);
     }
     
     /**
-     * Retrieves the SummaryStatistics instance corresponding to the given
-     * process and type, if such an instance exists; null otherwise.
+     * Retrieves the SummaryStatistics corresponding to the given
+     * process and type, if this exists; null otherwise.
      * 
      * @param process name of the associated process
      * @param type description of the associated metric
      * @return SummaryStatistics for the given <process,type>; null if there is
      * no such element in the container
      */
-    public SummaryStatistics getStatistics(String process, String type) {
-        return data.get(new StatisticsKey(process, type));
+    public synchronized SummaryStatistics getStatistics(String process,
+            String type) {
+        StatisticsKey key = new StatisticsKey(process, type);
+        return data.get(key);
     }
     
     /**
-     * Returns the full list of SummaryStatistics instances corresponding to
+     * Returns the full list of SummaryStatistics corresponding to
      * the given <code>type</code> - i.e, the list of statistics of the 
      * given type across processes.  For example, 
-     * <code>getStatistics("latency")</code> will return a list of latency
+     * <code>getStatisticsByType("latency")</code> will return a list of latency
      * summaries, one for each process, assuming "latency" is the name of 
      * an accumulated metric.
      * 
      * @param type the type value to get statistics for
-     * @return the List of SummmaryStatistics stored under the given type
+     * @return the List of SummaryStatistics stored under the given type
      */
-    public List<SummaryStatistics> getStatistics(String type) {
+    public synchronized List<SummaryStatistics> getStatisticsByType(String type) {
         ArrayList<SummaryStatistics> result = new ArrayList<SummaryStatistics>();
         Iterator<StatisticsKey> it = data.keySet().iterator();
         while (it.hasNext()) {
@@ -88,20 +88,43 @@
     }
     
     /**
-     * Returns SummaryStatistics for the mean of the given metric across
-     * processes - i.e., the "mean of the means", the "min of the means"
-     * etc. More precisely, the returned SummaryStatistics instance describes
-     * the distribution of the individual process means for the given metric.
-     * The same results could be obtained by iterating over the result of 
-     * {{@link #getStatistics(String)} for the given <code>type</code>,
+     * Returns the full list of SummaryStatistics corresponding to
+     * the given <code>process</code> - i.e, the list of statistics of
+     * of different types maintained for the given process. 
+     * 
+     * @param type the type value to get statistics for
+     * @return the List of SummaryStatistics for the given process
+     */
+    public synchronized List<SummaryStatistics> getStatisticsByProcess(
+            String process) {
+        ArrayList<SummaryStatistics> result = new ArrayList<SummaryStatistics>();
+        Iterator<StatisticsKey> it = data.keySet().iterator();
+        while (it.hasNext()) {
+            StatisticsKey key = it.next();
+            if (key.process.equals(process)) {
+                result.add(data.get(key));
+            }
+        }
+        return result;
+    }
+    
+    /**
+     * <p>Returns a SummaryStatistics instance describing the mean of the given
+     * metric across processes - i.e., the "mean of the means", the 
+     * "min of the means" etc. More precisely, the returned SummaryStatistics
+     * describes the distribution of the individual process means for the given
+     * metric.</p>
+     * 
+     * <p>The same results could be obtained by iterating over the result of 
+     * {{@link #getStatisticsByType(String)} for the given <code>type</code>,
      * extracting the mean and adding its value to a SummaryStatistics
-     * instance.
+     * instance.</p>
      * 
      * @param type the metric to get summary mean statistics for
      * @return a SummaryStatistics instance describing the process means for
      * the given metric
      */
-    public SummaryStatistics getMeanSummary(String type) {
+    public synchronized SummaryStatistics getMeanSummary(String type) {
         SummaryStatistics result = new SummaryStatistics();
         Iterator<StatisticsKey> it = data.keySet().iterator();
         while (it.hasNext()) {
@@ -110,7 +133,7 @@
                 result.addValue(data.get(key).getMean());
             }
         }
-        return result; 
+        return result;
     }
     
     /**
@@ -122,7 +145,7 @@
      * deviations for the given metric
      * @see #getMeanSummary(String)
      */
-    public SummaryStatistics getStdSummary(String type) {
+    public synchronized SummaryStatistics getStdSummary(String type) {
         SummaryStatistics result = new SummaryStatistics();
         Iterator<StatisticsKey> it = data.keySet().iterator();
         while (it.hasNext()) {
@@ -131,7 +154,7 @@
                 result.addValue(data.get(key).getStandardDeviation());
             }
         }
-        return result; 
+        return result;
     }
     
     /**
@@ -143,7 +166,7 @@
      * for the given metric
      * @see #getMeanSummary(String)
      */
-    public SummaryStatistics getMinSummary(String type) {
+    public synchronized SummaryStatistics getMinSummary(String type) {
         SummaryStatistics result = new SummaryStatistics();
         Iterator<StatisticsKey> it = data.keySet().iterator();
         while (it.hasNext()) {
@@ -152,7 +175,7 @@
                 result.addValue(data.get(key).getMin());
             }
         }
-        return result; 
+        return result;
     }
     
     /**
@@ -160,11 +183,11 @@
      * processes.
      * 
      * @param type the metric to get summary maximum statistics for
-     * @return a SummaryStatistics instance describing the process maxima
+     * @return a SummaryStatistics describing the process maxima
      * for the given metric
      * @see #getMeanSummary(String)
      */
-    public SummaryStatistics getMaxSummary(String type) {
+    public synchronized SummaryStatistics getMaxSummary(String type) {
         SummaryStatistics result = new SummaryStatistics();
         Iterator<StatisticsKey> it = data.keySet().iterator();
         while (it.hasNext()) {
@@ -173,7 +196,7 @@
                 result.addValue(data.get(key).getMax());
             }
         }
-        return result; 
+        return result;
     }
     
     /**
@@ -181,7 +204,7 @@
      * 
      * @return List of processes represented in the container
      */
-    public List<String> getProcesses() {
+    public synchronized List<String> getProcesses() {
         ArrayList<String> result = new ArrayList<String>();
         Iterator<StatisticsKey> it = data.keySet().iterator();
         while (it.hasNext()) {
@@ -198,7 +221,7 @@
      * 
      * @return List of types represented in the container
      */
-    public List<String> getTypes() {
+    public synchronized List<String> getTypes() {
         ArrayList<String> result = new ArrayList<String>();
         Iterator<StatisticsKey> it = data.keySet().iterator();
         while (it.hasNext()) {
@@ -211,6 +234,63 @@
     }
     
     /**
+     * Computes and formats display of summary statistics by type, across
+     * processes. 
+     * 
+     * @return String representing summaries for each metric 
+     */
+    public synchronized String displayOverallSummary() {
+        Iterator<String> metricsIterator = getTypes().iterator();
+        StringBuffer buffer = new StringBuffer();
+        while (metricsIterator.hasNext()) {
+            String metric = metricsIterator.next();
+            buffer.append("Overall statistics for the mean ");
+            buffer.append(metric.toUpperCase());
+            buffer.append("\n");
+            buffer.append(getMeanSummary(metric).toString());
+            buffer.append("********************************************\n");
+            buffer.append("Overall statistics for the standard deviation ");
+            buffer.append(metric.toUpperCase());
+            buffer.append("\n");
+            buffer.append(getStdSummary(metric).toString());
+            buffer.append("********************************************\n");
+            buffer.append("Overall statistics for the min ");
+            buffer.append(metric.toUpperCase());
+            buffer.append("\n");
+            buffer.append(getMinSummary(metric).toString());
+            buffer.append("********************************************\n");
+            buffer.append("Overall statistics for the max ");
+            buffer.append(metric.toUpperCase());
+            buffer.append("\n");
+            buffer.append(getMaxSummary(metric).toString());
+            buffer.append("********************************************\n");
+        } 
+        return buffer.toString();
+    }
+    
+    /**
+     * Displays statistics for the given process
+     * 
+     * @param process the process to retrieve metrics for
+     * @return String representing all currently defined statistics for the
+     * given process
+     */
+    public synchronized String displayProcessStatistics(String process) {
+        Iterator<String> metricsIterator = getTypes().iterator();
+        StringBuffer buffer = new StringBuffer();
+        while (metricsIterator.hasNext()) {
+            String metric = metricsIterator.next();
+            buffer.append("*********************************************\n");
+            buffer.append(metric.toUpperCase());
+            buffer.append(" for ");
+            buffer.append(process);
+            buffer.append(getStatistics(process, metric).toString());
+            buffer.append("\n********************************************\n");
+        }
+        return buffer.toString();
+    }
+    
+    /**
      * Composite key (<process,type>).
      */
     private static class StatisticsKey {
@@ -225,8 +305,8 @@
                 return false;
             } else {
                 StatisticsKey other = (StatisticsKey) obj;
-                return other.process == this.process &&
-                    other.type == this.type;  
+                return (other.process.equals(this.process)) &&
+                    (other.type.equals(this.type));  
             }
         }
         public int hashCode() {



Mime
View raw message