bandwidth

package
v0.1.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 9, 2019 License: Apache-2.0 Imports: 7 Imported by: 4

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

func NewLimiter(config Config, opts ...Option) (*Limiter, error)

NewLimiter creates a new Limiter.

func (*Limiter) Adjust

func (l *Limiter) Adjust(denominator int) error

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

func (l *Limiter) EgressLimit() int64

EgressLimit returns the current egress limit.

func (*Limiter) IngressLimit

func (l *Limiter) IngressLimit() int64

IngressLimit returns the current ingress limit.

func (*Limiter) ReserveEgress

func (l *Limiter) ReserveEgress(nbytes int64) error

ReserveEgress blocks until egress bandwidth for nbytes is available. Returns error if nbytes is larger than the maximum egress bandwidth.

func (*Limiter) ReserveIngress

func (l *Limiter) ReserveIngress(nbytes int64) error

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL