mirror of
https://github.com/BrenBroZAYT/gameyfin.git
synced 2026-06-14 16:20:04 +00:00
Added config properties for max req/s and max concurrent requests
This commit is contained in:
@@ -5,7 +5,9 @@ import io.github.resilience4j.bulkhead.BulkheadConfig;
|
||||
import io.github.resilience4j.ratelimiter.RateLimiter;
|
||||
import io.github.resilience4j.ratelimiter.RateLimiterConfig;
|
||||
import io.netty.handler.logging.LogLevel;
|
||||
import lombok.Getter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.boot.web.reactive.function.client.WebClientCustomizer;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
@@ -20,24 +22,32 @@ import reactor.netty.transport.logging.AdvancedByteBufFormat;
|
||||
import java.time.Duration;
|
||||
|
||||
@Slf4j
|
||||
@Getter
|
||||
@Configuration
|
||||
public class WebClientConfig implements WebClientCustomizer {
|
||||
|
||||
// The IGDB API has a rate limit of 4 req/s
|
||||
public static final RateLimiter IGDB_RATE_LIMITER = RateLimiter.of("igdb-rate-limiter",
|
||||
RateLimiterConfig.custom()
|
||||
.limitForPeriod(4)
|
||||
.limitRefreshPeriod(Duration.ofSeconds(1))
|
||||
.timeoutDuration(Duration.ofMinutes(1))
|
||||
.build());
|
||||
private final RateLimiter igdbRateLimiter;
|
||||
private final Bulkhead igdbConcurrencyLimiter;
|
||||
|
||||
// According to the docs, there is a maximum of 8 concurrent requests, but in my tests the actual limit was 4
|
||||
// and even then it sometimes failed, so I set it to 3 to be sure
|
||||
public static final Bulkhead IGDB_CONCURRENCY_LIMITER = Bulkhead.of("igdb-concurrency-limiter",
|
||||
BulkheadConfig.custom()
|
||||
.maxConcurrentCalls(2)
|
||||
.maxWaitDuration(Duration.ofMinutes(1))
|
||||
.build());
|
||||
|
||||
public WebClientConfig(@Value("${gameyfin.igdb.api.max-concurrent-requests}") int maxConcurrentRequestsToIgdb,
|
||||
@Value("${gameyfin.igdb.api.max-requests-per-second}") int maxRequestsPerSecondToIgdb) {
|
||||
|
||||
log.info("IGDB API connection properties: max. {} req/s, max. {} concurrent requests", maxRequestsPerSecondToIgdb, maxConcurrentRequestsToIgdb);
|
||||
|
||||
igdbRateLimiter = RateLimiter.of("igdb-rate-limiter",
|
||||
RateLimiterConfig.custom()
|
||||
.limitForPeriod(maxRequestsPerSecondToIgdb)
|
||||
.limitRefreshPeriod(Duration.ofSeconds(1))
|
||||
.timeoutDuration(Duration.ofMinutes(1))
|
||||
.build());
|
||||
|
||||
igdbConcurrencyLimiter = Bulkhead.of("igdb-concurrency-limiter",
|
||||
BulkheadConfig.custom()
|
||||
.maxConcurrentCalls(maxConcurrentRequestsToIgdb)
|
||||
.maxWaitDuration(Duration.ofMinutes(1))
|
||||
.build());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(WebClient.Builder webClientBuilder) {
|
||||
|
||||
@@ -38,6 +38,9 @@ public class IgdbWrapper {
|
||||
@Autowired
|
||||
private WebClient.Builder webclientBuilder;
|
||||
|
||||
@Autowired
|
||||
private WebClientConfig webClientConfig;
|
||||
|
||||
private WebClient twitchApiClient;
|
||||
|
||||
private WebClient igdbApiClient;
|
||||
@@ -173,8 +176,8 @@ public class IgdbWrapper {
|
||||
.bodyValue(query)
|
||||
.retrieve()
|
||||
.bodyToMono(responseClass)
|
||||
.transformDeferred(BulkheadOperator.of(WebClientConfig.IGDB_CONCURRENCY_LIMITER))
|
||||
.transformDeferred(RateLimiterOperator.of(WebClientConfig.IGDB_RATE_LIMITER))
|
||||
.transformDeferred(BulkheadOperator.of(webClientConfig.getIgdbConcurrencyLimiter()))
|
||||
.transformDeferred(RateLimiterOperator.of(webClientConfig.getIgdbRateLimiter()))
|
||||
.block();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,8 +14,15 @@ gameyfin.db=${gameyfin.root}/.gameyfin/db
|
||||
# File extensions which gameyfin will recognize as game files
|
||||
gameyfin.file-extensions=iso, zip, rar, 7z, exe
|
||||
|
||||
# List of IGDB platform enums to limit search results. FOr possible values see: https://api-docs.igdb.com/#platform
|
||||
# List of IGDB platform enums to limit search results. For possible values see: https://api-docs.igdb.com/#platform
|
||||
gameyfin.igdb.config.preferred-platforms=6
|
||||
|
||||
# Twitch Client ID and Client Secret
|
||||
gameyfin.igdb.api.client-id=
|
||||
gameyfin.igdb.api.client-secret=
|
||||
gameyfin.igdb.api.client-secret=
|
||||
|
||||
# The IGDB API has a rate limit of 4 req/s
|
||||
gameyfin.igdb.api.max-requests-per-second=4
|
||||
|
||||
# According to the docs, there is a maximum of 8 concurrent requests, but in my tests the actual limit was 4 and even then it sometimes failed, so I set it to 2 to be sure
|
||||
gameyfin.igdb.api.max-concurrent-requests=2
|
||||
Reference in New Issue
Block a user