-
Notifications
You must be signed in to change notification settings - Fork 101
add rate limit for local backend, parse limit args #1066
base: master
Are you sure you want to change the base?
Conversation
[REVIEW NOTIFICATION] This pull request has not been approved. To complete the pull request process, please ask the reviewers in the list to review by filling The full list of commands accepted by this bot can be found here. Reviewer can indicate their review by writing |
Welcome @recall704! |
No release note, Please follow https://github.com/pingcap/community/blob/master/contributors/release-note-checker.md |
replace cloud.google.com/go/storage => github.com/3pointer/google-cloud-go/storage v1.6.1-0.20210108125931-b59bfa0720b2 | ||
replace ( | ||
cloud.google.com/go/storage => github.com/3pointer/google-cloud-go/storage v1.6.1-0.20210108125931-b59bfa0720b2 | ||
github.com/pingcap/kvproto v0.0.0-20210308063835-39b884695fb8 => github.com/recall704/kvproto v0.0.0-20210414071537-7bdfcba5f5d5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
pingcap/kvproto#756 PR required
No release note, Please follow https://github.com/pingcap/community/blob/master/contributors/release-note-checker.md |
Instead of adding a
The rate limiter should introduce a wrapper of |
type withRatelimit struct {
ExternalStorage
Ratelimit uint64 // Byte/sec
}
// WithRatelimit
func WithRatelimit(inner ExternalStorage, ratelimit uint64) ExternalStorage {
if ratelimit == 0 {
return inner
}
return &withRatelimit{ExternalStorage: inner, Ratelimit: ratelimit}
}
func (r *withRatelimit) Create(ctx context.Context, name string) (ExternalFileWriter, error) {
var (
writer ExternalFileWriter
err error
)
if localStorage, ok := r.ExternalStorage.(*LocalStorage); ok {
file, err := os.Create(filepath.Join(localStorage.base, name))
if err != nil {
return nil, errors.Trace(err)
}
buf := bufio.NewWriter(file)
if r.Ratelimit > 0 {
w := shapeio.NewWriterWithContext(buf, ctx)
w.SetRateLimit(float64(r.Ratelimit))
return newFlushStorageWriter(w, buf, file), nil
}
return newFlushStorageWriter(buf, buf, file), nil
}
writer, err = r.ExternalStorage.Create(ctx, name)
if err != nil {
return nil, errors.Trace(err)
}
return writer, nil
} I try to use thanks |
@recall704 sorry for late reply, there's a week-long holiday in China and Japan 🙃.
you could just return a wrapper type that implements type withRateLimitWriter struct {
ExternalFileWriter
Ratelimit uint64
}
func (r *withRatelimit) Create(ctx context.Context, name string) (ExternalFileWriter, error) {
inner, err := r.ExternalStorage.Create(ctx, name)
if err != nil {
return nil, err
}
return &withRateLimitWriter{
ExternalFileWriter: inner,
Ratelimit: r.Ratelimit,
}, nil
} and then apply the Ratelimit in its func (rw *withRateLimitWriter) Write(ctx context.Context, p []byte) (int, error) {
// do rate limiting here.
} There's no need to figure out how to fit this into |
@recall704: PR needs rebase. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. |
No release note, Please follow https://github.com/pingcap/community/blob/master/contributors/release-note-checker.md |
What problem does this PR solve?
add rate limit for local backend
What is changed and how it works?
set rate limit for
io.Writer