• Stars
    star
    252
  • Rank 161,312 (Top 4 %)
  • Language
    Go
  • License
    MIT License
  • Created about 10 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Measure and throttle the rate at which data is transferred.

iocontrol

-- import "github.com/aybabtme/iocontrol"

Package iocontrol offers io.Writer, io.Reader, io.WriterAt, and io.ReaderAt implementations that allow one to measure and throttle the rate at which data is transferred.

Usage

const (
	KiB = 1 << 10
	MiB = 1 << 20
	GiB = 1 << 30
)

Orders of magnitude of data, in kibibyte (powers of 2, or multiples of 1024). See https://en.wikipedia.org/wiki/Kibibyte.

Exposed Methods and Types

For all of the exposed functionality, there are versions for all of io.{Reader,Writer}At with intuitive naming conventions.

The io.{Reader,Writer} implementations are documented below.

func ThrottledReader

func ThrottledReader(r io.Reader, bytesPerSec int, maxBurst time.Duration) io.Reader

ThrottledReader ensures that reads to r never exceeds a specified rate of bytes per second. The maxBurst duration changes how often the verification is done. The smaller the value, the less bursty, but also the more overhead there is to the throttling.

func ThrottledWriter

func ThrottledWriter(w io.Writer, bytesPerSec int, maxBurst time.Duration) io.Writer

ThrottledWriter ensures that writes to w never exceeds a specified rate of bytes per second. The maxBurst duration changes how often the verification is done. The smaller the value, the less bursty, but also the more overhead there is to the throttling.

type MeasuredReader

type MeasuredReader struct {
}

MeasuredReader wraps a reader and tracks how many bytes are read to it.

func NewMeasuredReader

func NewMeasuredReader(r io.Reader) *MeasuredReader

NewMeasuredReader wraps a reader.

func (*MeasuredReader) BytesPer

func (m *MeasuredReader) BytesPer(perPeriod time.Duration) uint64

BytesPer tells the rate per period at which bytes were read since last measurement.

func (*MeasuredReader) BytesPerSec

func (m *MeasuredReader) BytesPerSec() uint64

BytesPerSec tells the rate per second at which bytes were read since last measurement.

func (*MeasuredReader) Read

func (m *MeasuredReader) Read(b []byte) (n int, err error)

func (*MeasuredReader) Total

func (m *MeasuredReader) Total() int

Total number of bytes that have been read.

type MeasuredWriter

type MeasuredWriter struct {
}

MeasuredWriter wraps a writer and tracks how many bytes are written to it.

func NewMeasuredWriter

func NewMeasuredWriter(w io.Writer) *MeasuredWriter

NewMeasuredWriter wraps a writer.

func (*MeasuredWriter) BytesPer

func (m *MeasuredWriter) BytesPer(perPeriod time.Duration) uint64

BytesPer tells the rate per period at which bytes were written since last measurement.

func (*MeasuredWriter) BytesPerSec

func (m *MeasuredWriter) BytesPerSec() uint64

BytesPerSec tells the rate per second at which bytes were written since last measurement.

func (*MeasuredWriter) Total

func (m *MeasuredWriter) Total() int

Total number of bytes that have been written.

func (*MeasuredWriter) Write

func (m *MeasuredWriter) Write(b []byte) (n int, err error)

More Repositories

1

humanlog

Logs for humans to read.
Go
428
star
2

rgbterm

RGB colors for your terminal
Go
250
star
3

uniplot

Makes histograms and barcharts.
Go
209
star
4

datagen

Generate datastructures for your types.
Go
77
star
5

bitflip

Flip bits in files.
Go
61
star
6

portproxy

TCP proxy, highjacks HTTP to allow CORS
Go
53
star
7

tailf

Read and follow subsequent writes to a file. Like tailf.
Go
52
star
8

untilitworks

Retry some command until it works.
Go
47
star
9

fatherhood

