qf

package
v0.2.1 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: MIT Imports: 30 Imported by: 0

README

Benchmarks for quorum functions with and without the request object

The question we want to answer in this document is: Will Gorums be faster if we generate quorum functions without the request parameter, when the request is not needed by the quorum function?

Below are three runs of the benchmark for three variants of using the quorum function.

  • The UseReqQF method actually receive and use the request object passed to the quorum function. If your quorum function needs the request object, you anyway have to use this approach.
  • The IgnoreReqQF method has the same function signature as UseReqQF, but ignores the request object by using a _ in the implementation. This would be the recommended approach if we make the quorum function signature always require the request object.
  • The WithoutReqQF method has a function signature without the request object, and as such it should be the fastest, since it does not need to pass the request object on the stack at all.

All three benchmark methods has the same number of allocations, and so we exclude those details from the results below.

The conclusion from the benchmarks below is that UseReqQF is always slower, which is to be expected. However, from three runs of the benchmark on the same machine (a mid-2013 MacPro), it is not possible to observe any relevant difference between WithoutReqQF and IgnoreReqQF. In conclusion, it does not appear to be any value keeping the qf_with_req option.

Running the benchmarks

First compile the qf proto file.

cd cmd/protoc-gen-gorums/tests
make qf

To plot graphs based on the benchmarks, you will need benchgraph:

go get -v github.com/AntonioSun/benchgraph

To run the benchmarks:

cd qf
go test -bench=BenchmarkQF | benchgraph -title "Quorum Function Evaluation"
go test -bench=BenchmarkFullStackQF | benchgraph -title "Quorum Function Evaluation (full stack)"

To view plots for three separate runs:

Documentation

Index

Constants

View Source
const LevelNotSet = -1

LevelNotSet is the zero value level used to indicate that no level (and thereby no reply) has been set for a correctable quorum call.

Variables

View Source
var Error = func(n1, n2 *Node) bool {
	if n1.lastErr != nil && n2.lastErr == nil {
		return false
	}
	return true
}

Error sorts nodes by their LastErr() status in increasing order. A node with LastErr() != nil is larger than a node with LastErr() == nil.

View Source
var File_qf_qf_proto protoreflect.FileDescriptor
View Source
var ID = func(n1, n2 *Node) bool {
	return n1.id < n2.id
}

ID sorts nodes by their identifier in increasing order.

View Source
var Latency = func(n1, n2 *Node) bool {
	if n1.latency < 0 {
		return false
	}
	return n1.latency < n2.latency
}

Latency sorts nodes by latency in increasing order. Latencies less then zero (sentinel value) are considered greater than any positive latency.

View Source
var Port = func(n1, n2 *Node) bool {
	p1, _ := strconv.Atoi(n1.Port())
	p2, _ := strconv.Atoi(n2.Port())
	return p1 < p2
}

Port sorts nodes by their port number in increasing order. Warning: This function may be removed in the future.

Functions

func Equal

func Equal(a, b *Configuration) bool

Equal returns a boolean reporting whether a and b represents the same configuration.

func ManagerCreationError

func ManagerCreationError(err error) error

ManagerCreationError returns an error reporting that a Manager could not be created due to err.

func RegisterQuorumFunctionServer

func RegisterQuorumFunctionServer(s *grpc.Server, srv QuorumFunctionServer)

Types

type ConfigNotFoundError

type ConfigNotFoundError uint32

A ConfigNotFoundError reports that a specified configuration could not be found.

func (ConfigNotFoundError) Error

func (e ConfigNotFoundError) Error() string

type Configuration

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

A Configuration represents a static set of nodes on which quorum remote procedure calls may be invoked.

func NewConfig

func NewConfig(addrs []string, qspec QuorumSpec, opts ...ManagerOption) (*Configuration, func(), error)

NewConfig returns a configuration for the given node addresses and quorum spec. The returned func() must be called to close the underlying connections. This is experimental API.

func (*Configuration) ID

func (c *Configuration) ID() uint32

ID reports the identifier for the configuration.

