ratelimiter

package module
v0.0.0-...-68135e7 Latest Latest
Warning

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

Go to latest
Published: Oct 20, 2018 License: MIT Imports: 2 Imported by: 0

README

RateLimiter Build Status Go Report Card GoDoc

go-ratelimiter

RateLimiter can be used to limit the rate at which work is done, for example to control the TPS in a load testing client

Installation

Use the 'go' command: $ go get github.com/taylorza/go-ratelimiter

Example

package main

import (
	"fmt"
	"time"

	"github.com/taylorza/go-ratelimiter"
)

func main() {
	// create a rate limiter that will limit work to 1 per second
	l := ratelimiter.New(1)

	// print a '.' at a rate of 1 per second
	start := time.Now()
	for i := 0; i < 10; i++ {
		l.Throttle()
		fmt.Print(".")
	}
	fmt.Println()
	fmt.Println("Time taken:", time.Since(start))
}

Copyright (C)2013-2018 by Chris Taylor (taylorza) See LICENSE

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Limiter

type Limiter struct {
	// contains filtered or unexported fields
}

Limiter used to limit the rate at which work is done

func New

func New(rate uint) *Limiter

New creates a rate limiter that can be used to throttle work to target rate per second. The returned ratelimiter is started and ready to throttle.

func (*Limiter) SetRate

func (l *Limiter) SetRate(rate uint)

SetRate updates the rate of the ratelimiter on the fly.

func (*Limiter) Start

func (l *Limiter) Start()

Start a stopped ratelimiter if the rate limiter is already started the operation does nothing.

func (*Limiter) Stop

func (l *Limiter) Stop()

Stop the rate limiter and releases the internal resources.

func (*Limiter) Throttle

func (l *Limiter) Throttle()

Throttle blocks if the current rate of work exceeds the limiter.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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