apache / jmeter

Apache JMeter open-source load testing tool for analyzing and measuring the performance of a variety of services
https://jmeter.apache.org/
Apache License 2.0
7.97k stars 2.02k forks source link

ConstantThroughputTimer does not work in non-GUI (batch) mode #1045

Closed asfimport closed 21 years ago

asfimport commented 21 years ago

jkb (Bug 17688): ConstantThroughputTimer does not work in non-GUI (batch) mode. This is because the "delay" field does not get set up - it remains as zero.

==

The similar ConstantTimer works OK in non-GUI mode. It uses iterationStarted() to set the delay from the relevant properties string, which seems to be set up from the JMX record in non-GUI mode.

However, iterationStarted() seems to be called every time through the loop, so maybe setJMeterVariables() would be a better place to calculate the delay and save it ... hope to find time to test this soon; will post details later.

Severity: normal OS: other

asfimport commented 21 years ago

jkb (migrated from Bugzilla): Created attachment ConstantThroughputTimer.java: Updated copy of ConstantThroughputTimer.java

ConstantThroughputTimer.java ````java /* * ==================================================================== * The Apache Software License, Version 1.1 * * Copyright (c) 2002 The Apache Software Foundation. All rights * reserved. * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: * * 1. Redistributions of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * * 2. Redistributions in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in * the documentation and/or other materials provided with the * distribution. * * 3. The end-user documentation included with the redistribution, * if any, must include the following acknowledgment: * "This product includes software developed by the * Apache Software Foundation (http://www.apache.org/)." * Alternately, this acknowledgment may appear in the software itself, * if and wherever such third-party acknowledgments normally appear. * * 4. The names "Apache" and "Apache Software Foundation" and * "Apache JMeter" must not be used to endorse or promote products * derived from this software without prior written permission. For * written permission, please contact apache@apache.org. * * 5. Products derived from this software may not be called "Apache", * "Apache JMeter", nor may "Apache" appear in their name, without * prior written permission of the Apache Software Foundation. * * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * ==================================================================== * * This software consists of voluntary contributions made by many * individuals on behalf of the Apache Software Foundation. For more * information on the Apache Software Foundation, please see * . */ package org.apache.jmeter.timers; import java.util.*; import java.io.*; import org.apache.jmeter.util.JMeterUtils; import org.apache.jmeter.testelement.AbstractTestElement; import org.apache.jmeter.testelement.ThreadListener; import org.apache.jmeter.threads.JMeterVariables; /** * This class implements a constant throughput timer. A Constant Throughtput * Timer paces the samplers under it's influence so that the total number of * samples per unit of time approaches a given constant as much as possible. * * @author Jordi Salvat i Alabart * @author Scott Eade * @version $Id: ConstantThroughputTimer.java,v 1.3 2003/01/10 13:59:51 seade Exp $ */ public class ConstantThroughputTimer extends AbstractTestElement implements Timer, Serializable, ThreadListener { public final static String THROUGHPUT= "ConstantThroughputTimer.throughput"; private static List addableList= new LinkedList(); /** * Target time for the start of the next request. The delay provided by * the timer will be calculated so that the next request happens at this * time. */ private long targetTime= 0; /** * Inverse of the configured throughput, in milliseconds. It's the interval * at which sampling should ideally occur to get that throughput. */ private long delay; /** * Constructor for a non-configured ConstantThroughputTimer. */ public ConstantThroughputTimer() { } public void setJMeterVariables(JMeterVariables jmVars) { delay= 60000/getThroughput(); } public void iterationStarted(int iterationCount) // Needed for interface; not used { } /** * Sets the desired throughput. * * @param throughput Desired sampling rate, in samples per minute. */ public void setThroughput(long throughput) { setProperty(THROUGHPUT,new Long(throughput)); delay= 60000/throughput; } /** * Not implemented. */ public void setRange(double range) { } /** * Not implemented. */ public double getRange() { return (double)0; } /** * Not implemented. */ public void setDelay(String delay) { } /** * Not implemented. */ public String getDelay() { return ""; } /** * Gets the configured desired throughput. * * @return the rate at which samples should occur, in samples per minute. */ public long getThroughput() { Object throughput = getProperty(THROUGHPUT); if(throughput instanceof Long) { return ((Long)throughput).longValue(); } else { return Long.parseLong((String)throughput); } } /** * Retrieve the delay to use during test execution. * * @see org.apache.jmeter.timers.Timer#delay() */ public synchronized long delay() { long currentTime = System.currentTimeMillis(); long currentTarget = targetTime == 0 ? currentTime : targetTime; targetTime = currentTarget + delay; if (currentTime > currentTarget) { // We're behind schedule -- try to catch up: return 0; } return currentTarget - currentTime; } /** * Provide a description of this timer class. * * @return the description of this timer class. */ public String toString() { return JMeterUtils.getResString("constant_throughput_timer_memo"); } /** * Creates a copy of this ConstantThroughputTimer, ready to start * calculating delays for new samples. This is in assumption that cloning * always happens just before a test starts running. * * @return a fresh copy of this ConstantThroughputTimer */ public Object clone() { ConstantThroughputTimer result = (ConstantThroughputTimer)super.clone(); result.targetTime = 0; return result; } } ````
asfimport commented 21 years ago

jkb (migrated from Bugzilla): Created attachment ConstantThroughputTimer.patch: Patch version of fix - use instead of previous attachment

ConstantThroughputTimer.patch ````diff Index: ConstantThroughputTimer.java =================================================================== RCS file: /home/cvspublic/jakarta-jmeter/src/components/org/apache/jmeter/timers/ConstantThroughputTimer.java,v retrieving revision 1.5 diff -u -r1.5 ConstantThroughputTimer.java --- ConstantThroughputTimer.java 7 Apr 2003 14:35:19 -0000 1.5 +++ ConstantThroughputTimer.java 7 Apr 2003 17:26:26 -0000 @@ -60,7 +60,9 @@ import java.util.List; import org.apache.jmeter.testelement.AbstractTestElement; +import org.apache.jmeter.testelement.ThreadListener; import org.apache.jmeter.testelement.property.LongProperty; +import org.apache.jmeter.threads.JMeterVariables; import org.apache.jmeter.util.JMeterUtils; /** @@ -74,7 +76,7 @@ */ public class ConstantThroughputTimer extends AbstractTestElement - implements Timer, Serializable + implements Timer, Serializable, ThreadListener { public final static String THROUGHPUT= "ConstantThroughputTimer.throughput"; private static List addableList= new LinkedList(); @@ -98,6 +100,15 @@ public ConstantThroughputTimer() { } + + public void setJMeterVariables(JMeterVariables jmVars) + { + delay= 60000/getThroughput(); + } + + public void iterationStarted(int iterationCount) // Needed for interface; not used + { + } /** * Sets the desired throughput. ````