func (*Configuration) IgnoreReq

func (c *Configuration) IgnoreReq(ctx context.Context, in *Request, opts ...grpc.CallOption) (resp *Response, err error)

IgnoreReq is a quorum call invoked on all nodes in configuration c, with the same argument in, and returns a combined result.

func (*Configuration) NodeIDs

func (c *Configuration) NodeIDs() []uint32

NodeIDs returns a slice containing the local ids of all the nodes in the configuration. IDs are returned in the same order as they were provided in the creation of the Configuration.

func (*Configuration) Nodes

func (c *Configuration) Nodes() []*Node

Nodes returns a slice of each available node. IDs are returned in the same order as they were provided in the creation of the Configuration.

func (*Configuration) Size

func (c *Configuration) Size() int

Size returns the number of nodes in the configuration.

func (*Configuration) String

func (c *Configuration) String() string

func (*Configuration) SubError

func (c *Configuration) SubError() <-chan GRPCError

SubError returns a channel for listening to individual node errors. Currently only a single listener is supported.

func (*Configuration) UseReq

func (c *Configuration) UseReq(ctx context.Context, in *Request, opts ...grpc.CallOption) (resp *Response, err error)

UseReq is a quorum call invoked on all nodes in configuration c, with the same argument in, and returns a combined result.

type GRPCError

type GRPCError struct {
	NodeID uint32
	Cause  error
}

GRPCError is used to report that a single gRPC call failed.

func (GRPCError) Error

func (e GRPCError) Error() string

type GorumsServer

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

GorumsServer serves all ordering based RPCs using registered handlers.

func NewGorumsServer

func NewGorumsServer(opts ...ServerOption) *GorumsServer

NewGorumsServer returns a new instance of GorumsServer.

func (*GorumsServer) GracefulStop

func (s *GorumsServer) GracefulStop()

GracefulStop waits for all RPCs to finish before stopping.

func (*GorumsServer) RegisterQuorumFunctionServer

func (s *GorumsServer) RegisterQuorumFunctionServer(srv QuorumFunction)

func (*GorumsServer) Serve

func (s *GorumsServer) Serve(listener net.Listener) error

Serve starts serving on the listener.

func (*GorumsServer) Stop

func (s *GorumsServer) Stop()

Stop stops the server immediately.

type IllegalConfigError

type IllegalConfigError string

An IllegalConfigError reports that a specified configuration could not be created.

func (IllegalConfigError) Error

func (e IllegalConfigError) Error() string

type Manager

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

Manager manages a pool of node configurations on which quorum remote procedure calls can be made.

func NewManager

func NewManager(nodeAddrs []string, opts ...ManagerOption) (*Manager, error)

NewManager attempts to connect to the given set of node addresses and if successful returns a new Manager containing connections to those nodes.

func (*Manager) AddNode

func (m *Manager) AddNode(addr string) error

AddNode attempts to dial to the provide node address. The node is added to the Manager's pool of nodes if a connection was established.

func (*Manager) Close

func (m *Manager) Close()

Close closes all node connections and any client streams.

func (*Manager) Configuration

func (m *Manager) Configuration(id uint32) (config *Configuration, found bool)

Configuration returns the configuration with the given global identifier if present.

func (*Manager) ConfigurationIDs

func (m *Manager) ConfigurationIDs() []uint32

ConfigurationIDs returns the identifier of each available configuration.

func (*Manager) Configurations

func (m *Manager) Configurations() []*Configuration

Configurations returns a slice of each available configuration.

func (*Manager) NewConfiguration

func (m *Manager) NewConfiguration(ids []uint32, qspec QuorumSpec) (*Configuration, error)

NewConfiguration returns a new configuration given quorum specification and a timeout.

func (*Manager) Node

func (m *Manager) Node(id uint32) (node *Node, found bool)

Node returns the node with the given identifier if present.

func (*Manager) NodeIDs

func (m *Manager) NodeIDs() []uint32

NodeIDs returns the identifier of each available node. IDs are returned in the same order as they were provided in the creation of the Manager.

func (*Manager) Nodes

