Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
resolve issue #93 (#106)
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 authored Nov 6, 2024
1 parent 775273c commit d6277d5
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
## Unreleased

FEATURES:

* Add pause between requests in buckets discovering. Configured by config DiscoveryWorkStep, default is 10ms.

## v1.2.0

CHANGES:
Expand Down
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
8 changes: 8 additions & 0 deletions vshard.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,9 @@ type Config struct {
// DiscoveryTimeout is timeout between cron discovery job; by default there is no timeout.
DiscoveryTimeout time.Duration
DiscoveryMode DiscoveryMode
// DiscoveryWorkStep is a pause between calling buckets_discovery on storage
// in buckets discovering logic. Default is 10ms.
DiscoveryWorkStep time.Duration

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

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

err := validateCfg(cfg)
if err != nil {
Expand All @@ -258,6 +262,10 @@ func prepareCfg(ctx context.Context, cfg Config) (Config, error) {
cfg.Metrics = emptyMetricsProvider
}

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

return cfg, nil
}

Expand Down

0 comments on commit d6277d5

Please sign in to comment.