Skip to content

Commit 8a9651b

Browse files
committed
Removed per-request rate limiter use percentage.
1 parent 0c0f7a0 commit 8a9651b

File tree

6 files changed

+61
-329
lines changed

6 files changed

+61
-329
lines changed

driver/src/main/java/oracle/nosql/driver/NoSQLHandleConfig.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
import io.netty.handler.ssl.SslContext;
2222
import oracle.nosql.driver.Region.RegionProvider;
2323
import oracle.nosql.driver.iam.SignatureProvider;
24-
import oracle.nosql.driver.ops.Request;
2524

2625
/**
2726
* NoSQLHandleConfig groups parameters used to configure a {@link
@@ -834,9 +833,6 @@ public boolean getRateLimitingEnabled() {
834833
* full table limits. This only applies if rate limiting is enabled using
835834
* {@link #setRateLimitingEnabled}.
836835
* <p>
837-
* Rate limiter use percentage can also be set on a per-request
838-
* basis using {@link Request#setRateLimiterPercentage}.
839-
* <p>
840836
* The default for this value is 100.0 (full table limits).
841837
*
842838
* @param percent the percentage of table limits to use. This value
@@ -1205,7 +1201,7 @@ static private String checkRegionId(String endpoint,
12051201
return region.endpoint();
12061202
}
12071203
} catch (IllegalArgumentException iae) {
1208-
// ignore
1204+
/* ignore */
12091205
}
12101206
return endpoint;
12111207
}

driver/src/main/java/oracle/nosql/driver/http/Client.java

Lines changed: 25 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@
6969
import oracle.nosql.driver.util.ByteOutputStream;
7070
import oracle.nosql.driver.util.RateLimiterMap;
7171
import oracle.nosql.driver.util.SerializationUtil;
72-
import oracle.nosql.driver.util.SimpleRateLimiter;
7372

