mio

package module
v0.0.0-...-67f0e6d Latest Latest
Warning

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

Go to latest
Published: Aug 21, 2017 License: MIT Imports: 3 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

mio (aka metered IO)

Package mio provides tools to combine io.Reader/io.Writer and metrics.Histogram interfaces, so that every non-empty Read or Write call latency value is sampled to Histogram.

See documentation on godoc.org.

This package is intended to be used with metrics package.

Documentation

Overview

Package mio provides tools to combine io.Writer and metrics.Histogram interfaces, so that every non-empty Write call latency value is sampled to Histogram.

Writer and Reader can be used to bind standard metrics.Histogram to io.Writer and io.Reader. SelfCleaningHistogram provides a wrapper over metrics.Histogram with self-cleaning capabilities, which can be used for sharing one Histogram over multiple writers/readers and cleaning sample pool after period of inactivity.

This package is intended to be used with go-metrics: (https://github.com/rcrowley/go-metrics) or metrics (https://github.com/facebookgo/metrics) packages.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Histogram

type Histogram interface {
	Clear()
	Count() int64
	Max() int64
	Mean() float64
	Min() int64
	Percentile(float64) float64
	Percentiles([]float64) []float64
	StdDev() float64
	Update(int64)
	Variance() float64
}

Histogram interface wraps a subset of methods of metrics.Histogram interface so it can be used without type conversion.

type Reader

type Reader struct {
	io.Reader
	// contains filtered or unexported fields
}

Reader wraps io.Reader and registers each read operation latency in attached histogram

func NewReader

func NewReader(reader io.Reader, h Histogram) *Reader

NewReader attaches provided histogram to reader, returning new io.Reader. If histogram implements Registrar interface, this would also call its Register() method.

func (*Reader) Close

func (mr *Reader) Close() error

Close implements io.Closer interface. If underlying reader implements io.Closer, calling this method would also close it. If attached histogram also implements Registrar interface, this would call its Done() method.

func (*Reader) Read

func (mr *Reader) Read(p []byte) (n int, err error)

Read implements io.Reader interface; each read operation is timed and sampled in attached histogram. Samples are stored in nanoseconds.

type Registrar

type Registrar interface {
	Register()
	Done()
	Shutdown()
}

Registrar interface can be used to track object's concurrent usage.

Its Register method announces goroutine's intent to use this object's facilities; Done method should be called when goroutine finished working with this object. Shutdown method stops associated background goroutines so that resources can be garbage collected.

These methods provide a similar semantics as sync.WaitGroup's Add(1), and Done() methods.

type SelfCleaningHistogram

type SelfCleaningHistogram struct {
	Histogram
	// contains filtered or unexported fields
}

SelfCleaningHistogram wraps metrics.Histogram, adding self-cleaning feature if no samples were registered for a specified time. SelfCleaningHistogram also implements Registrar interface, call Register() method to announce following sample updates, call Done() after all samples were added. If no outstanding workers registered (for each Register() call Done() call were made), self-cleaning timer would start, cleaning histogram's sample pool in absence of Register() calls before timer fires.

func NewSelfCleaningHistogram

func NewSelfCleaningHistogram(histogram Histogram, delay time.Duration) *SelfCleaningHistogram

NewSelfCleaningHistogram returns SelfCleaningHistogram wrapping specified histogram; its self-cleaning period set to delay.

func (*SelfCleaningHistogram) Done

func (h *SelfCleaningHistogram) Done()

Done implements Registrar interface, using sync.WaitGroup.Done() for each call.

func (*SelfCleaningHistogram) Register

func (h *SelfCleaningHistogram) Register()

Register implements Registrar interface, using sync.WaitGroup.Add(1) for each call, blocking self-cleaning timer until all object's users releases it with Done() call.

func (*SelfCleaningHistogram) Shutdown

func (h *SelfCleaningHistogram) Shutdown()

Shutdown implements Registrar interface, it stops background goroutine. This method should be called as the very last method on object and needed only if object has to be removed and garbage collected.

type Writer

type Writer struct {
	io.Writer
	// contains filtered or unexported fields
}

Writer wraps io.Writer and registers each write operation latency in attached histogram

func NewWriter

func NewWriter(writer io.Writer, h Histogram) *Writer

NewWriter attaches provided histogram to writer, returning new io.Writer. If histogram implements Registrar interface, this would also call its Register() method.

func (*Writer) Close

func (mw *Writer) Close() error

Close implements io.Closer interface. If underlying writer implements io.Closer, calling this method would also close it. If attached histogram also implements Registrar interface, this would call its Done() method.

func (*Writer) Write

func (mw *Writer) Write(p []byte) (n int, err error)

Write implements io.Writer interface; each write operation is timed and sampled in attached histogram. Samples are stored in nanoseconds.

Jump to

Keyboard shortcuts

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