Fatherhood is a JSON stream decoding library wrapping megajson's scanner.
Go
42
star
10

streamql

StreamQL is a stream query language
Go
17
star
11

color

Colorize your terminal strings.
Go
17
star
12

benchkit

Benchkit is the lightweight, feather touch, benchmarking kit.
Go
17
star
13

log

Structured logger.
Go
15
star
14

bomberman

A bomberman game!
Go
15
star
15

desim

Discrete Event Simulations
Go
13
star
16

orderedjson

Type to unmarshal JSON objects while keeping the order of the keys.
Go
10
star
17

erasure

Demo of XOR erasure coding.
Go
10
star
18

godotto

Among other things, a DigitalOcean REPL
Go
9
star
19

pkgname

Tells if your package has a good name, or not.
Go
9
star
20

brog

Static blog app.
Go
8
star
21

goblog

Course project to build a blogging engine in Go.
Go
8
star
22

dpprof

Proxy to use Go pprof against multiple servers
Go
7
star
23

graph

Graph package providing various implementations of graph data structures and graph processing algorithms.
Go
7
star
24

dskvs

An in-memory, embedded and eventually persisted key-value store in Go, for Go.
Go
7
star
25

.config

Vim Script
6
star
26

embed

Rewrites string or []byte variables with the content of files.
Go
5
star
27

gexf

GEXF format in Go.
Go
5
star
28

bomberweb

A websocket Bomberman player.
JavaScript
4
star
29

temple

Template rendering command line tool.
Go
4
star
30

hmachttp

Go
4
star
31

multisshtail

Tails a set of files over a set of hosts, over SSH.
Go
4
star
32

gostatic

Packs assets into a Go file.
Go
4
star
33

flatjson

Fast decoder for JSON. Maybe.
Go
3
star
34

proxyssh

proxyssh: proxy connections over ssh to multiple hosts
Go
3
star
35

smaz

Go
3
star
36

expviz

Visualize expvar data.
JavaScript
3
star
37

groscanot

CSS
3
star
38

broadcaster

Send events to multiple listeners!
Go
3
star
39

couverture

Automagically improve your test coverage !!!
Java
3
star
40

trie

Fast trie implementations.
Go
2
star
41

canlii

A client for the CanLII API
Go
2
star
42

crawler

Toy domain crawler
Go
2
star
43

oci

Go
2
star
44

fuzzy

Fuzzy search of strings.
Go
2
star
45

monitor

Quick and dirty HTTP monitoring tool
Go
2
star
46

semaphore

A shell tool to create counting semaphores, acquire them and release them.
Go
2
star
47

antoine.im

shitty blog
CSS
2
star
48

parajson

Decode streams of \n separated objects in parallel.
Go
1
star
49

bricklayer

iGem bricklayer API, a sane one
Go
1
star
50

hangcover

Shell
1
star
51

chicken-review

Go
1
star
52

opengl-demo-nbody

C
1
star
53

gossipchat

Go
1
star
54

blocks

Helper funcs to draw blocks on a terminal.
Go
1
star
55

tonnerre

Simple HTTP load testing tool
Go
1
star
56

jag

Verifies that two S3 buckets contain the same data.
Go
1
star
57

go-ipc

A clone of bitbucket.com/avd/go-ipc.
Go
1
star
58

citegraph

DB to some data extracted from CanLII, with an client implementation to access the CanLII API.
Go
1
star
59

epher

Go
1
star
60

otsql

Go
1
star
61

bombertcp

A TCP Bomberman player.
Go
1
star
62

newtonmethod

Newton's Method, finds roots.
Go
1
star
63

search

Learning about information retrieval.
Go
1
star
64

terraform-provider-cockroach

Terraform provider for Cockroach DB.
Go
1
star
65

sumjson

sumjson
Go
1
star
66

kicad-libs

1
star
67

ppgen

Go
1
star
68

eprop-re

eprop-re
Go
1
star
69

grpc-blob

Go
1
star