7473
import io.netty.buffer.ByteBuf;
7574
import io.netty.channel.Channel;
@@ -379,6 +378,11 @@ public Result execute(Request kvRequest) {
379378
long thisTime = System.currentTimeMillis();
380379
int thisIterationTimeoutMs = timeoutMs - (int)(thisTime - startTime);
381380

381+
/*
382+
* Check rate limiters before executing the request.
383+
* Wait for read and/or write limiters to be below their limits
384+
* before continuing. Be aware of the timeout given.
385+
*/
382386
if (readLimiter != null && checkReadUnits == true) {
383387
try {
384388
/*
@@ -524,10 +528,10 @@ public Result execute(Request kvRequest) {
524528
/* consume rate limiter units based on actual usage */
525529
rateDelayedMs += consumeLimiterUnits(readLimiter,
526530
res.getReadUnitsInternal(),
527-
kvRequest, thisIterationTimeoutMs);
531+
thisIterationTimeoutMs);
528532
rateDelayedMs += consumeLimiterUnits(writeLimiter,
529533
res.getWriteUnitsInternal(),
530-
kvRequest, thisIterationTimeoutMs);
534+
thisIterationTimeoutMs);
531535
res.setRateLimitDelayedMs(rateDelayedMs);
532536

533537
/* copy retry stats to Result on successful operation */
@@ -716,21 +720,20 @@ private RateLimiter getQueryRateLimiter(Request request, boolean read) {
716720
return rateLimiterMap.getWriteLimiter(tableName);
717721
}
718722

719-
720723
/**
721724
* Comsume rate limiter units after successful operation.
722725
* @return the number of milliseconds delayed due to rate limiting
723726
*/
724-
private int consumeLimiterUnits(RateLimiter rl, long units,
725-
Request request, int timeoutMs) {
727+
private int consumeLimiterUnits(RateLimiter rl,
728+
long units, int timeoutMs) {
726729

727730
if (rl == null || units <= 0) {
728731
return 0;
729732
}
730733

731734
/*
732735
* The logic consumes units (and potentially delays) _after_ a
733-
* successful operation for a few reasons:
736+
* successful operation for a couple reasons:
734737
* 1) We don't know the actual number of units an op uses unitl
735738
* after the operation successfully finishes
736739
* 2) Delaying after the op keeps the application from immediately
@@ -740,32 +743,12 @@ private int consumeLimiterUnits(RateLimiter rl, long units,
740743
* after a successful op, client threads will get staggered
741744
* better to avoid spikes in throughput and oscillation that
742745
* can result from it.
743-
* 3) For operations that use less than 100% of the limits (i.e.
744-
* they set a usePercent to less than 100), this is the only place
745-
* where the delay time may be longer, because the pre-operation
746-
* "wait for below the limit" limiter checks do not take usePercent
747-
* into account.
748746
*/
749747

750-
double usePercent = request.getRateLimiterPercentage();
751-
if (usePercent == 0.0) {
752-
usePercent = config.getDefaultRateLimitingPercentage();
753-
}
754748
try {
755-
if (rl instanceof SimpleRateLimiter && usePercent > 0.0) {
756-
/* "true" == "consume units, even on timeout" */
757-
return ((SimpleRateLimiter)rl).consumeUnitsWithTimeout(
758-
units, timeoutMs,
759-
true, usePercent);
760-
} else {
761-
/* "true" == "consume units, even on timeout" */
762-
return rl.consumeUnitsWithTimeout(units, timeoutMs, true);
763-
}
749+
return rl.consumeUnitsWithTimeout(units, timeoutMs, false);
764750
} catch (TimeoutException e) {
765-
/*
766-
* Do not throw: the operation succeeded.
767-
* We just delayed a while.
768-
*/
751+
/* Don't throw - operation succeeded. Just return timeoutMs. */
769752
return timeoutMs;
770753
}
771754
}
@@ -807,14 +790,19 @@ public boolean updateRateLimiters(String tableName, TableLimits limits) {
807790
int durationSeconds = Integer.getInteger("test.rldurationsecs", 30)
808791
.intValue();
809792

810-
rateLimiterMap.update(tableName,
811-
(double)limits.getReadUnits(),
812-
(double)limits.getWriteUnits(),
813-
durationSeconds);
793+
double RUs = (double)limits.getReadUnits();
794+
double WUs = (double)limits.getWriteUnits();
795+
796+
/* if there's a specified rate limiter percentage, use that */
797+
double rlPercent = config.getDefaultRateLimitingPercentage();
798+
if (rlPercent > 0.0) {
799+
RUs = (RUs * rlPercent) / 100.0;
800+
WUs = (WUs * rlPercent) / 100.0;
801+
}
814802

803+
rateLimiterMap.update(tableName, RUs, WUs, durationSeconds);
815804
final String msg = String.format("Updated table '%s' to have " +
816-
"RUs=%d and WUs=%d per second",
817-
tableName, limits.getReadUnits(), limits.getWriteUnits());
805+
"RUs=%.1f and WUs=%.1f per second", tableName, RUs, WUs);
818806
logInfo(logger, msg);
819807

820808
return true;
@@ -1146,7 +1134,8 @@ public void resetRateLimiters(String tableName) {
11461134
* executed by one thread when no other operations are
11471135
* in progress.
11481136
*/
1149-
public void enableRateLimiting(boolean enable) {
1137+
public void enableRateLimiting(boolean enable, double usePercent) {
1138+
config.setDefaultRateLimitingPercentage(usePercent);
11501139
if (enable == true && rateLimiterMap == null) {
11511140
rateLimiterMap = new RateLimiterMap();
11521141
tableLimitUpdateMap = new ConcurrentHashMap<String, AtomicLong>();

driver/src/main/java/oracle/nosql/driver/ops/Request.java

Lines changed: 0 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,6 @@ public abstract class Request {
6565
*/
6666
private RateLimiter writeRateLimiter;
6767

68-
/**
69-
* @hidden
70-
*/
71-
private double rateLimiterPercentage;
72-
7368
protected Request() {}
7469

7570
/**
@@ -211,34 +206,6 @@ public void setWriteRateLimiter(RateLimiter rl) {
211206
writeRateLimiter = rl;
212207
}
213208

214-
/**
215-
* Sets rate limiter percentage to use for this request.
216-
* Cloud service only.
217-
* <p>
218-
* This setting controls how much of a table's limits this request has
219-
* access to.
220-
* <p>
221-
* This setting is ignored if a rate limiter is set on this request
222-
* using {@link #setReadRateLimiter} or {@link #setWriteRateLimiter}.
223-
* <p>
224-
* This is only used if internal rate limiting is enabled using
225-
* {@link NoSQLHandleConfig#setRateLimitingEnabled}.
226-
* <p>
227-
* The default for this value is the value given to
228-
* {@link NoSQLHandleConfig#setDefaultRateLimitingPercentage}, or 100.0
229-
* if no default was set.
230-
*
231-
* @param percent the percentage of table limits to use. This value
232-
* must be positive.
233-
*/
234-
public void setRateLimiterPercentage(double percent) {
235-
if (percent <= 0.0) {
236-
throw new IllegalArgumentException(
237-
"rate limiter percentage must be positive");
238-
}
239-
rateLimiterPercentage = percent;
240-
}
241-
242209
/**
243210
* Returns the read rate limiter instance used during this request.
244211
* Cloud service only.
@@ -275,18 +242,6 @@ public RateLimiter getWriteRateLimiter() {
275242
return writeRateLimiter;
276243
}
277244

278-
/**
279-
* @hidden
280-
* Internal use only
281-
* @return percentage to use. 0.0 means full limits (same as 100.0).
282-
*/
283-
public double getRateLimiterPercentage() {
284-
if (rateLimiterPercentage <= 0.0) {
285-
return 100.0;
286-
}
287-
return rateLimiterPercentage;
288-
}
289-
290245
/**
291246
* @hidden
292247
* Internal use only

0 commit comments

Comments
 (0)