Giter VIP home page Giter VIP logo

iocontrol's Introduction

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)

iocontrol's People

Contributors

aybabtme avatar khayyamsaleem avatar nickvanw avatar vnegi-digitalocean avatar

Stargazers

Andrei Gonchar avatar Justin Vieira avatar Mauro Risonho de Paula Assumpção avatar Dale Dude avatar  avatar David Manouchehri avatar  avatar YuZou avatar Christian Stewart avatar  avatar Michael Rykov avatar montag451 avatar Gus Eggert avatar Jatin Jindal avatar Wayne Zhou avatar Tony Chen avatar Hai-Hsin avatar tomwei7 avatar DCjanus avatar liangkai avatar Nestor Wheelock avatar SM avatar Aagat Adhikari avatar YiSuo avatar Atul Bhosale avatar Alex Soveliev avatar  avatar Yonder Blue avatar Yuxuan avatar Gustavo Hoirisch avatar  avatar Indrajith Bandara avatar  avatar  avatar luwei avatar GAURAV avatar David Danziger avatar lgwei avatar Dmytro Chornyi avatar Coder Monkey avatar Pavel T  avatar Terry avatar Seki Rocc avatar Sergey Mezentsev avatar Tom Thorogood avatar Val Packett avatar  avatar  avatar Davide Berdin avatar QuantumGhost avatar kevin avatar Rajeeva Lochan Musunuri avatar C.J. Winslow avatar Denis Denisov avatar Chris Watson avatar Blain Smith avatar Tom Reznik avatar Michael Barrett avatar Thomas Hopkins avatar Rob Warner avatar Martin H avatar Radu Topala avatar swh avatar Theofanis Despoudis avatar  avatar Rajiv Kilaparti avatar Denis Tokarev avatar  avatar  avatar Bogdan U avatar Zhipeng Jiang avatar JaredYeah avatar Gabor Dolla avatar Vishal Isharani avatar Xiaohan Song avatar Oleg avatar Aaron Eikenberry avatar Yijun Zhao avatar Oleg Lebedev avatar  avatar Shiwei Wang avatar ##-- avatar AnyISalIn avatar Marco Lüthy avatar Kevin Birk avatar Rodrigo Oler avatar Maythee Anegboonlap avatar Erich Smith avatar Kollan House avatar George Jiglau avatar Andre Cerqueira avatar TJ Holowaychuk avatar Garrett Johnson avatar Gurpartap Singh avatar Clement Rey avatar Fotis Nikolaidis avatar David Odohi avatar Darwin Smith avatar Nikita Galushko avatar jet tsang zeon-git avatar

Watchers

mayulu avatar Vasiliy Tolstov avatar Stakhiv avatar James Cloos avatar goroutine avatar Justin Hines avatar Mac Browning avatar  avatar  avatar

iocontrol's Issues

Create measured versions of io.ReaderAt and io.WriterAt

The package currently covers io.Reader and io.Writer only.

io.ReaderAt and io.WriterAt are useful for sparse read/write use-cases, and the instrumented versions of these would be helpful for sparse/concurrent (non-streaming) reads and writes.

Add OSS license

It would be nice to add a friendly OSS license (BSD/MIT/ASL?) so folks can evaluate whether they're comfortable using this in their projects.

make RateCounter public

Not sure if RateCounter (and limiter, for that matter) should be exposed as a separate module, but they're compact and useful! If they were exposed outside this package, people can leverage these utilities for arbitrary Reader/Writer implementations

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.