mstover1    2004/12/13 13:43:00

  Modified:    src/core/org/apache/jmeter/threads JMeterContextService.java
                        JMeterThread.java
               src/components/org/apache/jmeter/timers
                        ConstantThroughputTimer.java
               bin      jmeter
  Log:
  The Constant Throughput Timer should be smart enough to gear it's delay for 
the number of threads in the test, allowing the user to set their desired 
throughput rate and forget it instead of having to manually calculate and 
adjust based on a changing number of simulated users.
  
  Revision  Changes    Path
  1.9       +20 -2     
jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterContextService.java
  
  Index: JMeterContextService.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterContextService.java,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- JMeterContextService.java 28 May 2004 21:09:12 -0000      1.8
  +++ JMeterContextService.java 13 Dec 2004 21:43:00 -0000      1.9
  @@ -34,6 +34,7 @@
       };
       
       private static long testStart = 0;
  +    private static int numberOfThreads = 0;
   
       /**
        * Private constructor to prevent instantiation.
  @@ -51,6 +52,7 @@
       {
          if(testStart == 0)
          {
  +          numberOfThreads = 0;
               testStart = System.currentTimeMillis();
               threadContext = new ThreadLocal(){
                  public Object initialValue()
  @@ -61,9 +63,25 @@
          }
       }
       
  +    static public void incrNumberOfThreads()
  +    {
  +       numberOfThreads++;
  +    }
  +    
  +    static public void decrNumberOfThreads()
  +    {
  +       numberOfThreads--;
  +    }
  +    
  +    static public int getNumberOfThreads()
  +    {
  +       return numberOfThreads;
  +    }
  +    
       static public void endTest()
       {
          testStart = 0;
  +       numberOfThreads = 0;
       }
       
       static public long getTestStartTime()
  
  
  
  1.56      +4 -2      
jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterThread.java
  
  Index: JMeterThread.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/core/org/apache/jmeter/threads/JMeterThread.java,v
  retrieving revision 1.55
  retrieving revision 1.56
  diff -u -r1.55 -r1.56
  --- JMeterThread.java 10 Dec 2004 21:32:55 -0000      1.55
  +++ JMeterThread.java 13 Dec 2004 21:43:00 -0000      1.56
  @@ -330,6 +330,7 @@
        private void threadStarted() {
                Traverser startup = new Traverser(true);
           testTree.traverse(startup);
  +        JMeterContextService.incrNumberOfThreads();
        }
   
       /**
  @@ -338,6 +339,7 @@
        private void threadFinished() {
                Traverser shut = new Traverser(false);
           testTree.traverse(shut);
  +        JMeterContextService.decrNumberOfThreads();
        }
   
       private class Traverser implements HashTreeTraverser
  
  
  
  1.19      +127 -117  
jakarta-jmeter/src/components/org/apache/jmeter/timers/ConstantThroughputTimer.java
  
  Index: ConstantThroughputTimer.java
  ===================================================================
  RCS file: 
/home/cvs/jakarta-jmeter/src/components/org/apache/jmeter/timers/ConstantThroughputTimer.java,v
  retrieving revision 1.18
  retrieving revision 1.19
  diff -u -r1.18 -r1.19
  --- ConstantThroughputTimer.java      10 Dec 2004 21:32:54 -0000      1.18
  +++ ConstantThroughputTimer.java      13 Dec 2004 21:43:00 -0000      1.19
  @@ -13,7 +13,7 @@
    * See the License for the specific language governing permissions and
    * limitations under the License.
    * 
  -*/
  + */
   
   package org.apache.jmeter.timers;
   
  @@ -21,6 +21,7 @@
   import org.apache.jmeter.testbeans.TestBean;
   import org.apache.jmeter.testelement.AbstractTestElement;
   import org.apache.jmeter.testelement.TestListener;
  +import org.apache.jmeter.threads.JMeterContextService;
   import org.apache.jmeter.util.JMeterUtils;
   import org.apache.jorphan.logging.LoggingManager;
   import org.apache.log.Logger;
  @@ -29,123 +30,132 @@
    * 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.
  - *
  + *  
    */
  -public class ConstantThroughputTimer
  -        extends AbstractTestElement
  -        implements Timer, TestListener,TestBean
  +public class ConstantThroughputTimer extends AbstractTestElement implements 
