*
* ECOMP is a trademark and service mark of AT&T Intellectual Property.
*/
-package org.onap.aai.sparky.synchronizer;
+package org.onap.aai.sparky.sync;
import java.util.concurrent.atomic.AtomicInteger;
import org.onap.aai.sparky.analytics.AveragingRingBuffer;
-import org.onap.aai.sparky.synchronizer.config.TaskProcessorConfig;
+import org.onap.aai.sparky.sync.config.NetworkStatisticsConfig;
-/**
- * TODO: Fill in description.
- *
- * @author davea.
- */
-public class TransactionRateController {
+public class TransactionRateMonitor {
+ private AtomicInteger numTransactions;
private AveragingRingBuffer responseTimeTracker;
- private double msPerTransaction;
- private int numThreads;
- private TaskProcessorConfig config;
private long startTimeInMs;
- private AtomicInteger numTransactions;
/**
* Instantiates a new transaction rate controller.
*
* @param config the config
*/
- public TransactionRateController(TaskProcessorConfig config) {
+ public TransactionRateMonitor(int numWorkerThreads, NetworkStatisticsConfig config) {
- this.config = config;
this.responseTimeTracker = new AveragingRingBuffer(
- config.getNumSamplesPerThreadForRunningAverage() * config.getMaxConcurrentWorkers());
- this.msPerTransaction = 1000 / config.getTargetTps();
- this.numThreads = config.getMaxConcurrentWorkers();
+ config.getNumSamplesPerThreadForRunningAverage() * numWorkerThreads);
this.startTimeInMs = System.currentTimeMillis();
this.numTransactions = new AtomicInteger(0);
}
responseTimeTracker.addSample(responseTimeInMs);
}
- public long getFixedDelayInMs() {
-
- /*
- * The math here is pretty simple:
- *
- * 1. Target TPS is 10. Then the msPerTxn = 1000/10 = 100ms
- *
- * 2. If the calculated avgResponseTime = 40 ms, then the proposed delay is 60ms per thread.
- *
- * 3. If the calculated avgResponseTime = 200ms, then the proposed delay is -100 ms, which is
- * not possible, we can't speed it up, so we don't propose any further delay.
- */
-
- double proposedDelay = 0;
-
- if (config.isTransactionRateControllerEnabled()) {
- proposedDelay = ((msPerTransaction - responseTimeTracker.getAvg()) * this.numThreads);
-
- if (proposedDelay > 0) {
- return (long) (proposedDelay);
- }
- }
-
- return (long) proposedDelay;
- }
-
public long getAvg() {
return responseTimeTracker.getAvg();
}