You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by wo...@apache.org on 2005/10/25 05:45:23 UTC
svn commit: r328249 - in
/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers:
SampleEvent.java SampleResult.java SampleSenderFactory.java
StatisticalSampleResult.java StatisticalSampleSender.java
Author: woolfel
Date: Mon Oct 24 20:45:17 2005
New Revision: 328249
URL: http://svn.apache.org/viewcvs?rev=328249&view=rev
Log:
checking in part of the contribution submitted by Lars Krog-Jensen.
I still need to go over the visualizer and change it to use JCharts
peter lin
Added:
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/StatisticalSampleResult.java
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/StatisticalSampleSender.java
Modified:
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleEvent.java
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleResult.java
jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleSenderFactory.java
Modified: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleEvent.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleEvent.java?rev=328249&r1=328248&r2=328249&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleEvent.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleEvent.java Mon Oct 24 20:45:17 2005
@@ -19,6 +19,8 @@
package org.apache.jmeter.samplers;
import java.io.Serializable;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
/**
* Packages information regarding the target of a sample event, such as the
@@ -27,16 +29,29 @@
* @version $Revision$
*/
public class SampleEvent implements Serializable {
+ public static String HOSTNMAME;
+
+ static {
+ try {
+ HOSTNMAME = InetAddress.getLocalHost().getHostName();
+ } catch (UnknownHostException e) {
+ e.printStackTrace();
+ }
+ }
+
SampleResult result;
String threadGroup;
+ String hostname;
+
public SampleEvent() {
}
public SampleEvent(SampleResult result, String threadGroup) {
this.result = result;
this.threadGroup = threadGroup;
+ this.hostname = HOSTNMAME;
}
public SampleResult getResult() {
@@ -45,5 +60,9 @@
public String getThreadGroup() {
return threadGroup;
+ }
+
+ public String getHostname() {
+ return hostname;
}
}
Modified: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleResult.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleResult.java?rev=328249&r1=328248&r2=328249&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleResult.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleResult.java Mon Oct 24 20:45:17 2005
@@ -109,9 +109,9 @@
private long timeStamp = 0;// the time stamp - can be start or end
- private long startTime = 0;
+ private long startTime = 0; // changed to protected for subclass
- private long endTime = 0;
+ private long endTime = 0; // changed to protected for subclass
private long idleTime = 0;// Allow for non-sample time
@@ -545,6 +545,13 @@
contentType = string;
}
+ /**
+ * @return idleTime
+ */
+ public long getIdleTime() {
+ return idleTime;
+ }
+
/**
* @return the end time
*/
@@ -572,7 +579,7 @@
}
}
- private void setEndTime(long end) {
+ protected void setEndTime(long end) {
endTime = end;
if (!startTimeStamp) {
timeStamp = endTime;
Modified: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleSenderFactory.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleSenderFactory.java?rev=328249&r1=328248&r2=328249&view=diff
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleSenderFactory.java (original)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/SampleSenderFactory.java Mon Oct 24 20:45:17 2005
@@ -18,9 +18,11 @@
package org.apache.jmeter.samplers;
import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jmeter.samplers.StatisticalSampleSender;
/**
* @author Michael Freeman
+ * 10/24/2005 - added statistical mode for distributed testing
*/
public class SampleSenderFactory {
/**
@@ -43,6 +45,9 @@
} else if (type.equalsIgnoreCase("Batch")) {
BatchSampleSender b = new BatchSampleSender(listener);
return b;
+ } else if (type.equalsIgnoreCase("Statistical")) {
+ StatisticalSampleSender s = new StatisticalSampleSender(listener);
+ return s;
} else {
StandardSampleSender s = new StandardSampleSender(listener);
return s;
Added: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/StatisticalSampleResult.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/StatisticalSampleResult.java?rev=328249&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/StatisticalSampleResult.java (added)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/StatisticalSampleResult.java Mon Oct 24 20:45:17 2005
@@ -0,0 +1,78 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.samplers;
+
+import java.io.Serializable;
+
+/**
+ * @author Lars Krog-Jensen
+ * Created: 2005-okt-04
+ */
+public class StatisticalSampleResult extends SampleResult implements
+ Serializable {
+
+ protected int errorCount;
+
+ public StatisticalSampleResult(SampleResult res) {
+ setSampleLabel(res.getSampleLabel());
+ }
+
+ public void add(SampleResult res) {
+ // Add Sample Counter
+ setSampleCount(getSampleCount() + res.getSampleCount());
+
+ // Add bytes
+ int bytesLength = 0;
+ // in case the sampler doesn't return the contents
+ // we see if the bytes was set
+ if (res.getResponseData() == null || res.getResponseData().length == 0) {
+ bytesLength = res.getBytes();
+ } else {
+ bytesLength = res.getResponseData().length;
+ }
+ setBytes(getBytes() + bytesLength);
+
+ // Add Error Counter
+ if (!res.isSuccessful()) {
+ errorCount++;
+ }
+
+ // Set start/end times
+ this.setStartTime(Math.min(getStartTime(), res.getStartTime()));
+ this.setEndTime(Math.max(getEndTime(), res.getEndTime()));
+ }
+
+ public long getTime() {
+ return getEndTime() - getStartTime() - this.getIdleTime();
+ }
+
+ public long getTimeStamp() {
+ return getEndTime();
+ }
+
+ public int getErrorCount() {
+ return errorCount;
+ }
+
+ public static String getKey(SampleEvent event) {
+ String key = event.getResult().getSampleLabel() + "-"
+ + event.getThreadGroup();
+
+ return key;
+ }
+}
Added: jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/StatisticalSampleSender.java
URL: http://svn.apache.org/viewcvs/jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/StatisticalSampleSender.java?rev=328249&view=auto
==============================================================================
--- jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/StatisticalSampleSender.java (added)
+++ jakarta/jmeter/branches/rel-2-1/src/core/org/apache/jmeter/samplers/StatisticalSampleSender.java Mon Oct 24 20:45:17 2005
@@ -0,0 +1,181 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.jmeter.samplers;
+
+import org.apache.jmeter.util.JMeterUtils;
+import org.apache.jorphan.logging.LoggingManager;
+import org.apache.log.Logger;
+
+import java.io.Serializable;
+import java.rmi.RemoteException;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * Implements batch reporting for remote testing.
+ *
+ * @author Lars Krog-Jensen
+ * Created: 2005-okt-04
+ */
+public class StatisticalSampleSender implements SampleSender, Serializable {
+ transient private static Logger log = LoggingManager.getLoggerForClass();
+
+ private static final int DEFAULT_NUM_SAMPLE_THRESHOLD = 100;
+
+ private static final long DEFAULT_TIME_THRESHOLD = 60000L;
+
+ private RemoteSampleListener listener;
+
+ private List sampleStore = new ArrayList();
+
+ private Map sampleTable = new HashMap();
+
+ private int numSamplesThreshold;
+
+ private int sampleCount;
+
+ private long timeThreshold;
+
+ private long batchSendTime = -1;
+
+ /**
+ * Constructor
+ *
+ * @param listener that the List of sample events will be sent to.
+ */
+ StatisticalSampleSender(RemoteSampleListener listener) {
+ this.listener = listener;
+ init();
+ log.info("Using batching for this run." + " Thresholds: num="
+ + numSamplesThreshold + ", time=" + timeThreshold);
+ }
+
+ /**
+ * Checks for the Jmeter properties num_sample_threshold and time_threshold,
+ * and assigns defaults if not found.
+ */
+ private void init() {
+ this.numSamplesThreshold = JMeterUtils.getPropDefault(
+ "num_sample_threshold", DEFAULT_NUM_SAMPLE_THRESHOLD);
+ this.timeThreshold = JMeterUtils.getPropDefault("time_threshold",
+ DEFAULT_TIME_THRESHOLD);
+ }
+
+ /**
+ * Checks if any sample events are still present in the sampleStore and
+ * sends them to the listener. Informs the listener of the testended.
+ */
+ public void testEnded() {
+ try {
+ if (sampleStore.size() != 0) {
+ sendBatch();
+ }
+ listener.testEnded();
+ } catch (RemoteException err) {
+ log.warn("testEnded()", err);
+ }
+ }
+
+ /**
+ * Checks if any sample events are still present in the sampleStore and
+ * sends them to the listener. Informs the listener of the testended.
+ *
+ * @param host the hostname that the test has ended on.
+ */
+ public void testEnded(String host) {
+ try {
+ if (sampleStore.size() != 0) {
+ sendBatch();
+ }
+ listener.testEnded(host);
+ } catch (RemoteException err) {
+ log.warn("testEnded(hostname)", err);
+ }
+ }
+
+ /**
+ * Stores sample events untill either a time or sample threshold is
+ * breached. Both thresholds are reset if one fires. If only one threshold
+ * is set it becomes the only value checked against. When a threhold is
+ * breached the list of sample events is sent to a listener where the event
+ * are fired locally.
+ *
+ * @param e a Sample Event
+ */
+ public void SampleOccurred(SampleEvent e) {
+ synchronized (sampleStore) {
+ // Locate the statistical sample colector
+ String key = StatisticalSampleResult.getKey(e);
+ StatisticalSampleResult statResult = (StatisticalSampleResult) sampleTable
+ .get(key);
+ if (statResult == null) {
+ statResult = new StatisticalSampleResult(e.getResult());
+ // store the new statistical result collector
+ sampleTable.put(key, statResult);
+ // add a new wrapper samplevent
+ sampleStore
+ .add(new SampleEvent(statResult, e.getThreadGroup()));
+ }
+ statResult.add(e.getResult());
+ sampleCount++;
+ if (numSamplesThreshold != -1) {
+ if (sampleCount >= numSamplesThreshold) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Firing sample");
+ }
+ sendBatch();
+ } catch (RemoteException err) {
+ log.warn("sampleOccurred", err);
+ }
+ }
+ }
+
+ if (timeThreshold != -1) {
+ long now = System.currentTimeMillis();
+ // Checking for and creating initial timestamp to cheak against
+ if (batchSendTime == -1) {
+ this.batchSendTime = now + timeThreshold;
+ }
+
+ if (batchSendTime < now) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Firing time");
+ }
+ sendBatch();
+ this.batchSendTime = now + timeThreshold;
+ } catch (RemoteException err) {
+ log.warn("sampleOccurred", err);
+ }
+ }
+ }
+ }
+ }
+
+ private void sendBatch() throws RemoteException {
+ if (sampleStore.size() > 0) {
+ listener.processBatch(sampleStore);
+ sampleStore.clear();
+ sampleTable.clear();
+ sampleCount = 0;
+ }
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org