Author: pmouawad Date: Tue Sep 20 12:28:37 2016 New Revision: 1761563 URL: http://svn.apache.org/viewvc?rev=1761563&view=rev Log: Bug 60018 - Timer : Add a factor to apply on pauses Bugzilla Id: 60018
Added: jmeter/trunk/src/core/org/apache/jmeter/timers/ModifiableTimer.java (with props) Modified: jmeter/trunk/bin/jmeter.properties jmeter/trunk/src/components/org/apache/jmeter/timers/RandomTimer.java jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java jmeter/trunk/xdocs/changes.xml jmeter/trunk/xdocs/usermanual/component_reference.xml Modified: jmeter/trunk/bin/jmeter.properties URL: http://svn.apache.org/viewvc/jmeter/trunk/bin/jmeter.properties?rev=1761563&r1=1761562&r2=1761563&view=diff ============================================================================== --- jmeter/trunk/bin/jmeter.properties (original) +++ jmeter/trunk/bin/jmeter.properties Tue Sep 20 12:28:37 2016 @@ -1253,3 +1253,12 @@ system.properties=system.properties # Force throuput controllers that work in percentage mode to be a 100% # Disabled by default #testplan_validation.tpc_force_100_pct=false + + +# +# Apply a factor on computed pauses by the following Timers: +# - Gaussian Random Timer +# - Uniform Random Timer +# - Poisson Random Timer +# +#timer.factor=1.0f \ No newline at end of file Modified: jmeter/trunk/src/components/org/apache/jmeter/timers/RandomTimer.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/components/org/apache/jmeter/timers/RandomTimer.java?rev=1761563&r1=1761562&r2=1761563&view=diff ============================================================================== --- jmeter/trunk/src/components/org/apache/jmeter/timers/RandomTimer.java (original) +++ jmeter/trunk/src/components/org/apache/jmeter/timers/RandomTimer.java Tue Sep 20 12:28:37 2016 @@ -31,7 +31,7 @@ import org.apache.jmeter.testelement.pro * method, is abstract and must be extended to provide full functionality. * */ -public abstract class RandomTimer extends ConstantTimer implements Timer, Serializable { +public abstract class RandomTimer extends ConstantTimer implements ModifiableTimer, Serializable { private static final long serialVersionUID = 241L; public static final String RANGE = "RandomTimer.range"; @@ -70,4 +70,12 @@ public abstract class RandomTimer extend protected Random getRandom() { return ThreadLocalRandom.current(); } + + /** + * @see org.apache.jmeter.timers.ModifiableTimer#isModifiable() + */ + @Override + public boolean isModifiable() { + return true; + } } Modified: jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java?rev=1761563&r1=1761562&r2=1761563&view=diff ============================================================================== --- jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java (original) +++ jmeter/trunk/src/core/org/apache/jmeter/threads/JMeterThread.java Tue Sep 20 12:28:37 2016 @@ -46,6 +46,7 @@ import org.apache.jmeter.testelement.Abs import org.apache.jmeter.testelement.TestElement; import org.apache.jmeter.testelement.TestIterationListener; import org.apache.jmeter.testelement.ThreadListener; +import org.apache.jmeter.timers.ModifiableTimer; import org.apache.jmeter.timers.Timer; import org.apache.jmeter.util.JMeterUtils; import org.apache.jorphan.collections.HashTree; @@ -75,6 +76,13 @@ public class JMeterThread implements Run private static final int RAMPUP_GRANULARITY = JMeterUtils.getPropDefault("jmeterthread.rampup.granularity", 1000); // $NON-NLS-1$ + private static final float TIMER_FACTOR = JMeterUtils.getPropDefault("timer.factor", 1.0f); + + /** + * 1 as float + */ + private static final float ONE_AS_FLOAT = 1.0f; + private final Controller threadGroupLoopController; private final HashTree testTree; @@ -795,7 +803,20 @@ public class JMeterThread implements Run long totalDelay = 0; for (Timer timer : timers) { TestBeanHelper.prepare((TestElement) timer); - totalDelay += timer.delay(); + long delay = timer.delay(); + if(TIMER_FACTOR != ONE_AS_FLOAT && + // TODO Improve this with Optional methods when migration to Java8 is completed + ((timer instanceof ModifiableTimer) + && ((ModifiableTimer)timer).isModifiable())) { + if(log.isDebugEnabled()) { + log.debug("Applying TIMER_FACTOR:" + +TIMER_FACTOR + " on timer:" + +((TestElement)timer).getName() + + " for thread:"+getThreadName()); + } + delay = Math.round(delay * TIMER_FACTOR); + } + totalDelay += delay; } if (totalDelay > 0) { try { Added: jmeter/trunk/src/core/org/apache/jmeter/timers/ModifiableTimer.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/timers/ModifiableTimer.java?rev=1761563&view=auto ============================================================================== --- jmeter/trunk/src/core/org/apache/jmeter/timers/ModifiableTimer.java (added) +++ jmeter/trunk/src/core/org/apache/jmeter/timers/ModifiableTimer.java Tue Sep 20 12:28:37 2016 @@ -0,0 +1,32 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You 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.timers; + + +/** + * This interface identifies Modifiable timers to which a factor can be applied + * @since 3.1 + */ +public interface ModifiableTimer extends Timer { + + /** + * @return true if factor can be applied to it + */ + boolean isModifiable(); +} Propchange: jmeter/trunk/src/core/org/apache/jmeter/timers/ModifiableTimer.java ------------------------------------------------------------------------------ svn:mime-type = text/plain Modified: jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java URL: http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java?rev=1761563&r1=1761562&r2=1761563&view=diff ============================================================================== --- jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java (original) +++ jmeter/trunk/src/core/org/apache/jmeter/util/JMeterUtils.java Tue Sep 20 12:28:37 2016 @@ -857,6 +857,26 @@ public class JMeterUtils implements Unit } return ans; } + + /** + * Get a float value with default if not present. + * + * @param propName + * the name of the property. + * @param defaultVal + * the default value. + * @return The PropDefault value + */ + public static float getPropDefault(String propName, float defaultVal) { + float ans; + try { + ans = Float.parseFloat(appProperties.getProperty(propName, Float.toString(defaultVal)).trim()); + } catch (Exception e) { + log.warn("Exception '"+ e.getMessage()+ "' occurred when fetching float property:'"+propName+"', defaulting to:"+defaultVal); + ans = defaultVal; + } + return ans; + } /** * Get a String value with default if not present. Modified: jmeter/trunk/xdocs/changes.xml URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/changes.xml?rev=1761563&r1=1761562&r2=1761563&view=diff ============================================================================== --- jmeter/trunk/xdocs/changes.xml [utf-8] (original) +++ jmeter/trunk/xdocs/changes.xml [utf-8] Tue Sep 20 12:28:37 2016 @@ -71,6 +71,7 @@ Summary <li>Since 3.1 version, Summariser ignores SampleResults generated by TransactionController when computing the live statistics, see <bugzilla>60109</bugzilla></li> <li>Since 3.1 version, when using Stripped modes (by default StrippedBatch is used) , response will be stripped also for failing SampleResults, you can revert this to previous behaviour by setting <code>sample_sender_strip_also_on_error=false</code> in user.properties, see <bugzilla>60137</bugzilla></li> <li>Since 3.1 version, <code>jmeter.save.saveservice.connect_time</code> property value is true, meaning CSV file for results will contain an additional column containing connection time, see <bugzilla>60106</bugzilla></li> + <li>Since 3.1 version, Random Timer subclasses (Gaussian Random Timer, Uniform Random Timer and Poisson Random Timer) implement interface <code><a href="./api/org/apache/jmeter/timers/ModifiableTimer.html">org.apache.jmeter.timers.ModifiableTimer</a></code></li> </ul> <h3>Deprecated and removed elements</h3> @@ -121,6 +122,7 @@ Summary <li><bug>59974</bug>Response Assertion : Add button "Add from clipboard". Contributed by Ubik Load Pack (support at ubikloadpack.com)</li> <li><bug>60050</bug>CSV Data Set : Make it clear in the logs when a thread will exit due to this configuration</li> <li><bug>59962</bug>Cache Manager does not update expires date when response code is 304.</li> + <li><bug>60018</bug>Timer : Add a factor to apply on pauses. Partly based on a patch by Ubik Load Pack (support at ubikloadpack.com)</li> </ul> <h3>Functions</h3> Modified: jmeter/trunk/xdocs/usermanual/component_reference.xml URL: http://svn.apache.org/viewvc/jmeter/trunk/xdocs/usermanual/component_reference.xml?rev=1761563&r1=1761562&r2=1761563&view=diff ============================================================================== --- jmeter/trunk/xdocs/usermanual/component_reference.xml (original) +++ jmeter/trunk/xdocs/usermanual/component_reference.xml Tue Sep 20 12:28:37 2016 @@ -4931,7 +4931,16 @@ please ensure that you select "<code>Sto <section name="§-num;.6 Timers" anchor="timers"> <description> - <br></br> + <note> + Since version 3.1, a new feature (in Beta mode as of JMeter 3.1 and subject to changes) has been implemented which provides the following feature.<br/> + You can apply a multiplication factor on the sleep delays computed by Random timer by setting property <code>timer.factor=float number</code> where float number is a decimal positive number.<br/> + JMeter will multiply this factor by the computed sleep delay. This feature can be used by: + <ul> + <li><complink name="Gaussian Random Timer"/></li> + <li><complink name="Poisson Random Timer"/></li> + <li><complink name="Uniform Random Timer"/></li> + </ul> + </note> <note> Note that timers are processed <b>before</b> each sampler in the scope in which they are found; if there are several timers in the same scope, <b>all</b> the timers will be processed <b>before