From 3f80f5e28d2782630e15febf0535196e195341c9 Mon Sep 17 00:00:00 2001 From: Andriy Biletsky Date: Wed, 22 Jan 2025 19:20:54 +0700 Subject: [PATCH] Increase cache getter retry interval --- app/query/processors.go | 10 +++++++--- apps/lbrytv/config/config.go | 7 ++++++- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/app/query/processors.go b/app/query/processors.go index 679bb824..9adafc2f 100644 --- a/app/query/processors.go +++ b/app/query/processors.go @@ -647,11 +647,15 @@ func preflightCacheHook(caller *Caller, ctx context.Context) (*jsonrpc.RPCRespon query := QueryFromContext(ctx) getterRetries := config.GetCacheGetterRetries() + getterInterval := config.GetCacheGetterInterval() + getter := func() (any, error) { var resp *jsonrpc.RPCResponse var err error + totalStart := time.Now() for attempt := range getterRetries { - time.Sleep(time.Duration(attempt) * time.Second) + currentInterval := time.Duration(attempt) * getterInterval + time.Sleep(currentInterval) start := time.Now() resp, err = caller.SendQuery(ctx, query) duration := time.Since(start).Seconds() @@ -659,8 +663,8 @@ func preflightCacheHook(caller *Caller, ctx context.Context) (*jsonrpc.RPCRespon case err == nil && resp.Error == nil: if attempt > 0 { log.Infof( - "cache retriever %s attempt #%d succeeded", - query.Method(), attempt, + "cache retriever %s attempt #%d succeeded (after spending %.2f seconds)", + query.Method(), attempt, time.Since(totalStart).Seconds(), ) QueryCacheRetrySuccesses.Observe(float64(attempt)) } diff --git a/apps/lbrytv/config/config.go b/apps/lbrytv/config/config.go index 433d9f0b..8ca6cd69 100644 --- a/apps/lbrytv/config/config.go +++ b/apps/lbrytv/config/config.go @@ -193,13 +193,17 @@ func GetLbrynetServers() map[string]string { } func GetTokenCacheTimeout() time.Duration { - return Config.Viper.GetDuration("TokenCacheTimeout") * time.Second + return Config.Viper.GetDuration("TokenCacheTimeout") } func GetCacheGetterRetries() int { return Config.Viper.GetInt("CacheGetterRetries") } +func GetCacheGetterInterval() time.Duration { + return Config.Viper.GetDuration("CacheGetterInterval") +} + func GetCORSDomains() []string { return Config.Viper.GetStringSlice("CORSDomains") } @@ -259,4 +263,5 @@ func init() { c.Viper.SetDefault("Host", "http://localhost:8080") c.Viper.SetDefault("Logging", map[string]string{"level": "debug", "format": "console"}) c.Viper.SetDefault("CacheGetterRetries", 3) + c.Viper.SetDefault("CacheGetterInterval", 1*time.Second) }