changeset 629:290de0f2a667

HttpClientMetric -> HttpClientWorkerMetric
author Devel 1
date Thu, 26 Oct 2017 11:48:39 +0200
parents ace9b1e69e96
children a31b75b6d5e2
files stress-tester/src/main/java/com/passus/st/client/http/HttpClientMetric.java stress-tester/src/main/java/com/passus/st/client/http/HttpClientWorker.java stress-tester/src/main/java/com/passus/st/client/http/HttpClientWorkerMetric.java
diffstat 3 files changed, 239 insertions(+), 239 deletions(-) [+]
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpClientMetric.java	Tue Oct 24 15:26:49 2017 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,237 +0,0 @@
-package com.passus.st.client.http;
-
-import com.passus.commons.Assert;
-import com.passus.commons.metric.LongHistogramMetric;
-import com.passus.commons.metric.LongHistogramMetricImpl;
-import com.passus.commons.metric.Metric;
-import java.io.Serializable;
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import java.util.Set;
-import java.util.TreeMap;
-import org.apache.commons.lang3.mutable.MutableInt;
-
-/**
- *
- * @author Mirosław Hawrot
- */
-public class HttpClientMetric implements Metric {
-
-    private static final int DEFAULT_HISTOGRAM_VALUES = 2048;
-
-    public static final String DEFAULT_NAME = "httpClient";
-
-    private final String name;
-
-    private final Map<String, Serializable> attrs = new LinkedHashMap<>();
-
-    private final MutableInt requestsNum = new MutableInt(0);
-    private final MutableInt responsesNum = new MutableInt(0);
-
-    //private final HashMap<ByteString, MutableInt> reqUrls = new HashMap<>();
-    private final TreeMap<Integer, MutableInt> respStatuses = new TreeMap<>();
-
-    private final LongHistogramMetric responseTimeHistogram = new LongHistogramMetricImpl(DEFAULT_HISTOGRAM_VALUES);
-    private final LongHistogramMetric requestSendingTimeHistogram = new LongHistogramMetricImpl(DEFAULT_HISTOGRAM_VALUES);
-    private final LongHistogramMetric responseReceivingTimeHistogram = new LongHistogramMetricImpl(DEFAULT_HISTOGRAM_VALUES);
-    private final LongHistogramMetric requestSizeHistogram = new LongHistogramMetricImpl(DEFAULT_HISTOGRAM_VALUES);
-    private final LongHistogramMetric responseSizeHistogram = new LongHistogramMetricImpl(DEFAULT_HISTOGRAM_VALUES);
-
-    private boolean active;
-
-    public HttpClientMetric() {
-        this(DEFAULT_NAME);
-    }
-
-    public HttpClientMetric(String name) {
-        Assert.notNull(name, "name");
-        this.name = name;
-        attrs.put("requests", requestsNum);
-        attrs.put("responses", responsesNum);
-        //attrs.put("requestsUrl", reqUrls);
-        attrs.put("responseStatusCodes", respStatuses);
-        attrs.put("responseTimeDist", responseTimeHistogram);
-        attrs.put("requestSendTimeDist", requestSendingTimeHistogram);
-        attrs.put("responseRecvTimeDist", responseReceivingTimeHistogram);
-        attrs.put("requestSizeDist", requestSizeHistogram);
-        attrs.put("responseSizeDist", responseSizeHistogram);
-    }
-
-    @Override
-    public String getName() {
-        return name;
-    }
-
-    @Override
-    public boolean isActive() {
-        return active;
-    }
-
-    @Override
-    public void activate() {
-        responseTimeHistogram.activate();
-        requestSendingTimeHistogram.activate();
-        responseReceivingTimeHistogram.activate();
-        requestSizeHistogram.activate();
-        responseSizeHistogram.activate();
-        active = true;
-    }
-
-    @Override
-    public void deactivate() {
-        if (!active) {
-            return;
-        }
-
-        reset();
-        responseTimeHistogram.deactivate();
-        requestSendingTimeHistogram.deactivate();
-        responseReceivingTimeHistogram.deactivate();
-        requestSizeHistogram.deactivate();
-        responseSizeHistogram.deactivate();
-        active = false;
-    }
-
-    public void incRequestsNum() {
-        requestsNum.increment();
-    }
-
-    public void incResponsesNum() {
-        responsesNum.increment();
-    }
-
-    public int getRequestsNum() {
-        return requestsNum.intValue();
-    }
-
-    public int getResponsesNum() {
-        return responsesNum.intValue();
-    }
-
-    public Map<Integer, MutableInt> getStatusCodes() {
-        return respStatuses;
-    }
-
-    /*public void addRequestUrl(URL url) {
-        MutableInt count = reqUrls.get(url);
-        if (count == null) {
-            count = new MutableInt(1);
-            reqUrls.put(url.toByteString(), count);
-        } else {
-            count.increment();
-        }
-    }*/
-    public void addResponseStatusCode(Integer statusCode) {
-        MutableInt count = respStatuses.get(statusCode);
-        if (count == null) {
-            count = new MutableInt(1);
-            respStatuses.put(statusCode, count);
-        } else {
-            count.increment();
-        }
-    }
-
-    public void addResponseTime(long time) {
-        responseTimeHistogram.update(time);
-    }
-
-    public void addRequestSendingTime(long time) {
-        requestSendingTimeHistogram.update(time);
-    }
-
-    public void addResponseReceivingTime(long time) {
-        responseReceivingTimeHistogram.update(time);
-    }
-
-    public void addRequestSize(long size) {
-        requestSizeHistogram.update(size);
-    }
-
-    public void addResponseSize(long size) {
-        responseSizeHistogram.update(size);
-    }
-
-    @Override
-    public Class getAttributeClass(String name) {
-        Serializable value = getAttributeValue(name);
-        if (value == null) {
-            return null;
-        }
-
-        return value.getClass();
-    }
-
-    @Override
-    public boolean hasAttribute(String name) {
-        return attrs.containsKey(name);
-    }
-
-    @Override
-    public Set<String> getAttributesName() {
-        return attrs.keySet();
-    }
-
-    @Override
-    public Serializable getAttributeValue(String name) {
-        return attrs.get(name);
-    }
-
-    @Override
-    public Map<String, Serializable> getAttributesValue() {
-        return Collections.unmodifiableMap(attrs);
-    }
-
-    @Override
-    public void reset() {
-        requestsNum.setValue(0);
-        responsesNum.setValue(0);
-        //reqUrls.clear();
-        respStatuses.clear();
-        responseTimeHistogram.reset();
-        requestSendingTimeHistogram.reset();
-        responseReceivingTimeHistogram.reset();
-        requestSizeHistogram.reset();
-        responseSizeHistogram.reset();
-    }
-
-    private void update(Map map1, Map map2) {
-        for (Object key : map1.keySet()) {
-            Object value1 = map1.get(key);
-            Object value2 = map2.get(key);
-            if (value2 != null) {
-                ((MutableInt) value1).add((MutableInt) value2);
-            }
-        }
-
-        for (Object key : map2.keySet()) {
-            if (!map1.containsKey(key)) {
-                map1.put(key, map2.get(key));
-            }
-        }
-    }
-
-    @Override
-    public void update(Metric metric) {
-        if (!(metric instanceof HttpClientMetric)) {
-            throw new IllegalArgumentException(LongHistogramMetric.class + " required.");
-        }
-
-        HttpClientMetric clientMetric = (HttpClientMetric) metric;
-        requestsNum.add(clientMetric.requestsNum);
-        responsesNum.add(clientMetric.responsesNum);
-        //update(reqUrls, clientMetric.reqUrls);
-        update(respStatuses, clientMetric.respStatuses);
-        responseTimeHistogram.update(clientMetric.responseTimeHistogram);
-        requestSendingTimeHistogram.update(clientMetric.requestSendingTimeHistogram);
-        responseReceivingTimeHistogram.update(clientMetric.responseReceivingTimeHistogram);
-        requestSizeHistogram.update(clientMetric.requestSizeHistogram);
-        responseSizeHistogram.update(clientMetric.responseSizeHistogram);
-    }
-
-    @Override
-    public String toString() {
-        return "HttpClientMetric{" + "requestsNum=" + requestsNum + ", responsesNum=" + responsesNum + ", respStatuses=" + respStatuses + '}';
-    }
-
-}
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpClientWorker.java	Tue Oct 24 15:26:49 2017 +0200
+++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpClientWorker.java	Thu Oct 26 11:48:39 2017 +0200
@@ -36,7 +36,7 @@
 
     protected boolean collectMetric;
 
