Documentation ¶
Overview ¶
Copyright (c) 2016-2019 Uber Technologies, Inc.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { EgressBitsPerSec uint64 `yaml:"egress_bits_per_sec"` IngressBitsPerSec uint64 `yaml:"ingress_bits_per_sec"` // TokenSize defines the granularity of a token in the bucket. It is used to // avoid integer overflow errors that would occur if we mapped each bit to a // token. TokenSize uint64 `yaml:"token_size"` Enable bool `yaml:"enable"` }
Config defines Limiter configuration.
type Limiter ¶
type Limiter struct {
// contains filtered or unexported fields
}
Limiter limits egress and ingress bandwidth via token-bucket rate limiter.
func NewLimiter ¶
NewLimiter creates a new Limiter.
func (*Limiter) Adjust ¶
Adjust divides the originally configured egress and ingress bps by denominator. Note, because the original configuration is always used, multiple Adjust calls have no affect on each other.
func (*Limiter) EgressLimit ¶
EgressLimit returns the current egress limit.
func (*Limiter) IngressLimit ¶
IngressLimit returns the current ingress limit.
func (*Limiter) ReserveEgress ¶
ReserveEgress blocks until egress bandwidth for nbytes is available. Returns error if nbytes is larger than the maximum egress bandwidth.
func (*Limiter) ReserveIngress ¶
ReserveIngress blocks until ingress bandwidth for nbytes is available. Returns error if nbytes is larger than the maximum ingress bandwidth.
type Option ¶
type Option func(*Limiter)
Option allows setting optional parameters in Limiter.
func WithLogger ¶
func WithLogger(logger *zap.SugaredLogger) Option
WithLogger configures a Limiter with a custom logger.