Package org.jpos.util

Class ThroughputControl


  • public class ThroughputControl
    extends java.lang.Object
    ThroughputControl limits the throughput of a process to a maximum number of transactions in a given period of time. As an example, the following code will cap the transaction count at 15 every second (a.k.a. 15 TPS).
    
      ThroughputControl throughput = new ThroughputControl(15, 1000);
    
      while (isConditionTrue()) {
          throughput.control();
          // Do stuff.
      }
    
     
    • Constructor Summary

      Constructors 
      Constructor Description
      ThroughputControl​(int[] maxTransactions, int[] periodInMillis)  
      ThroughputControl​(int maxTransactions, int periodInMillis)  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long control()
      This method should be called on every transaction.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • ThroughputControl

        public ThroughputControl​(int maxTransactions,
                                 int periodInMillis)
        Parameters:
        maxTransactions - Transaction count threshold.
        periodInMillis - Time window, expressed in milliseconds.
      • ThroughputControl

        public ThroughputControl​(int[] maxTransactions,
                                 int[] periodInMillis)
        Parameters:
        maxTransactions - An array with transaction count thresholds.
        periodInMillis - An array of time windows, expressed in milliseconds.
    • Method Detail

      • control

        public long control()
        This method should be called on every transaction. It will pause the thread for a while when the threshold is reached in order to control the process throughput.
        Returns:
        Returns sleep time in milliseconds when threshold is reached. Otherwise, zero.