Timer, TestListener,
  +      TestBean
   {
  -     private static final Logger log = LoggingManager.getLoggerForClass();
   
  -    /**
  -     * 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;
  -
  -     /**
  -      * Desired throughput, in samples per minute.
  -      */
  -     private double throughput;
  -
  -    /**
  -     * Constructor for a non-configured ConstantThroughputTimer.
  -     */
  -    public ConstantThroughputTimer()
  -    {
  -    }
  -
  -    /**
  -     * Sets the desired throughput.
  -     *
  -     * @param throughput Desired sampling rate, in samples per minute.
  -     */
  -    public void setThroughput(double throughput)
  -    {
  -       log.info("setting throughput to: " + throughput);
  -     this.throughput= throughput;
  -    }
  -
  -    /**
  -     * Gets the configured desired throughput.
  -     *
  -     * @return the rate at which samples should occur, in samples per minute.
  -     */
  -    public double getThroughput()
  -    {
  -       log.info("Getting throughput, which is: " + throughput);
  -     return throughput;
  -    }
  -    
  -    /**
  -     * Retrieve the delay to use during test execution.
  -     * 
  -     * @see org.apache.jmeter.timers.Timer#delay()
  -     */
  -    public synchronized long delay()
  -    {
  -       log.info("in Delay, using throughput, which is " + getThroughput());
  -        long currentTime = System.currentTimeMillis();
  -        long currentTarget = targetTime == 0 ? currentTime : targetTime;
  -        targetTime = currentTarget + (long)( 60000.0 / getThroughput() );
  -        if (currentTime > currentTarget)
  -        {
  -            // We're behind schedule -- try to catch up:
  -            return 0;
  -        }
  -        return currentTarget - currentTime;
  -    }
  -
  -    /**
  -     * Provide a description of this timer class.
  -     * 
  -     * TODO: Is this ever used? I can't remember where. Remove if it isn't --
  -     * TODO: or obtain text from bean's displayName or shortDescription.
  -     *
  -     * @return the description of this timer class.
  -     */
  -    public String toString()
  -    {
  -        return JMeterUtils.getResString("constant_throughput_timer_memo");
  -    }
  -
  -    /**
  -     * Get the timer ready to compute delays for a new test.
  -     * 
  -     * @see org.apache.jmeter.testelement.TestListener#testStarted()
  -     */
  -    public synchronized void testStarted()//synch to protect targetTime
  -    {
  -     log.debug("Test started - reset throughput calculation.");
  -     targetTime= 0;
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see org.apache.jmeter.testelement.TestListener#testEnded()
  -     */
  -    public void testEnded()
  -    {
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see 
org.apache.jmeter.testelement.TestListener#testStarted(java.lang.String)
  -     */
  -    public void testStarted(String host)
  -    {
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see 
org.apache.jmeter.testelement.TestListener#testEnded(java.lang.String)
  -     */
  -    public void testEnded(String host)
  -    {
  -    }
  -
  -    /* (non-Javadoc)
  -     * @see 
org.apache.jmeter.testelement.TestListener#testIterationStart(org.apache.jmeter.engine.event.LoopIterationEvent)
  -     */
  -    public void testIterationStart(LoopIterationEvent event)
  -    {
  -    }
  +   private static final Logger log = LoggingManager.getLoggerForClass();
  +
  +   /**
  +    * 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 previousTime = 0;
  +
  +   /**
  +    * Desired throughput, in samples per minute.
  +    */
  +   private double throughput;
  +
  +   /**
  +    * Constructor for a non-configured ConstantThroughputTimer.
  +    */
  +   public ConstantThroughputTimer()
  +   {
  +   }
  +
  +   /**
  +    * Sets the desired throughput.
  +    * 
  +    * @param throughput
  +    *           Desired sampling rate, in samples per minute.
  +    */
  +   public void setThroughput(double throughput)
  +   {
  +      this.throughput = throughput;
  +   }
  +
  +   /**
  +    * Gets the configured desired throughput.
  +    * 
  +    * @return the rate at which samples should occur, in samples per minute.
  +    */
  +   public double getThroughput()
  +   {
  +      return 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 = 
  +            (previousTime == 0) ? currentTime
  +            + ((JMeterContextService.getContext().getThreadNum() + 1) * 
(long) (60000.0 / getThroughput()))
  +            : previousTime
  +                  + (JMeterContextService.getNumberOfThreads() * (long) 
(60000.0 / getThroughput()));
  +      previousTime = currentTarget;
  +      if (currentTime > currentTarget)
  +      {
  +         // We're behind schedule -- try to catch up:
  +         return 0;
  +      }
  +      return currentTarget - currentTime;
  +   }
  +
  +   /**
  +    * Provide a description of this timer class.
  +    * 
  +    * TODO: Is this ever used? I can't remember where. Remove if it isn't --
  +    * TODO: or obtain text from bean's displayName or shortDescription.
  +    * 
  +    * @return the description of this timer class.
  +    */
  +   public String toString()
  +   {
  +      return JMeterUtils.getResString("constant_throughput_timer_memo");
  +   }
  +
  +   /**
  +    * Get the timer ready to compute delays for a new test.
  +    * 
  +    * @see org.apache.jmeter.testelement.TestListener#testStarted()
  +    */
  +   public synchronized void testStarted()//synch to protect targetTime
  +   {
  +      log.debug("Test started - reset throughput calculation.");
  +      previousTime = 0;
  +   }
  +
  +   /*
  +    * (non-Javadoc)
  +    * 
  +    * @see org.apache.jmeter.testelement.TestListener#testEnded()
  +    */
  +   public void testEnded()
  +   {
  +   }
  +
  +   /*
  +    * (non-Javadoc)
  +    * 
  +    * @see 
org.apache.jmeter.testelement.TestListener#testStarted(java.lang.String)
  +    */
  +   public void testStarted(String host)
  +   {
  +   }
  +
  +   /*
  +    * (non-Javadoc)
  +    * 
  +    * @see 
org.apache.jmeter.testelement.TestListener#testEnded(java.lang.String)
  +    */
  +   public void testEnded(String host)
  +   {
  +   }
  +
  +   /*
  +    * (non-Javadoc)
  +    * 
  +    * @see 
org.apache.jmeter.testelement.TestListener#testIterationStart(org.apache.jmeter.engine.event.LoopIterationEvent)
  +    */
  +   public void testIterationStart(LoopIterationEvent event)
  +   {
  +   }
   }
  
  
  
  1.26      +2 -2      jakarta-jmeter/bin/jmeter
  
  Index: jmeter
  ===================================================================
  RCS file: /home/cvs/jakarta-jmeter/bin/jmeter,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- jmeter    1 Oct 2004 16:25:08 -0000       1.25
  +++ jmeter    13 Dec 2004 21:43:00 -0000      1.26
  @@ -77,4 +77,4 @@
   
   ARGS="$SERVER $HEAP $NEW $SURVIVOR $TENURING $EVACUATION $RMIGC $PERM $DEBUG"
   
  -/usr/java/j2sdk1.4.2_05/jre/bin/java $ARGS -jar `dirname 
$0`/ApacheJMeter.jar "$@"
  +java $ARGS -jar `dirname $0`/ApacheJMeter.jar "$@"
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to