grpc: google.golang.org/grpc/benchmark/latency Index | Files

package latency

import "google.golang.org/grpc/benchmark/latency"

Package latency provides wrappers for net.Conn, net.Listener, and net.Dialers, designed to interoperate to inject real-world latency into network connections.

Index

Package Files

latency.go

Variables

var (
    //Local simulates local network.
    Local = Network{0, 0, 0}
    //LAN simulates local area network network.
    LAN = Network{100 * 1024, 2 * time.Millisecond, 1500}
    //WAN simulates wide area network.
    WAN = Network{20 * 1024, 30 * time.Millisecond, 1500}
    //Longhaul simulates bad network.
    Longhaul = Network{1000 * 1024, 200 * time.Millisecond, 9000}
)

type ContextDialer Uses

type ContextDialer func(ctx context.Context, network, address string) (net.Conn, error)

ContextDialer is a function matching the signature of net.Dialer.DialContext.

type Dialer Uses

type Dialer func(network, address string) (net.Conn, error)

Dialer is a function matching the signature of net.Dial.

type Network Uses

type Network struct {
    Kbps    int           // Kilobits per second; if non-positive, infinite
    Latency time.Duration // One-way latency (sending); if non-positive, no delay
    MTU     int           // Bytes per packet; if non-positive, infinite
}

Network represents a network with the given bandwidth, latency, and MTU (Maximum Transmission Unit) configuration, and can produce wrappers of net.Listeners, net.Conn, and various forms of dialing functions. The Listeners and Dialers/Conns on both sides of connections must come from this package, but need not be created from the same Network. Latency is computed when sending (in Write), and is injected when receiving (in Read). This allows senders' Write calls to be non-blocking, as in real-world applications.

Note: Latency is injected by the sender specifying the absolute time data should be available, and the reader delaying until that time arrives to provide the data. This package attempts to counter-act the effects of clock drift and existing network latency by measuring the delay between the sender's transmission time and the receiver's reception time during startup. No attempt is made to measure the existing bandwidth of the connection.

func (*Network) Conn Uses

func (n *Network) Conn(c net.Conn) (net.Conn, error)

Conn returns a net.Conn that wraps c and injects n's latency into that connection. This function also imposes latency for connection creation. If n's Latency is lower than the measured latency in c, an error is returned.

func (*Network) ContextDialer Uses

func (n *Network) ContextDialer(d ContextDialer) ContextDialer

ContextDialer returns a ContextDialer that wraps d and injects n's latency in its connections. n's Latency is also injected to the connection's creation.

func (*Network) Dialer Uses

func (n *Network) Dialer(d Dialer) Dialer

Dialer returns a Dialer that wraps d and injects n's latency in its connections. n's Latency is also injected to the connection's creation.

func (*Network) Listener Uses

func (n *Network) Listener(l net.Listener) net.Listener

Listener returns a net.Listener that wraps l and injects n's latency in its connections.

func (*Network) TimeoutDialer Uses

func (n *Network) TimeoutDialer(d TimeoutDialer) TimeoutDialer

TimeoutDialer returns a TimeoutDialer that wraps d and injects n's latency in its connections. n's Latency is also injected to the connection's creation.

type TimeoutDialer Uses

type TimeoutDialer func(network, address string, timeout time.Duration) (net.Conn, error)

TimeoutDialer is a function matching the signature of net.DialTimeout.

Package latency imports 7 packages (graph) and is imported by 10 packages. Updated 2018-11-12. Refresh now. Tools for package owners.