Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions config/storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`

Expand Down
11 changes: 9 additions & 2 deletions pkg/proc/yio/yrreader.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
Expand Down
12 changes: 10 additions & 2 deletions pkg/proc/yio/ywriter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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
}

Expand Down
Loading