-
Notifications
You must be signed in to change notification settings - Fork 41
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #411 from bnb-chain/feat-bandwidth-limit
feat:add upload download add bandwidth limit
- Loading branch information
Showing
9 changed files
with
71 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package http | ||
|
||
import ( | ||
"sync" | ||
|
||
"github.com/bnb-chain/greenfield-storage-provider/pkg/log" | ||
"golang.org/x/time/rate" | ||
) | ||
|
||
type BandwidthLimiterConfig struct { | ||
Enable bool //Enable Whether to enable bandwidth limiting | ||
R rate.Limit //R The speed at which tokens are generated R per second | ||
B int //B The size of the token bucket | ||
} | ||
|
||
type BandwidthLimiter struct { | ||
Limiter *rate.Limiter | ||
} | ||
|
||
var LimiterOnce sync.Once | ||
var BandwidthLimit *BandwidthLimiter | ||
|
||
func NewBandwidthLimiter(r rate.Limit, b int) { | ||
log.Infof("config r: %v, b:%d", r, b) | ||
|
||
LimiterOnce.Do(func() { | ||
BandwidthLimit = &BandwidthLimiter{ | ||
Limiter: rate.NewLimiter(r, b), | ||
} | ||
}) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters