Documentation
¶
Index ¶
- Constants
- Variables
- func AcquireResponse() *response
- func ReleaseResponse(resp *response)
- type Client
- func (c *Client) Call(Operation string, args, reply interface{}) (err error)
- func (c *Client) DoContext(ctx context.Context, req requestWriter, resp responseReader) error
- func (c *Client) DoDeadline(req requestWriter, resp responseReader, deadline time.Time) error
- func (c *Client) PendingRequests() int
- func (c *Client) SendNowait(req requestWriter, releaseReq func(req requestWriter)) bool
- type ClientOption
- type CompressType
- type Context
- type Exposable
- type Handler
- type HandlerFunc
- type Message
- type OperationInfo
- type OperationTypes
- type Server
- type ServerOption
- type TypeMaker
Constants ¶
const ( // CompressNone disables connection compression. // // CompressNone may be used in the following cases: // // * If network bandwidth between client and server is unlimited. // * If client and server are located on the same physical host. // * If other CompressType values consume a lot of CPU resources. // CompressNone = CompressType(1) // CompressFlate uses compress/flate with default // compression level for connection compression. // // CompressFlate may be used in the following cases: // // * If network bandwidth between client and server is limited. // * If client and server are located on distinct physical hosts. // * If both client and server have enough CPU resources // for compression processing. // CompressFlate = CompressType(0) // CompressSnappy uses snappy compression. // // CompressSnappy vs CompressFlate comparison: // // * CompressSnappy consumes less CPU resources. // * CompressSnappy consumes more network bandwidth. // CompressSnappy = CompressType(2) )
const MaxBytesSize = 16 << 20
Variables ¶
var ( // ErrTimeout is returned from timed out calls. ErrTimeout = errors.New("timeout") // ErrPendingRequestsOverflow is returned when Client cannot send // more requests to the server due to Client.MaxPendingRequests limit. ErrPendingRequestsOverflow = errors.New("Pending requests overflow. Increase Client.MaxPendingRequests, " + "reduce requests rate or speed up the server") )
Functions ¶
func ReleaseResponse ¶
func ReleaseResponse(resp *response)
ReleaseResponse releases the given response.
Types ¶
type Client ¶
type Client struct { // SniffHeader is the header written to each connection established // to the server. // // It is expected that the server replies with the same header. SniffHeader string // ProtocolVersion is the version of requestWriter and responseReader. // todo remove // The ProtocLolVersion must be changed each time requestWriter // or responseReader changes the underlying format. ProtocolVersion byte // NewResponse must return new response object. NewResponse func() responseReader // Addr is the Server address to connect to. Addr string // contains filtered or unexported fields }
Client sends rpc requests to the Server over a single connection.
Use multiple clients for establishing multiple connections to the server if a single connection processing consumes 100% of a single CPU core on either multi-core client or server.
func NewClient ¶
func NewClient(addr string, opts ...ClientOption) (c *Client)
func (*Client) DoContext ¶
DoDeadline sends the given request to the server set in Client.Addr.
ErrTimeout is returned if the server didn't return response until the given deadline.
func (*Client) DoDeadline ¶
DoDeadline sends the given request to the server set in Client.Addr.
ErrTimeout is returned if the server didn't return response until the given deadline.
func (*Client) PendingRequests ¶
PendingRequests returns the number of pending requests at the moment.
This function may be used either for informational purposes or for load balancing purposes.
func (*Client) SendNowait ¶
SendNowait schedules the given request for sending to the server set in Client.Addr.
req cannot be used after SendNowait returns and until releaseReq is called. releaseReq is called when the req is no longer needed and may be re-used.
req cannot be re-used if releaseReq is nil.
Returns true if the request is successfully scheduled for sending, otherwise returns false.
response for the given request is ignored.
type ClientOption ¶
type ClientOption func(c *clientOptions)
ClientOption set Dialer client option
func ClientCodec ¶
func ClientCodec(co string) ClientOption
ClientCodec Specifies the client codec used to marshal / unmarshal messages
func ClientCompression ¶
func ClientCompression(compression CompressType) ClientOption
ClientCompression set the client compression type
func ClientDialer ¶
func ClientDialer(dialer func(string) (net.Conn, error)) ClientOption
ClientDialer Specifies the dialer to use when establishing new connection
func ClientTLSConfig ¶
func ClientTLSConfig(tc *tls.Config) ClientOption
TLSConfig is TLS (aka SSL) config used for establishing encrypted connection to the server.
Encrypted connections may be used for transferring sensitive information over untrusted networks.
By default connection to the server isn't encrypted.
func PipelineRequests ¶
func PipelineRequests(b bool) ClientOption
PipelineRequests enables requests' pipelining.
Requests from a single client are processed serially if is set to true.
Enabling requests' pipelining may be useful in the following cases:
- if requests from a single client must be processed serially;
- if the Server.Handler doesn't block and maximum throughput must be achieved for requests' processing.
By default requests from a single client are processed concurrently.
type Exposable ¶
type Exposable interface { //ExposedOperations return a list of operations ExposedOperations() []OperationInfo }
Exposable interface autoregister services Operations
type HandlerFunc ¶
The HandlerFunc type is an adapter to allow the use of ordinary functions as exposed RPC handlers.
func (HandlerFunc) ServeExposed ¶
func (h HandlerFunc) ServeExposed(ctx *Context, req Message, resp Message) (err error)
type OperationInfo ¶
type OperationInfo struct { Operation string Handler HandlerFunc OperationTypes *OperationTypes }
type OperationTypes ¶
type Server ¶
type Server struct { // SniffHeader is the header read from each client connection. // // The server sends the same header to each client. SniffHeader string // ProtocolVersion is the version of *exposedCtx.ReadRequest // and *exposedCtx.WriteResponse. // // The ProtocolVersion must be changed each time *exposedCtx.ReadRequest // or *exposedCtx.WriteResponse changes the underlying format. ProtocolVersion byte // NewHandlerCtx must return new *exposedCtx NewHandlerCtx func() *exposedCtx // Handler must process incoming requests. // // The handler must return either ctx passed to the call // or new non-nil ctx. // // The handler may return ctx passed to the call only if the ctx // is no longer used after returning from the handler. // Otherwise new ctx must be returned. Handler func(ctx *exposedCtx) *exposedCtx // Logger, which is used by the Server. // // Standard logger from log package is used by default. Logger *zerolog.Logger // contains filtered or unexported fields }
Server accepts rpc requests from Client.
func NewServer ¶
func NewServer(opts ...ServerOption) *Server
NewServer creates a exposed server with the provided server options which has no service registered and has not started to accept requests yet.
func (*Server) HandleFunc ¶
func (s *Server) HandleFunc(path string, handlerFunc HandlerFunc, info *OperationTypes)
func (*Server) RegisterService ¶
type ServerOption ¶
type ServerOption func(*serverOptions)
A ServerOption sets options such as codec, compress type, etc.
func ServerCodec ¶
func ServerCodec(co string) ServerOption
ServerCodec specifies the encoding codec to be used to marshal/unmarshal messages its possible to achieve zero copy with carefully written codecs
func ServerCompression ¶
func ServerCompression(sc CompressType) ServerOption
ServerCompression sets the compression type used by the transport
func ServerMaxBatchDelay ¶
func ServerMaxBatchDelay(d time.Duration) ServerOption
MaxBatchDelay is the maximum duration before ready responses are sent to the client.
Responses' batching may reduce network bandwidth usage and CPU usage.
By default responses are sent immediately to the client.
func ServerMaxConcurrency ¶
func ServerMaxConcurrency(maxConcurrency uint32) ServerOption
ServerCompression sets the maximum number of concurrent requests before server return error
func ServerTlsConfig ¶
func ServerTlsConfig(tlsc *tls.Config) ServerOption
ServerCompression sets the compression type used by the transport
Source Files
¶
Directories
¶
Path | Synopsis |
---|---|
examples
|
|
echo/echoservice
Package echoservice is a generated protocol buffer package.
|
Package echoservice is a generated protocol buffer package. |