Skip to content

Commit

Permalink
Increase cache getter retry interval
Browse files Browse the repository at this point in the history
  • Loading branch information
anbsky committed Jan 22, 2025
1 parent 1060691 commit 3f80f5e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
10 changes: 7 additions & 3 deletions app/query/processors.go
Original file line number Diff line number Diff line change
Expand Up @@ -647,20 +647,24 @@ 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()
switch {
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))
}
Expand Down
7 changes: 6 additions & 1 deletion apps/lbrytv/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down Expand Up @@ -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)
}

0 comments on commit 3f80f5e

Please sign in to comment.