Skip to content

Commit

Permalink
fix not applying max concurrency from gatewayBotRs & cleanup sharding…
Browse files Browse the repository at this point in the history
… ratelimiter
  • Loading branch information
topi314 committed May 16, 2022
1 parent 01a73fe commit d66ebe1
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 10 deletions.
2 changes: 1 addition & 1 deletion bot/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ func BuildClient(token string, config Config, gatewayEventHandlerFunc func(clien
),
sharding.WithLogger(client.logger),
func(config *sharding.Config) {
config.RateLimiterConfigOpts = append([]srate.ConfigOpt{srate.WithLogger(client.logger)}, config.RateLimiterConfigOpts...)
config.RateLimiterConfigOpts = append([]srate.ConfigOpt{srate.WithLogger(client.logger), srate.WithMaxConcurrency(gatewayBotRs.SessionStartLimit.MaxConcurrency)}, config.RateLimiterConfigOpts...)
},
}, config.ShardManagerConfigOpts...)

Expand Down
10 changes: 2 additions & 8 deletions sharding/srate/shard_rate_limiter_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,12 @@ func DefaultConfig() *Config {
return &Config{
Logger: log.Default(),
MaxConcurrency: 1,
StartupDelay: 5,
}
}

type Config struct {
Logger log.Logger
MaxConcurrency int
StartupDelay int
}

type ConfigOpt func(config *Config)
Expand All @@ -26,20 +24,16 @@ func (c *Config) Apply(opts []ConfigOpt) {
}
}

// WithLogger sets the logger for the Limiter.
func WithLogger(logger log.Logger) ConfigOpt {
return func(config *Config) {
config.Logger = logger
}
}

// WithMaxConcurrency sets the maximum number of concurrent identifies in 5 seconds.
func WithMaxConcurrency(maxConcurrency int) ConfigOpt {
return func(config *Config) {
config.MaxConcurrency = maxConcurrency
}
}

func WithStartupDelay(startupDelay int) ConfigOpt {
return func(config *Config) {
config.StartupDelay = startupDelay
}
}
2 changes: 1 addition & 1 deletion sharding/srate/shard_rate_limiter_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ func (r *limiterImpl) UnlockBucket(shardID int) {
b.mu.Unlock()
}()

b.Reset = time.Now().Add(time.Duration(r.config.StartupDelay) * time.Second)
b.Reset = time.Now().Add(5 * time.Second)
}

type bucket struct {
Expand Down

0 comments on commit d66ebe1

Please sign in to comment.