Author: sebb
Date: Thu Mar 11 11:37:54 2010
New Revision: 921807
URL: http://svn.apache.org/viewvc?rev=921807&view=rev
Log:
Simplify. Ensure only count or timer fire for a given sample.
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/BatchSampleSender.java
jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/StatisticalSampleSender.java
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/BatchSampleSender.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/BatchSampleSender.java?rev=921807&r1=921806&r2=921807&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/BatchSampleSender.java
(original)
+++
jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/BatchSampleSender.java
Thu Mar 11 11:37:54 2010
@@ -40,16 +40,16 @@ public class BatchSampleSender implement
private static final long DEFAULT_TIME_THRESHOLD = 60000L;
- private final RemoteSampleListener listener;
-
- private final List<SampleEvent> sampleStore = new ArrayList<SampleEvent>();
-
- private final int numSamplesThreshold =
+ private static final int NUM_SAMPLES_THRESHOLD =
JMeterUtils.getPropDefault("num_sample_threshold",
DEFAULT_NUM_SAMPLE_THRESHOLD); // $NON-NLS-1$
private static final long TIME_THRESHOLD_MS =
JMeterUtils.getPropDefault("time_threshold", DEFAULT_TIME_THRESHOLD);
// $NON-NLS-1$
+ private final RemoteSampleListener listener;
+
+ private final List<SampleEvent> sampleStore = new ArrayList<SampleEvent>();
+
private long batchSendTime = -1;
/**
@@ -69,7 +69,7 @@ public class BatchSampleSender implement
BatchSampleSender(RemoteSampleListener listener) {
this.listener = listener;
log.info("Using batching for this run."
- + " Thresholds: num=" + numSamplesThreshold
+ + " Thresholds: num=" + NUM_SAMPLES_THRESHOLD
+ ", time=" + TIME_THRESHOLD_MS);
}
@@ -121,41 +121,39 @@ public class BatchSampleSender implement
public void sampleOccurred(SampleEvent e) {
synchronized (sampleStore) {
sampleStore.add(e);
+ final int sampleCount = sampleStore.size();
- if (numSamplesThreshold != -1) {
- if (sampleStore.size() >= numSamplesThreshold) {
- try {
- log.debug("Firing sample");
- listener.processBatch(sampleStore);
- sampleStore.clear();
- } catch (RemoteException err) {
- log.error("sampleOccurred", err);
- }
+ boolean sendNow = false;
+ if (NUM_SAMPLES_THRESHOLD != -1) {
+ if (sampleCount >= NUM_SAMPLES_THRESHOLD) {
+ sendNow = true;
}
}
+ long now = 0;
if (TIME_THRESHOLD_MS != -1) {
- SampleResult sr = e.getResult();
- long timestamp = sr.getTimeStamp();
-
- // Checking for and creating initial timestamp to cheak against
+ now = System.currentTimeMillis();
+ // Checking for and creating initial timestamp to check against
if (batchSendTime == -1) {
- this.batchSendTime = timestamp + TIME_THRESHOLD_MS;
+ this.batchSendTime = now + TIME_THRESHOLD_MS;
+ }
+ if (batchSendTime < now && sampleCount > 0) {
+ sendNow = true;
}
+ }
- if (batchSendTime < timestamp) {
- try {
- log.debug("Firing time");
- if (sampleStore.size() > 0) {
- listener.processBatch(sampleStore);
- sampleStore.clear();
- }
- this.batchSendTime = timestamp + TIME_THRESHOLD_MS;
- } catch (RemoteException err) {
- log.error("sampleOccurred", err);
+ if (sendNow){
+ try {
+ log.debug("Firing sample");
+ listener.processBatch(sampleStore);
+ sampleStore.clear();
+ if (TIME_THRESHOLD_MS != -1) {
+ this.batchSendTime = now + TIME_THRESHOLD_MS;
}
- }
+ } catch (RemoteException err) {
+ log.error("sampleOccurred", err);
+ }
}
- }
+ } // synchronized(sampleStore)
}
}
Modified:
jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/StatisticalSampleSender.java
URL:
http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/StatisticalSampleSender.java?rev=921807&r1=921806&r2=921807&view=diff
==============================================================================
---
jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/StatisticalSampleSender.java
(original)
+++
jakarta/jmeter/trunk/src/core/org/apache/jmeter/samplers/StatisticalSampleSender.java
Thu Mar 11 11:37:54 2010
@@ -42,19 +42,19 @@ public class StatisticalSampleSender imp
private static final long DEFAULT_TIME_THRESHOLD = 60000L;
+ private static final int NUM_SAMPLES_THRESHOLD =
JMeterUtils.getPropDefault(
+ "num_sample_threshold", DEFAULT_NUM_SAMPLE_THRESHOLD);
+
+ private static final long TIME_THRESHOLD_MS =
JMeterUtils.getPropDefault("time_threshold",
+ DEFAULT_TIME_THRESHOLD);
+
private final RemoteSampleListener listener;
private final List<SampleEvent> sampleStore = new ArrayList<SampleEvent>();
private final Map<String, StatisticalSampleResult> sampleTable = new
HashMap<String, StatisticalSampleResult>();
- private final int numSamplesThreshold = JMeterUtils.getPropDefault(
- "num_sample_threshold", DEFAULT_NUM_SAMPLE_THRESHOLD);
-
- private int sampleCount;
-
- private static final long TIME_THRESHOLD_MS =
JMeterUtils.getPropDefault("time_threshold",
- DEFAULT_TIME_THRESHOLD);
+ private int sampleCount; // maintain separate count of samples for speed
private long batchSendTime = -1;
@@ -76,7 +76,7 @@ public class StatisticalSampleSender imp
StatisticalSampleSender(RemoteSampleListener listener) {
this.listener = listener;
log.info("Using batching for this run." + " Thresholds: num="
- + numSamplesThreshold + ", time=" + TIME_THRESHOLD_MS);
+ + NUM_SAMPLES_THRESHOLD + ", time=" + TIME_THRESHOLD_MS);
}
/**
@@ -135,39 +135,38 @@ public class StatisticalSampleSender imp
}
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);
- }
+ boolean sendNow = false;
+ if (NUM_SAMPLES_THRESHOLD != -1) {
+ if (sampleCount >= NUM_SAMPLES_THRESHOLD) {
+ sendNow = true;
}
}
+ long now = 0;
if (TIME_THRESHOLD_MS != -1) {
- long now = System.currentTimeMillis();
- // Checking for and creating initial timestamp to cheak against
+ now = System.currentTimeMillis();
+ // Checking for and creating initial timestamp to check against
if (batchSendTime == -1) {
this.batchSendTime = now + TIME_THRESHOLD_MS;
}
-
if (batchSendTime < now) {
- try {
- if (log.isDebugEnabled()) {
- log.debug("Firing time");
- }
- sendBatch();
+ sendNow = true;
+ }
+ }
+ if (sendNow) {
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("Firing sample");
+ }
+ sendBatch();
+ if (TIME_THRESHOLD_MS != -1) {
this.batchSendTime = now + TIME_THRESHOLD_MS;
- } catch (RemoteException err) {
- log.warn("sampleOccurred", err);
}
+ } catch (RemoteException err) {
+ log.warn("sampleOccurred", err);
}
}
- }
+ } // synchronized(sampleStore)
}
private void sendBatch() throws RemoteException {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]