-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: find endpoints asynchronously, cache errors (#419)
Goals: 1. Make endpoint lookup parallel across all SPs 2. Don't error unless we don't have any endpoints—but log an error 3. Cache the error case too because it's not cheap and with a misbehaving SP it'll slow down every call for a particular piece
- Loading branch information
Showing
4 changed files
with
141 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package endpointfinder | ||
|
||
import "time" | ||
|
||
const ( | ||
defaultLruSize = 128 | ||
defaultLruTimeout = 2 * time.Hour | ||
defaultErrorLruSize = 128 | ||
defaultErrorLruTimeout = 5 * time.Minute | ||
) | ||
|
||
type config struct { | ||
LruSize int | ||
LruTimeout time.Duration | ||
ErrorLruSize int | ||
ErrorLruTimeout time.Duration | ||
} | ||
|
||
func applyOptions(opts ...Option) *config { | ||
cfg := &config{ | ||
LruSize: defaultLruSize, | ||
ErrorLruSize: defaultErrorLruSize, | ||
ErrorLruTimeout: defaultErrorLruTimeout, | ||
} | ||
for _, opt := range opts { | ||
opt(cfg) | ||
} | ||
return cfg | ||
} | ||
|
||
type Option func(*config) | ||
|
||
func WithLruSize(size int) Option { | ||
return func(cfg *config) { | ||
cfg.LruSize = size | ||
} | ||
} | ||
|
||
func WithLruTimeout(timeout time.Duration) Option { | ||
return func(cfg *config) { | ||
cfg.LruTimeout = timeout | ||
} | ||
} | ||
|
||
func WithErrorLruSize(size int) Option { | ||
return func(cfg *config) { | ||
cfg.ErrorLruSize = size | ||
} | ||
} | ||
|
||
func WithErrorLruTimeout(timeout time.Duration) Option { | ||
return func(cfg *config) { | ||
cfg.ErrorLruTimeout = timeout | ||
} | ||
} |