A Go package for throttling application IO (such as bandwidth).
Go Shell
Latest commit 60e7e54 Nov 21, 2014 Evan Farrer Simplification of the unit tests.
Handle an error within createTcpPipe so it's callers don't have to handle it.
Permalink
Failed to load latest commit information.
bin Add a script for running the benchmarks. Apr 26, 2012
.gitignore
LICENSE Provide an explicit BSD 2 clause license. May 21, 2012
README.md Update Examples to have more meaningful output May 15, 2012
example_test.go go fmt Nov 20, 2014
iothrottler.go go fmt Nov 20, 2014
iothrottler_test.go Simplification of the unit tests. Nov 21, 2014

README.md

iothrottler

A Go package for throttling application IO (such as bandwidth).

Installation

If you have the Go Language installed type go get "github.com/efarrer/iothrottler"

Example

import (
    "bytes"
    "fmt"
    "io"
    "github.com/efarrer/iothrottler"
    "os"
)

// Basic usage of a IOThrottlerPool to throttle reading from a file 
func ExampleIOThrottlerPool() {
    // Construct a bandwidth throttling pool that's limited to 100 bytes per second
    pool := iothrottler.NewIOThrottlerPool(iothrottler.BytesPerSecond * 100)
    defer pool.ReleasePool()

    file, err := os.Open("/dev/zero")
    if err != nil {
        // handle error
        return
    }
    defer file.Close()

    throttledFile, err := pool.AddReader(file)
    if err != nil {
        // handle error
        return
    }

    var zeros bytes.Buffer

    copied, err := io.CopyN(&zeros, throttledFile, 200)
    if err != nil {
        // handle error
    }

    fmt.Printf("Copied %v bytes\n", copied)
    // Output: Copied 200 bytes
}