func (m *Manager) Nodes() []*Node

Nodes returns a slice of each available node. IDs are returned in the same order as they were provided in the creation of the Manager.

func (*Manager) Size

func (m *Manager) Size() (nodes, configs int)

Size returns the number of nodes and configurations in the Manager.

type ManagerOption

type ManagerOption func(*managerOptions)

ManagerOption provides a way to set different options on a new Manager.

func WithBackoff

func WithBackoff(backoff backoff.Config) ManagerOption

WithBackoff allows for changing the backoff delays used by Gorums.

func WithDialTimeout

func WithDialTimeout(timeout time.Duration) ManagerOption

WithDialTimeout returns a ManagerOption which is used to set the dial context timeout to be used when initially connecting to each node in its pool.

func WithGrpcDialOptions

func WithGrpcDialOptions(opts ...grpc.DialOption) ManagerOption

WithGrpcDialOptions returns a ManagerOption which sets any gRPC dial options the Manager should use when initially connecting to each node in its pool.

func WithLogger

func WithLogger(logger *log.Logger) ManagerOption

WithLogger returns a ManagerOption which sets an optional error logger for the Manager.

func WithNoConnect

func WithNoConnect() ManagerOption

WithNoConnect returns a ManagerOption which instructs the Manager not to connect to any of its nodes. Mainly used for testing purposes.

func WithSendBufferSize

func WithSendBufferSize(size uint) ManagerOption

WithSendBufferSize allows for changing the size of the send buffer used by Gorums. A larger buffer might achieve higher throughput for asynchronous calltypes, but at the cost of latency.

func WithTracing

func WithTracing() ManagerOption

WithTracing controls whether to trace quorum calls for this Manager instance using the golang.org/x/net/trace package. Tracing is currently only supported for regular quorum calls.

type MultiSorter

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

MultiSorter implements the Sort interface, sorting the nodes within.

func OrderedBy

func OrderedBy(less ...lessFunc) *MultiSorter

OrderedBy returns a Sorter that sorts using the less functions, in order. Call its Sort method to sort the data.

func (*MultiSorter) Len

func (ms *MultiSorter) Len() int

Len is part of sort.Interface.

func (*MultiSorter) Less

func (ms *MultiSorter) Less(i, j int) bool

Less is part of sort.Interface. It is implemented by looping along the less functions until it finds a comparison that is either Less or !Less. Note that it can call the less functions twice per call. We could change the functions to return -1, 0, 1 and reduce the number of calls for greater efficiency: an exercise for the reader.

func (*MultiSorter) Sort

func (ms *MultiSorter) Sort(nodes []*Node)

Sort sorts the argument slice according to the less functions passed to OrderedBy.

func (*MultiSorter) Swap

func (ms *MultiSorter) Swap(i, j int)

Swap is part of sort.Interface.

type Node

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

Node encapsulates the state of a node on which a remote procedure call can be performed.

func (*Node) Address

func (n *Node) Address() string

Address returns network address of n.

func (*Node) FullString

func (n *Node) FullString() string

FullString returns a more descriptive string representation of n that includes id, network address and latency information.

func (*Node) ID

func (n *Node) ID() uint32

ID returns the ID of n.

func (*Node) IgnoreReq

func (n *Node) IgnoreReq(ctx context.Context, in *Request, replyChan chan<- internalResponse)

func (*Node) LastErr

func (n *Node) LastErr() error

LastErr returns the last error encountered (if any) when invoking a remote procedure call on this node.

func (*Node) Latency

func (n *Node) Latency() time.Duration

Latency returns the latency of the last successful remote procedure call made to this node.

func (*Node) Port

func (n *Node) Port() string

Port returns network port of n.

func (*Node) String

func (n *Node) String() string

func (*Node) UseReq

func (n *Node) UseReq(ctx context.Context, in *Request, replyChan chan<- internalResponse)

type NodeNotFoundError

type NodeNotFoundError uint32

A NodeNotFoundError reports that a specified node could not be found.

func (NodeNotFoundError) Error

