Mercurial > stress-tester
changeset 522:b8d7e565adc9
Http metrics synchronization bugfix
author | Devel 2 |
---|---|
date | Fri, 25 Aug 2017 09:50:53 +0200 |
parents | dd71d49065ad |
children | 433b21bb546f |
files | stress-tester/src/main/java/com/passus/st/client/http/HttpClientWorker.java stress-tester/src/main/java/com/passus/st/client/http/HttpFlowBasedClientWorker.java stress-tester/src/main/java/com/passus/st/metric/MetricsBatchTimeWindow.java |
diffstat | 3 files changed, 39 insertions(+), 18 deletions(-) [+] |
line wrap: on
line diff
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpClientWorker.java Fri Aug 25 08:46:27 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpClientWorker.java Fri Aug 25 09:50:53 2017 +0200 @@ -104,10 +104,12 @@ } @Override - public final void writeMetrics(MetricsContainer container) { + public void writeMetrics(MetricsContainer container) { if (collectMetric) { - container.update(System.currentTimeMillis(), metric); - metric.reset(); + synchronized (metric) { + container.update(System.currentTimeMillis(), metric); + metric.reset(); + } } }
--- a/stress-tester/src/main/java/com/passus/st/client/http/HttpFlowBasedClientWorker.java Fri Aug 25 08:46:27 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/client/http/HttpFlowBasedClientWorker.java Fri Aug 25 09:50:53 2017 +0200 @@ -21,6 +21,7 @@ import com.passus.st.emitter.ChannelContext; import com.passus.st.emitter.Emitter; import com.passus.st.emitter.SessionInfo; +import com.passus.st.metric.MetricsContainer; import java.util.Collections; import java.util.HashMap; import java.util.Map; @@ -338,6 +339,13 @@ } @Override + public void writeMetrics(MetricsContainer container) { + synchronized (lock) { + super.writeMetrics(container); + } + } + + @Override public void channelActive(ChannelContext context) throws Exception { synchronized (lock) { HttpFlowContext flowContext = flowContext(context); @@ -430,12 +438,14 @@ } if (collectMetric) { - metric.incResponsesNum(); - metric.addResponseStatusCode(resp.getStatus().getCode()); - metric.addResponseSize(decoder.getHeaderSize() + decoder.getContentSize()); - metric.addResponseReceivingTime(now - flowContext.receivedStartTimestamp); - if (req != null) { - metric.addResponseTime(now - (long) req.getTag(TAG_TIME_START)); + synchronized (metric) { + metric.incResponsesNum(); + metric.addResponseStatusCode(resp.getStatus().getCode()); + metric.addResponseSize(decoder.getHeaderSize() + decoder.getContentSize()); + metric.addResponseReceivingTime(now - flowContext.receivedStartTimestamp); + if (req != null) { + metric.addResponseTime(now - (long) req.getTag(TAG_TIME_START)); + } } } @@ -476,7 +486,9 @@ if (flowContext != null && flowContext.sentEvent != null) { long now = System.currentTimeMillis(); if (collectMetric) { - metric.addRequestSendingTime(now - flowContext.sendStartTimestamp); + synchronized (metric) { + metric.addRequestSendingTime(now - flowContext.sendStartTimestamp); + } } flowContext.sentEvent.getRequest().setTag(TAG_TIME_END, now); @@ -525,9 +537,11 @@ req.setTag(TAG_CONTENT_SIZE, (long) (context.buffer.readableBytes() - headerSize)); if (collectMetric) { - metric.incRequestsNum(); - metric.addRequestSize(context.buffer.readableBytes()); - //metric.addRequestUrl(req.getUrl()); + synchronized (metric) { + metric.incRequestsNum(); + metric.addRequestSize(context.buffer.readableBytes()); + //metric.addRequestUrl(req.getUrl()); + } } try { @@ -536,14 +550,14 @@ context.sendStartTimestamp = now; changeFlowState(context, HttpFlowContext.STATE_REQ_SENT); context.sentEvent = event; - + context.channelContext.writeAndFlush(context.buffer); if (logger.isDebugEnabled()) { debug(context, "Request '{}' sending ({} bytes).", req.getUrl(), context.buffer.length()); } - + context.buffer.clear(); - + return true; } catch (Exception e) { if (logger.isDebugEnabled()) {
--- a/stress-tester/src/main/java/com/passus/st/metric/MetricsBatchTimeWindow.java Fri Aug 25 08:46:27 2017 +0200 +++ b/stress-tester/src/main/java/com/passus/st/metric/MetricsBatchTimeWindow.java Fri Aug 25 09:50:53 2017 +0200 @@ -74,10 +74,15 @@ private Metric doUpdate(MetricsBatchTimeWindowRange range, Metric metric) { Metric rangeMetric = range.get(metric.getName()); if (rangeMetric == null) { - rangeMetric = metric.copy(); + synchronized (metric) { + rangeMetric = metric.copy(); + } + range.put(rangeMetric); } else { - rangeMetric.update(metric); + synchronized (metric) { + rangeMetric.update(metric); + } } return rangeMetric;