Skip to content

Commit

Permalink
resolve issue #93
Browse files Browse the repository at this point in the history
* Add a pause between bucketsDiscovery requests (default is 10 ms)
  • Loading branch information
nurzhan-saktaganov committed Oct 29, 2024
1 parent d0298bd commit dd210df
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
4 changes: 4 additions & 0 deletions discovery.go
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ func (r *Router) DiscoveryAllBuckets(ctx context.Context) error {
}

bucketsDiscoveryPaginationFrom = resp.NextFrom

// Don't spam many requests at once. Give storages time to handle them and other requests.
// https://github.com/tarantool/vshard/blob/b6fdbe950a2e4557f05b83bd8b846b126ec3724e/vshard/router/init.lua#L308
time.Sleep(r.cfg.DiscoveryWorkStep)
}
})
}
Expand Down
10 changes: 8 additions & 2 deletions vshard.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,9 @@ type Config struct {

// Discovery
// DiscoveryTimeout is timeout between cron discovery job; by default there is no timeout.
DiscoveryTimeout time.Duration
DiscoveryMode DiscoveryMode
DiscoveryTimeout time.Duration
DiscoveryWorkStep time.Duration
DiscoveryMode DiscoveryMode

// BucketsSearchMode defines policy for BucketDiscovery method.
// Default value is BucketsSearchLegacy.
Expand Down Expand Up @@ -234,6 +235,7 @@ func (r *Router) RouteMapClean() {

func prepareCfg(cfg Config) (Config, error) {
const discoveryTimeoutDefault = 1 * time.Minute
const discoveryWorkStepDefault = 10 * time.Millisecond

err := validateCfg(cfg)
if err != nil {
Expand All @@ -244,6 +246,10 @@ func prepareCfg(cfg Config) (Config, error) {
cfg.DiscoveryTimeout = discoveryTimeoutDefault
}

if cfg.DiscoveryWorkStep == 0 {
cfg.DiscoveryWorkStep = discoveryWorkStepDefault
}

if cfg.Loggerf == nil {
cfg.Loggerf = emptyLogfProvider
}
Expand Down

0 comments on commit dd210df

Please sign in to comment.