X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-distributed-datastore%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fcluster%2Fdatastore%2Futils%2FTransactionRateLimiter.java;h=32faf3a00b02d24cf8fe4c446666cae867fceee4;hb=b5cb353e3553a39f576c284119af75ffa5ea66a9;hp=d7cbce74a93fcb77edf8a124da8dd6023e50430c;hpb=3b0499cd187bcdeda057465350d381c8bc28847c;p=controller.git diff --git a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/TransactionRateLimiter.java b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/TransactionRateLimiter.java index d7cbce74a9..32faf3a00b 100644 --- a/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/TransactionRateLimiter.java +++ b/opendaylight/md-sal/sal-distributed-datastore/src/main/java/org/opendaylight/controller/cluster/datastore/utils/TransactionRateLimiter.java @@ -23,27 +23,28 @@ public class TransactionRateLimiter { private final ActorContext actorContext; private final long commitTimeoutInSeconds; - private final String dataStoreType; + private final String dataStoreName; private final RateLimiter txRateLimiter; private final AtomicLong acquireCount = new AtomicLong(); private volatile long pollOnCount = 1; - public TransactionRateLimiter(ActorContext actorContext){ + public TransactionRateLimiter(ActorContext actorContext) { this.actorContext = actorContext; this.commitTimeoutInSeconds = actorContext.getDatastoreContext().getShardTransactionCommitTimeoutInSeconds(); - this.dataStoreType = actorContext.getDataStoreType(); - this.txRateLimiter = RateLimiter.create(actorContext.getDatastoreContext().getTransactionCreationInitialRateLimit()); + this.dataStoreName = actorContext.getDataStoreName(); + this.txRateLimiter = RateLimiter.create(actorContext.getDatastoreContext() + .getTransactionCreationInitialRateLimit()); } - public void acquire(){ + public void acquire() { adjustRateLimit(); txRateLimiter.acquire(); } private void adjustRateLimit() { final long count = acquireCount.incrementAndGet(); - if(count >= pollOnCount) { + if (count >= pollOnCount) { final Timer commitTimer = actorContext.getOperationTimer(ActorContext.COMMIT); double newRateLimit = calculateNewRateLimit(commitTimer, commitTimeoutInSeconds); @@ -53,28 +54,28 @@ public class TransactionRateLimiter { if (newRateLimit >= 1.0) { txRateLimiter.setRate(newRateLimit); - pollOnCount = count + ((long) newRateLimit/2); + pollOnCount = count + (long) newRateLimit / 2; } } } - public double getTxCreationLimit(){ + public double getTxCreationLimit() { return txRateLimiter.getRate(); } - private double getRateLimitFromOtherDataStores(){ + private double getRateLimitFromOtherDataStores() { // Since we have no rate data for unused Tx's data store, adjust to the rate from another // data store that does have rate data. - for(String datastoreType: DatastoreContext.getGlobalDatastoreTypes()) { - if(datastoreType.equals(this.dataStoreType)) { + for (String name: DatastoreContext.getGlobalDatastoreNames()) { + if (name.equals(this.dataStoreName)) { continue; } - double newRateLimit = calculateNewRateLimit(actorContext.getOperationTimer(datastoreType, ActorContext.COMMIT), + double newRateLimit = calculateNewRateLimit(actorContext.getOperationTimer(name, ActorContext.COMMIT), this.commitTimeoutInSeconds); - if(newRateLimit > 0.0) { + if (newRateLimit > 0.0) { LOG.debug("On unused Tx - data Store {} commit rateLimit adjusted to {}", - this.dataStoreType, newRateLimit); + this.dataStoreName, newRateLimit); return newRateLimit; } @@ -83,8 +84,8 @@ public class TransactionRateLimiter { return -1.0D; } - private double calculateNewRateLimit(Timer commitTimer, long commitTimeoutInSeconds) { - if(commitTimer == null) { + private static double calculateNewRateLimit(Timer commitTimer, long commitTimeoutInSeconds) { + if (commitTimer == null) { // This can happen in unit tests. return 0; } @@ -96,13 +97,13 @@ public class TransactionRateLimiter { // Find the time that it takes for transactions to get executed in every 10th percentile // Compute the rate limit for that percentile and sum it up - for(int i=1;i<=10;i++){ + for (int i = 1; i <= 10; i++) { // Get the amount of time transactions take in the i*10th percentile double percentileTimeInNanos = timerSnapshot.getValue(i * 0.1D); - if(percentileTimeInNanos > 0) { + if (percentileTimeInNanos > 0) { // Figure out the rate limit for the i*10th percentile in nanos - double percentileRateLimit = (commitTimeoutInNanos / percentileTimeInNanos); + double percentileRateLimit = commitTimeoutInNanos / percentileTimeInNanos; // Add the percentileRateLimit to the total rate limit newRateLimit += percentileRateLimit; @@ -110,7 +111,7 @@ public class TransactionRateLimiter { } // Compute the rate limit per second - return newRateLimit/(commitTimeoutInSeconds*10); + return newRateLimit / (commitTimeoutInSeconds * 10); } @VisibleForTesting @@ -119,13 +120,12 @@ public class TransactionRateLimiter { } @VisibleForTesting - void setPollOnCount(long value){ + void setPollOnCount(long value) { pollOnCount = value; } @VisibleForTesting - void setAcquireCount(long value){ + void setAcquireCount(long value) { acquireCount.set(value); } - }