I'm voting -1 on this commit.

Most of these modifications are not necessary and they break the design of the metrics feature. The one change is useful - fixing the measurement for chained requests (RequestHandler.java ). The rest of the issues mentioned in the commit message do not need to be fixed - they were caused by configuration errors.

-Adrian

On 5/17/2013 3:21 PM, jler...@apache.org wrote:
Author: jleroux
Date: Fri May 17 14:21:02 2013
New Revision: 1483822

URL: http://svn.apache.org/r1483822
Log:
Improves the Metrics stats by adding a new column used only by requests. It's 
quite useful to measure the real (not smoothed) durations of events in notably 
*chained* requests.

Modified:
     ofbiz/trunk/framework/base/src/org/ofbiz/base/metrics/Metrics.java
     ofbiz/trunk/framework/base/src/org/ofbiz/base/metrics/MetricsFactory.java
     ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java
     
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
     ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml
     ofbiz/trunk/framework/webtools/widget/StatsForms.xml

Modified: ofbiz/trunk/framework/base/src/org/ofbiz/base/metrics/Metrics.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/metrics/Metrics.java?rev=1483822&r1=1483821&r2=1483822&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/metrics/Metrics.java 
(original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/metrics/Metrics.java Fri May 
17 14:21:02 2013
@@ -53,6 +53,12 @@ public interface Metrics {
       */
      double getServiceRate();
+ /**
+     * Returns a moving average of the request rate in milliseconds. The 
default
+     * implementation divides the total time by the total number of events
+     */
+    double getRequestRate();
+
      /** Returns the metric threshold. The meaning of the threshold is
       * determined by client code.
       * <p>The idea is for client code to compare {@link #getServiceRate()} to
@@ -69,6 +75,13 @@ public interface Metrics {
       */
      void recordServiceRate(int numEvents, long time);
+ /**
+     * Records the request time for <code>numEvents</code> taking
+     * <code>time</code> milliseconds to be processed.
+     */
+    void recordRequestRate(int numEvents, long time);
+
      /** Resets all metrics. */
      void reset();
+
  }
\ No newline at end of file

Modified: 
ofbiz/trunk/framework/base/src/org/ofbiz/base/metrics/MetricsFactory.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/base/src/org/ofbiz/base/metrics/MetricsFactory.java?rev=1483822&r1=1483821&r2=1483822&view=diff
==============================================================================
--- ofbiz/trunk/framework/base/src/org/ofbiz/base/metrics/MetricsFactory.java 
(original)
+++ ofbiz/trunk/framework/base/src/org/ofbiz/base/metrics/MetricsFactory.java 
Fri May 17 14:21:02 2013
@@ -144,6 +144,7 @@ public final class MetricsFactory {
          private long lastTime = System.currentTimeMillis();
          @LockedBy("this")
          private double serviceRate = 0.0;
+        private double requestRate = 0.0;
          @LockedBy("this")
          private long totalServiceTime = 0;
          @LockedBy("this")
@@ -187,6 +188,11 @@ public final class MetricsFactory {
          }
@Override
+        public synchronized double getRequestRate() {
+            return requestRate;
+        }
+
+        @Override
          public double getThreshold() {
              return threshold;
          }
@@ -220,9 +226,17 @@ public final class MetricsFactory {
              }
          }
+ public synchronized void recordRequestRate(int numEvents, long time) {
+            totalEvents += numEvents;
+            cumulativeEvents += numEvents;
+            totalServiceTime += time;
+            requestRate = totalServiceTime / cumulativeEvents;
+        }
+
          @Override
          public synchronized void reset() {
              serviceRate = 0.0;
+            requestRate = 0.0;
              count = 0;
              lastTime = System.currentTimeMillis();
              totalEvents = totalServiceTime = cumulativeEvents = 0;
@@ -247,6 +261,11 @@ public final class MetricsFactory {
          }
@Override
+        public double getRequestRate() {
+            return 0;
+        }
+
+        @Override
          public double getThreshold() {
              return 0.0;
          }
@@ -261,6 +280,10 @@ public final class MetricsFactory {
          }
@Override
+        public void recordRequestRate(int numEvents, long time) {
+        }
+
+        @Override
          public void reset() {
          }
      }

Modified: ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java?rev=1483822&r1=1483821&r2=1483822&view=diff
==============================================================================
--- ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java 
(original)
+++ ofbiz/trunk/framework/common/src/org/ofbiz/common/CommonServices.java Fri 
May 17 14:21:02 2013
@@ -552,6 +552,7 @@ public class CommonServices {
              Map<String, Object> metricsMap = FastMap.newInstance();
              metricsMap.put("name", metrics.getName());
              metricsMap.put("serviceRate", metrics.getServiceRate());
+            metricsMap.put("requestRate", metrics.getRequestRate());
              metricsMap.put("threshold", metrics.getThreshold());
              metricsMap.put("totalEvents", metrics.getTotalEvents());
              metricsMapList.add(metricsMap);

Modified: 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?rev=1483822&r1=1483821&r2=1483822&view=diff
==============================================================================
--- 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java 
(original)
+++ 
ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java 
Fri May 17 14:21:02 2013
@@ -109,6 +109,7 @@ public class RequestHandler {
              GenericValue userLogin, Delegator delegator) throws 
RequestHandlerException, RequestHandlerExceptionAllowExternalRequests {
long startTime = System.currentTimeMillis();
+        int numEvent = 1;
          HttpSession session = request.getSession();
// get the controllerConfig once for this method so we don't have to get it over and over inside the method
@@ -421,6 +422,11 @@ public class RequestHandler {
                          ServerHitBin.countEvent(cname + "." + 
requestMap.event.invoke, request, eventStartTime,
                                  System.currentTimeMillis() - eventStartTime, 
userLogin);
                      }
+                    if (requestMap.metrics != null) {
+                        requestMap.metrics.recordRequestRate(numEvent, 
System.currentTimeMillis() - eventStartTime);
+                        numEvent = 0;
+                    }
+
// set the default event return
                      if (eventReturn == null) {
@@ -676,7 +682,7 @@ public class RequestHandler {
              }
          }
          if (requestMap.metrics != null) {
-            requestMap.metrics.recordServiceRate(1, System.currentTimeMillis() 
- startTime);
+            requestMap.metrics.recordServiceRate(numEvent, 
System.currentTimeMillis() - startTime);
          }
      }
Modified: ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml?rev=1483822&r1=1483821&r2=1483822&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml (original)
+++ ofbiz/trunk/framework/webtools/config/WebtoolsUiLabels.xml Fri May 17 
14:21:02 2013
@@ -3405,8 +3405,13 @@
          <value xml:lang="ja">メトリックス</value>
          <value xml:lang="zh">度量</value>
      </property>
-    <property key="WebtoolsMetricsRate">
+    <property key="WebtoolsMetricsRequestRate">
+        <value xml:lang="en">Request/Event Rate (mS)</value>
+        <value xml:lang="fr">Durée des requêtes/évènements (mS)</value>
+    </property>
+    <property key="WebtoolsMetricsServiceRate">
          <value xml:lang="en">Service Rate (mS)</value>
+        <value xml:lang="fr">Durée des Services (mS)</value>
          <value xml:lang="ja">サービスレート(ミリ秒)</value>
          <value xml:lang="zh">服务速率(毫秒)</value>
      </property>
@@ -5053,7 +5058,7 @@
      <property key="WebtoolsStatsNoRequests">
          <value xml:lang="de">Es wurden keine Anfragestatistiken 
gefunden.</value>
          <value xml:lang="en">No Request statistics found.</value>
-        <value xml:lang="fr">Aucune requêt de statistiques trouvée</value>
+        <value xml:lang="fr">Aucune requête de statistiques trouvée</value>
          <value xml:lang="it">Nessuna statistica delle request trovata.</value>
          <value xml:lang="ja">リクエスト統計はありません</value>
          <value xml:lang="pt">Nenhum pedido de estatísticas 
encontrado.</value>

Modified: ofbiz/trunk/framework/webtools/widget/StatsForms.xml
URL: 
http://svn.apache.org/viewvc/ofbiz/trunk/framework/webtools/widget/StatsForms.xml?rev=1483822&r1=1483821&r2=1483822&view=diff
==============================================================================
--- ofbiz/trunk/framework/webtools/widget/StatsForms.xml (original)
+++ ofbiz/trunk/framework/webtools/widget/StatsForms.xml Fri May 17 14:21:02 
2013
@@ -49,13 +49,14 @@ under the License.
      <form name="ListMetrics" type="list" list-name="metricsList" 
paginate-target="ViewMetrics"
              header-row-style="header-row-2" default-table-style="basic-table 
light-grid">
          <actions>
-            <service service-name="getAllMetrics" />
-        </actions>
-        <field name="name" title="${uiLabelMap.CommonName}"><display/></field>
-        <field name="serviceRate" 
title="${uiLabelMap.WebtoolsMetricsRate}"><display/></field>
-        <field name="threshold" 
title="${uiLabelMap.WebtoolsMetricsThreshold}"><display/></field>
-        <field name="totalEvents" 
title="${uiLabelMap.WebtoolsMetricsTotalEvents}"><display/></field>
-        <field name="resetMetric" title=" " widget-area-style="button-col">
+            <service service-name="getAllMetrics" />
+        </actions>
+        <field name="name" title="${uiLabelMap.CommonName}"><display/></field>
+        <field name="serviceRate" 
title="${uiLabelMap.WebtoolsMetricsServiceRate}"><display/></field>
+        <field name="requestRate" 
title="${uiLabelMap.WebtoolsMetricsRequestRate}"><display/></field>
+        <field name="threshold" 
title="${uiLabelMap.WebtoolsMetricsThreshold}"><display/></field>
+        <field name="totalEvents" 
title="${uiLabelMap.WebtoolsMetricsTotalEvents}"><display/></field>
+        <field name="resetMetric" title=" " widget-area-style="button-col">
              <hyperlink description="${uiLabelMap.CommonReset}" 
target="ResetMetric">
                  <parameter param-name="name"/>
              </hyperlink>



Reply via email to