func (e NodeNotFoundError) Error() string

type QuorumCallError

type QuorumCallError struct {
	Reason     string
	ReplyCount int
	Errors     []GRPCError
}

A QuorumCallError is used to report that a quorum call failed.

func (QuorumCallError) Error

func (e QuorumCallError) Error() string

type QuorumFunction

type QuorumFunction interface {
}

QuorumFunction is the server-side API for the QuorumFunction Service

type QuorumFunctionClient

type QuorumFunctionClient interface {
	UseReq(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
	IgnoreReq(ctx context.Context, in *Request, opts ...grpc.CallOption) (*Response, error)
}

QuorumFunctionClient is the client API for QuorumFunction service.

For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream.

type QuorumFunctionServer

type QuorumFunctionServer interface {
	UseReq(context.Context, *Request) (*Response, error)
	IgnoreReq(context.Context, *Request) (*Response, error)
	// contains filtered or unexported methods
}

QuorumFunctionServer is the server API for QuorumFunction service. All implementations must embed UnimplementedQuorumFunctionServer for forward compatibility

type QuorumSpec

type QuorumSpec interface {

	// UseReqQF is the quorum function for the UseReq
	// quorum call method. The in parameter is the request object
	// supplied to the UseReq method at call time, and may or may not
	// be used by the quorum function. If the in parameter is not needed
	// you should implement your quorum function with '_ *Request'.
	UseReqQF(in *Request, replies []*Response) (*Response, bool)

	// IgnoreReqQF is the quorum function for the IgnoreReq
	// quorum call method. The in parameter is the request object
	// supplied to the IgnoreReq method at call time, and may or may not
	// be used by the quorum function. If the in parameter is not needed
	// you should implement your quorum function with '_ *Request'.
	IgnoreReqQF(in *Request, replies []*Response) (*Response, bool)
}

QuorumSpec is the interface of quorum functions for QuorumFunction.

type Request

type Request struct {
	Value int64 `protobuf:"varint,1,opt,name=Value,proto3" json:"Value,omitempty"`
	// contains filtered or unexported fields
}

func (*Request) Descriptor deprecated

func (*Request) Descriptor() ([]byte, []int)

Deprecated: Use Request.ProtoReflect.Descriptor instead.

func (*Request) GetValue

func (x *Request) GetValue() int64

func (*Request) ProtoMessage

func (*Request) ProtoMessage()

func (*Request) ProtoReflect

func (x *Request) ProtoReflect() protoreflect.Message

func (*Request) Reset

func (x *Request) Reset()

func (*Request) String

func (x *Request) String() string

type Response

type Response struct {
	Result int64 `protobuf:"varint,1,opt,name=Result,proto3" json:"Result,omitempty"`
	// contains filtered or unexported fields
}

func (*Response) Descriptor deprecated

func (*Response) Descriptor() ([]byte, []int)

Deprecated: Use Response.ProtoReflect.Descriptor instead.

func (*Response) GetResult

func (x *Response) GetResult() int64

func (*Response) ProtoMessage

func (*Response) ProtoMessage()

func (*Response) ProtoReflect

func (x *Response) ProtoReflect() protoreflect.Message

func (*Response) Reset

func (x *Response) Reset()

func (*Response) String

func (x *Response) String() string

type ServerOption

type ServerOption func(*serverOptions)

ServerOption is used to change settings for the GorumsServer

func WithGRPCServerOptions

func WithGRPCServerOptions(opts ...grpc.ServerOption) ServerOption

func WithServerBufferSize

func WithServerBufferSize(size uint) ServerOption

WithServerBufferSize sets the buffer size for the server. A larger buffer may result in higher throughput at the cost of higher latency.

type UnimplementedQuorumFunctionServer

type UnimplementedQuorumFunctionServer struct {
}

UnimplementedQuorumFunctionServer must be embedded to have forward compatible implementations.

func (*UnimplementedQuorumFunctionServer) IgnoreReq

func (*UnimplementedQuorumFunctionServer) UseReq

Jump to

Keyboard shortcuts

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