-    protected HttpClientMetric metric;
+    protected HttpClientWorkerMetric metric;
 
     protected boolean connectPartialSession = false;
 
@@ -93,7 +93,7 @@
     @Override
     public void setCollectMetrics(boolean collectMetrics) {
         if (collectMetrics && metric == null) {
-            metric = new HttpClientMetric();
+            metric = new HttpClientWorkerMetric();
             metric.activate();
             collectMetric = true;
         } else if (!collectMetrics && metric != null) {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpClientWorkerMetric.java	Thu Oct 26 11:48:39 2017 +0200
@@ -0,0 +1,237 @@
+package com.passus.st.client.http;
+
+import com.passus.commons.Assert;
+import com.passus.commons.metric.LongHistogramMetric;
+import com.passus.commons.metric.LongHistogramMetricImpl;
+import com.passus.commons.metric.Metric;
+import java.io.Serializable;
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import java.util.Set;
+import java.util.TreeMap;
+import org.apache.commons.lang3.mutable.MutableInt;
+
+/**
+ *
+ * @author Mirosław Hawrot
+ */
+public class HttpClientWorkerMetric implements Metric {
+
+    private static final int DEFAULT_HISTOGRAM_VALUES = 2048;
+
+    public static final String DEFAULT_NAME = "httpClientWorker";
+
+    private final String name;
+
+    private final Map<String, Serializable> attrs = new LinkedHashMap<>();
+
+    private final MutableInt requestsNum = new MutableInt(0);
+    private final MutableInt responsesNum = new MutableInt(0);
+
+    //private final HashMap<ByteString, MutableInt> reqUrls = new HashMap<>();
+    private final TreeMap<Integer, MutableInt> respStatuses = new TreeMap<>();
+
+    private final LongHistogramMetric responseTimeHistogram = new LongHistogramMetricImpl(DEFAULT_HISTOGRAM_VALUES);
+    private final LongHistogramMetric requestSendingTimeHistogram = new LongHistogramMetricImpl(DEFAULT_HISTOGRAM_VALUES);
+    private final LongHistogramMetric responseReceivingTimeHistogram = new LongHistogramMetricImpl(DEFAULT_HISTOGRAM_VALUES);
+    private final LongHistogramMetric requestSizeHistogram = new LongHistogramMetricImpl(DEFAULT_HISTOGRAM_VALUES);
+    private final LongHistogramMetric responseSizeHistogram = new LongHistogramMetricImpl(DEFAULT_HISTOGRAM_VALUES);
+
+    private boolean active;
+
+    public HttpClientWorkerMetric() {
+        this(DEFAULT_NAME);
+    }
+
+    public HttpClientWorkerMetric(String name) {
+        Assert.notNull(name, "name");
+        this.name = name;
+        attrs.put("requests", requestsNum);
+        attrs.put("responses", responsesNum);
+        //attrs.put("requestsUrl", reqUrls);
+        attrs.put("responseStatusCodes", respStatuses);
+        attrs.put("responseTimeDist", responseTimeHistogram);
+        attrs.put("requestSendTimeDist", requestSendingTimeHistogram);
+        attrs.put("responseRecvTimeDist", responseReceivingTimeHistogram);
+        attrs.put("requestSizeDist", requestSizeHistogram);
+        attrs.put("responseSizeDist", responseSizeHistogram);
+    }
+
+    @Override
+    public String getName() {
+        return name;
+    }
+
+    @Override
+    public boolean isActive() {
+        return active;
+    }
+
+    @Override
+    public void activate() {
+        responseTimeHistogram.activate();
+        requestSendingTimeHistogram.activate();
+        responseReceivingTimeHistogram.activate();
+        requestSizeHistogram.activate();
+        responseSizeHistogram.activate();
+        active = true;
+    }
+
+    @Override
+    public void deactivate() {
+        if (!active) {
+            return;
+        }
+
+        reset();
+        responseTimeHistogram.deactivate();
+        requestSendingTimeHistogram.deactivate();
+        responseReceivingTimeHistogram.deactivate();
+        requestSizeHistogram.deactivate();
+        responseSizeHistogram.deactivate();
+        active = false;
+    }
+
+    public void incRequestsNum() {
+        requestsNum.increment();
+    }
+
+    public void incResponsesNum() {
+        responsesNum.increment();
+    }
+
+    public int getRequestsNum() {
+        return requestsNum.intValue();
+    }
+
+    public int getResponsesNum() {
+        return responsesNum.intValue();
+    }
+
+    public Map<Integer, MutableInt> getStatusCodes() {
+        return respStatuses;
+    }
+
+    /*public void addRequestUrl(URL url) {
+        MutableInt count = reqUrls.get(url);
+        if (count == null) {
+            count = new MutableInt(1);
+            reqUrls.put(url.toByteString(), count);
+        } else {
+            count.increment();
+        }
+    }*/
+    public void addResponseStatusCode(Integer statusCode) {
+        MutableInt count = respStatuses.get(statusCode);
+        if (count == null) {
+            count = new MutableInt(1);
+            respStatuses.put(statusCode, count);
+        } else {
+            count.increment();
+        }
+    }
+
+    public void addResponseTime(long time) {
+        responseTimeHistogram.update(time);
+    }
+
+    public void addRequestSendingTime(long time) {
+        requestSendingTimeHistogram.update(time);
+    }
+
+    public void addResponseReceivingTime(long time) {
+        responseReceivingTimeHistogram.update(time);
+    }
+
+    public void addRequestSize(long size) {
+        requestSizeHistogram.update(size);
+    }
+
+    public void addResponseSize(long size) {
+        responseSizeHistogram.update(size);
+    }
+
+    @Override
+    public Class getAttributeClass(String name) {
+        Serializable value = getAttributeValue(name);
+        if (value == null) {
+            return null;
+        }
+
+        return value.getClass();
+    }
+
+    @Override
+    public boolean hasAttribute(String name) {
+        return attrs.containsKey(name);
+    }
+
+    @Override
+    public Set<String> getAttributesName() {
+        return attrs.keySet();
+    }
+
+    @Override
+    public Serializable getAttributeValue(String name) {
+        return attrs.get(name);
+    }
+
+    @Override
+    public Map<String, Serializable> getAttributesValue() {
+        return Collections.unmodifiableMap(attrs);
+    }
+
+    @Override
+    public void reset() {
+        requestsNum.setValue(0);
+        responsesNum.setValue(0);
+        //reqUrls.clear();
+        respStatuses.clear();
+        responseTimeHistogram.reset();
+        requestSendingTimeHistogram.reset();
+        responseReceivingTimeHistogram.reset();
+        requestSizeHistogram.reset();
+        responseSizeHistogram.reset();
+    }
+
+    private void update(Map<Integer, MutableInt> map1, Map<Integer, MutableInt> map2) {
+        for (Integer key : map1.keySet()) {
+            MutableInt value1 = map1.get(key);
+            MutableInt value2 = map2.get(key);
+            if (value2 != null) {
+                value1.add(value2);
+            }
+        }
+
+        for (Integer key : map2.keySet()) {
+            if (!map1.containsKey(key)) {
+                map1.put(key, map2.get(key));
+            }
+        }
+    }
+
+    @Override
+    public void update(Metric metric) {
+        if (!(metric instanceof HttpClientWorkerMetric)) {
+            throw new IllegalArgumentException(LongHistogramMetric.class + " required.");
+        }
+
+        HttpClientWorkerMetric clientMetric = (HttpClientWorkerMetric) metric;
+        requestsNum.add(clientMetric.requestsNum);
+        responsesNum.add(clientMetric.responsesNum);
+        //update(reqUrls, clientMetric.reqUrls);
+        update(respStatuses, clientMetric.respStatuses);
+        responseTimeHistogram.update(clientMetric.responseTimeHistogram);
+        requestSendingTimeHistogram.update(clientMetric.requestSendingTimeHistogram);
+        responseReceivingTimeHistogram.update(clientMetric.responseReceivingTimeHistogram);
+        requestSizeHistogram.update(clientMetric.requestSizeHistogram);
+        responseSizeHistogram.update(clientMetric.responseSizeHistogram);
+    }
+
+    @Override
+    public String toString() {
+        return "HttpClientMetric{" + "requestsNum=" + requestsNum + ", responsesNum=" + responsesNum + ", respStatuses=" + respStatuses + '}';
+    }
+
+}