echo

package module
v0.0.0-...-7cd3629 Latest Latest
Warning

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

Go to latest
Published: Sep 6, 2017 License: MIT Imports: 15 Imported by: 0

README

gRPC Service Template

This package is a template for designing gRPC services.

Quickstart

Install the server/client system using go get as follows:

$ go get github.com/bbengfort/echo

You should then have the echo command installed on your system:

$ echo --help

You can run the server as follows:

$ echo serve

And send messages from the client as:

$ echo send "hello world"

Note the various arguments you can pass to both serve and send to configure the setup. Run benchmarks with the bench command:

$ echo bench

The primary comparison is between gRPC and ZMQ — the ZMQ code can be found at github.com/bbengfort/rtreq.

Documentation

Index

Constants

View Source
const (
	Trace uint8 = iota
	Debug
	Info
	Status
	Warn
	Silent
)

Levels for implementing the debug and trace message functionality.

Variables

View Source
var (
	ErrNotImplemented = errors.New("functionality not implemented yet")
)

Standard errors for primary operations.

Functions

func LogLevel

func LogLevel() string

LogLevel returns a string representation of the current level

func SetLogLevel

func SetLogLevel(level uint8)

SetLogLevel modifies the log level for messages at runtime. Ensures that the highest level that can be set is the trace level.

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

func NewClient

func NewClient(addr, name string) (*Client, error)

func (*Client) Access

func (c *Client) Access(done chan<- bool, echan chan<- error)

Access sends a request to the server and waits for a response, measuring the latency of the message send to get throughput benchmarks.

func (*Client) Benchmark

func (c *Client) Benchmark(duration time.Duration, results string, nClients int) error

Benchmark the throughput in terms of messages per second to the zmqnet.

func (*Client) Close

func (c *Client) Close() (err error)

func (*Client) Connect

func (c *Client) Connect(timeout time.Duration) (err error)

func (*Client) Init

func (c *Client) Init(addr, name string)

func (*Client) Results

func (c *Client) Results(path string, data map[string]interface{}) error

Results saves the throughput to disk

func (*Client) Send

func (c *Client) Send(msg string) error

func (*Client) Shutdown

func (c *Client) Shutdown() error

type Error

type Error struct {
	// contains filtered or unexported fields
}

Error wraps other library errors and provides easier logging.

func WrapError

func WrapError(format string, err error, a ...interface{}) *Error

WrapError creates a new wrapped error message with the format string.

func (*Error) Error

func (e *Error) Error() string

Error prefixes the message to the internal error string

func (*Error) String

func (e *Error) String() string

String returns the error message

type Metrics

type Metrics struct {
	sync.RWMutex
	// contains filtered or unexported fields
}

Metrics tracks the measurable statistics of the system over time from the perspective of the local replica. Many stats are simply counters, other statistics perform online computations of the distribution of values.

func (*Metrics) Accesses

func (m *Metrics) Accesses() uint64

Accesses returns the total number of accesses to the replica.

func (*Metrics) Append

func (m *Metrics) Append(o *Metrics)

Append another metrics' data to the current metrics

func (*Metrics) ClientMean

func (m *Metrics) ClientMean() float64

ClientMean returns the average number of accesses per client.

func (*Metrics) Complete

func (m *Metrics) Complete()

Complete an access and set the finished time.

func (*Metrics) Duration

func (m *Metrics) Duration() time.Duration

Duration computes the amount of time during which accesses were received.

func (*Metrics) Increment

func (m *Metrics) Increment(client string)

Increment the access metrics and set the started time.

func (*Metrics) Init

func (m *Metrics) Init()

Init the metrics

func (*Metrics) NClients

func (m *Metrics) NClients() uint64

NClients returns the number of clients accessing the replica

func (*Metrics) Serialize

func (m *Metrics) Serialize(extra map[string]interface{}) map[string]interface{}

Serialize the data structure to a map

func (*Metrics) String

func (m *Metrics) String() string

String returns a quick summary of the access metrics

func (*Metrics) Throughput

func (m *Metrics) Throughput() (throughput float64)

Throughput computes the number of messages per second.

func (*Metrics) Write

func (m *Metrics) Write(path string, extra map[string]interface{}) error

Write the metrics to the path, appending the JSON as a line to the file.

type Server

type Server struct {
	// contains filtered or unexported fields
}

func NewServer

func NewServer(addr, name string) (*Server, error)

func (*Server) Init

func (s *Server) Init(addr, name string)

func (*Server) Respond

func (s *Server) Respond(ctx context.Context, in *pb.BasicMessage) (*pb.BasicMessage, error)

Respond implements the echo.HelloServer interface.

func (*Server) Run

func (s *Server) Run() error

func (*Server) Shutdown

func (s *Server) Shutdown(path string) error

Directories

Path Synopsis
cmd
echgo command
Package msg is a generated protocol buffer package.
Package msg is a generated protocol buffer package.

Jump to

Keyboard shortcuts

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