Skip to content

Commit

Permalink
Merge pull request #538 from OdyseeTeam/improve-cache-getter-retry
Browse files Browse the repository at this point in the history
Increase cache getter retry interval
  • Loading branch information
anbsky authored Jan 22, 2025
2 parents 5c98a2e + 1da19b6 commit 087513e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 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)
}
2 changes: 1 addition & 1 deletion apps/lbrytv/config/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestGetLbrynetServersNoDB(t *testing.T) {
}

func TestGetTokenCacheTimeout(t *testing.T) {
Config.Override("TokenCacheTimeout", 325)
Config.Override("TokenCacheTimeout", "325s")
defer Config.RestoreOverridden()
assert.Equal(t, 325*time.Second, GetTokenCacheTimeout())
}
Expand Down

0 comments on commit 087513e

Please sign in to comment.