Skip to content

Commit

Permalink
Remove throttling lib
Browse files Browse the repository at this point in the history
  • Loading branch information
kai-niemi committed Feb 12, 2024
1 parent a2ce7a9 commit 5476ee7
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 102 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import io.burpabet.common.shell.AnsiConsole;
import io.burpabet.common.shell.CommandGroups;
import io.burpabet.common.shell.JurisdictionValueProvider;
import io.burpabet.common.shell.ThrottledPredicates;
import io.burpabet.common.util.Money;
import io.burpabet.common.util.Networking;
import io.burpabet.common.util.RandomData;
Expand Down Expand Up @@ -101,11 +100,7 @@ public void placeBet(
@ShellOption(help = "number of bets per customer",
defaultValue = "1") int count,
@ShellOption(help = "duration for placements in seconds (>0 overrides count)",
defaultValue = "0") int duration,
@ShellOption(help = "max bets per minute (if count > 1)",
defaultValue = "120") int ratePerMin,
@ShellOption(help = "max bets per sec (if count > 1)",
defaultValue = "5") int ratePerSec
defaultValue = "0") int duration
) {
final Collection<Map<String, Object>> customerMap = new ArrayList<>();

Expand Down Expand Up @@ -148,13 +143,11 @@ public void placeBet(
if (duration > 0) {
final Duration theDuration = Duration.ofSeconds(duration);

logger.info("Placing bets for %s with rate limit of %d per minute and %d per sec"
.formatted(theDuration, ratePerMin, ratePerSec));
logger.info("Placing bets for %s"
.formatted(theDuration));

Predicate<Integer> completion =
ThrottledPredicates.timePredicate(Instant.now().plus(theDuration), ratePerMin, ratePerSec);

workloadExecutor.submit("Placement - " + map.get("name"), c, completion);
workloadExecutor.submit("Placement - " + map.get("name"), c,
x -> Instant.now().isBefore(Instant.now().plus(theDuration)));
} else {
IntStream.rangeClosed(1, count).forEach(value -> {
try {
Expand All @@ -180,9 +173,7 @@ public void settle(
@ShellOption(help = "query page size when iterating all races", defaultValue = "64") int pageSize,
@ShellOption(help = "number of settlements", defaultValue = "1") int count,
@ShellOption(help = "duration for settlements in seconds (>0 overrides count)", defaultValue = "0")
int duration,
@ShellOption(help = "max settlements per minute", defaultValue = "30") int ratePerMin,
@ShellOption(help = "max settlements per sec", defaultValue = "2") int ratePerSec
int duration
) {
final Duration theDuration = Duration.ofSeconds(duration);

Expand All @@ -209,13 +200,10 @@ public void settle(
};

if (duration > 0) {
logger.info("Settling bets for %s with rate limit of %d per minute and %d per sec"
.formatted(theDuration, ratePerMin, ratePerSec));

Predicate<Integer> completion =
ThrottledPredicates.timePredicate(Instant.now().plus(theDuration), ratePerMin, ratePerSec);
logger.info("Settling bets for %s".formatted(theDuration));

workloadExecutor.submit("Settlement", c, completion);
workloadExecutor.submit("Settlement", c,
x -> Instant.now().isBefore(Instant.now().plus(theDuration)));
} else {
IntStream.rangeClosed(1, count).forEach(value -> {
try {
Expand Down
4 changes: 0 additions & 4 deletions burpabet-common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,6 @@
<groupId>org.springframework.shell</groupId>
<artifactId>spring-shell-starter</artifactId>
</dependency>
<dependency>
<groupId>com.bucket4j</groupId>
<artifactId>bucket4j-core</artifactId>
</dependency>
<!-- Test -->
<dependency>
<groupId>org.junit.jupiter</groupId>
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
import io.burpabet.common.shell.AnsiConsole;
import io.burpabet.common.shell.CommandGroups;
import io.burpabet.common.shell.JurisdictionValueProvider;
import io.burpabet.common.shell.ThrottledPredicates;
import io.burpabet.common.util.Networking;
import io.burpabet.common.util.RandomData;
import io.burpabet.common.util.TableUtils;
Expand Down Expand Up @@ -77,7 +76,6 @@ public void register(
.asLongStream()
.unordered()
.parallel()
.takeWhile(ThrottledPredicates.longPredicate(ratePerMin, ratePerSec))
.forEach(value -> {
Pair<String, String> pair = RandomData.randomFullNameAndEmail("burpabet.io");

Expand Down
5 changes: 0 additions & 5 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -101,11 +101,6 @@
<artifactId>postgresql</artifactId>
<version>42.7.0</version>
</dependency>
<dependency>
<groupId>com.bucket4j</groupId>
<artifactId>bucket4j-core</artifactId>
<version>8.7.1</version>
</dependency>

<!-- Test -->
<dependency>
Expand Down

0 comments on commit 5476ee7

Please sign in to comment.