diff --git a/config/storage.go b/config/storage.go index 5c75a87..2f29e37 100644 --- a/config/storage.go +++ b/config/storage.go @@ -24,8 +24,11 @@ type Storage struct { TablespaceMap map[string]string `json:"tablespace_map" toml:"tablespace_map" yaml:"tablespace_map"` // how many concurrent connection acquire allowed - StorageConcurrency int64 `json:"storage_concurrency" toml:"storage_concurrency" yaml:"storage_concurrency"` - StorageRateLimit uint64 `json:"storage_rate_limit" toml:"storage_rate_limit" yaml:"storage_rate_limit"` + StorageConcurrency int64 `json:"storage_concurrency" toml:"storage_concurrency" yaml:"storage_concurrency"` + + // default will be false + EnableRateLimiter bool `json:"enable_rate_limiter" toml:"enable_rate_limiter" yaml:"enable_rate_limiter"` + StorageRateLimit uint64 `json:"storage_rate_limit" toml:"storage_rate_limit" yaml:"storage_rate_limit"` StorageRegion string `json:"storage_region" toml:"storage_region" yaml:"storage_region"` diff --git a/pkg/proc/yio/yrreader.go b/pkg/proc/yio/yrreader.go index 993e85c..0f91f85 100644 --- a/pkg/proc/yio/yrreader.go +++ b/pkg/proc/yio/yrreader.go @@ -5,6 +5,7 @@ import ( "io" "time" + "github.com/yezzey-gp/yproxy/config" "github.com/yezzey-gp/yproxy/pkg/client" "github.com/yezzey-gp/yproxy/pkg/proc/yio/limiter" "github.com/yezzey-gp/yproxy/pkg/settings" @@ -46,6 +47,8 @@ func NewRestartReader(s storage.StorageInteractor, l := limiter.GetLimiter() + /* due to storage config "enable limiter" can change on read-restart, allocate + * limiter unconditionally */ return &YRestartReader{ s: s, name: name, @@ -68,9 +71,13 @@ func (y *YRestartReader) Restart(offsetStart int64) error { return err } - /* with limiter */ + /* with limiter ? */ - y.underlying = limiter.NewReader(r, y.lim) + if config.InstanceConfig().StorageCnf.EnableRateLimiter { + y.underlying = limiter.NewReader(r, y.lim) + } else { + y.underlying = r + } return nil } diff --git a/pkg/proc/yio/ywriter.go b/pkg/proc/yio/ywriter.go index eba0214..3a3130d 100644 --- a/pkg/proc/yio/ywriter.go +++ b/pkg/proc/yio/ywriter.go @@ -3,6 +3,7 @@ package yio import ( "io" + "github.com/yezzey-gp/yproxy/config" "github.com/yezzey-gp/yproxy/pkg/client" "github.com/yezzey-gp/yproxy/pkg/proc/yio/limiter" "github.com/yezzey-gp/yproxy/pkg/ylogger" @@ -41,12 +42,19 @@ func NewYproxyWriter(under io.WriteCloser, selfCl client.YproxyClient) io.WriteC w := &YproxyWriter{ underlying: under, - lim: limiter.GetLimiter(), selfCl: selfCl, offsetReached: 0, } - w.underlying = limiter.NewWriter(under, w.lim) + /* with limiter ? */ + + if config.InstanceConfig().StorageCnf.EnableRateLimiter { + w.lim = limiter.GetLimiter() + w.underlying = limiter.NewWriter(under, w.lim) + } else { + w.underlying = under + } + return w }