-
Notifications
You must be signed in to change notification settings - Fork 41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat:add upload download add bandwidth limit #411
Conversation
2aeb8d7
to
ed9edae
Compare
config/config.go
Outdated
@@ -44,6 +44,7 @@ type StorageProviderConfig struct { | |||
RateLimiter *localhttp.RateLimiterConfig | |||
DiscontinueCfg *stopserving.DiscontinueConfig | |||
MetadataCfg *metadata.MetadataConfig | |||
BandwidthLimiter *localhttp.BandWidthLimiterConfig |
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.
Rename BandWidthLimiterConfig
to BandwidthLimiterConfig
.
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.
fixed
@@ -208,6 +210,10 @@ var DefaultRateLimiterConfig = &localhttp.RateLimiterConfig{ | |||
}, | |||
} | |||
|
|||
var DefaultBandwidthLimiterConfig = &localhttp.BandWidthLimiterConfig{ | |||
Enable: false, |
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.
Maybe you need to update the default configuration synchronously at config/config_template.toml.
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.
added
pkg/middleware/http/tokenBucket.go
Outdated
type BandWidthLimiterConfig struct { | ||
Enable bool | ||
R rate.Limit | ||
B int |
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.
Add more commentaries to explain the config meaning.
This naming convention is a bit vague for the name that the user needs to configure, and the user may not understand it.
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.
Annotated
service/gateway/object_handler.go
Outdated
// If it is limited, it will block | ||
if localHttp.BandWidthLimit != nil { | ||
if err := localHttp.BandWidthLimit.Limiter.Wait(ctx); err != nil { | ||
log.Errorw("failed to Wait bandwidth limiter", "err", err) |
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.
Refine Wait
to wait
, err
to error
in log.
service/gateway/object_handler.go
Outdated
@@ -223,6 +229,12 @@ func (gateway *Gateway) putObjectHandler(w http.ResponseWriter, r *http.Request) | |||
return | |||
} | |||
if readN > 0 { | |||
// If it is limited, it will block | |||
if localHttp.BandWidthLimit != nil { | |||
if err := localHttp.BandWidthLimit.Limiter.Wait(ctx); err != nil { |
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.
I don't understand how to calculate the actual bandwidth of the service?
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.
The first version of the implementation was simple and limited to whether data could be read from the network
ed9edae
to
56ac4f7
Compare
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.
LGTM
abea273
to
abe9cc1
Compare
abe9cc1
to
476c356
Compare
Description
Upload and download with broadband stream implementation
Rationale
Protect the sp service
Example
Limit the upload and download speed
Changes
Notable changes: