Movatterモバイル変換


[0]ホーム

URL:


drpc

packagemodule
v0.0.34Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2024 License:MITImports:3Imported by:129

Details

Repository

github.com/storj/drpc

Links

README

DRPC

A drop-in, lightweight gRPC replacement.

Go Report CardGo DocBetaZulip Chat

Links

Highlights

  • Simple, at just a few thousandlines of code.
  • Small dependencies. Only 3 requirements in go.mod, and 9 lines ofgo mod graph!
  • Compatible. Works for many gRPC use-cases as-is!
  • Fast. DRPC has a lightning quickwire format.
  • Extensible. DRPC is transport agnostic, supports middleware, and is designed around interfaces.
  • Battle Tested. Already used in production for years across tens of thousands of servers.

External Packages

  • go.bryk.io/pkg/net/drpc

    • Simplified TLS setup (for client and server)
    • Server middleware, including basic components for logging, token-based auth, rate limit, panic recovery, etc
    • Client middleware, including basic components for logging, custom metadata, panic recovery, etc
    • Bi-directional streaming support over upgraded HTTP(S) connections using WebSockets
    • Concurrent RPCs via connection pool
  • go.elara.ws/drpc

    • Concurrent RPCs based onyamux
    • Simple drop-in replacements fordrpcserver anddrpcconn
  • Open an issue or join theZulip chat if you'd like to be featured here.

Examples

Other Languages

DRPC can be made compatible with RPC clients generated from other languages. For example,Twirp clients andgrpc-web clients can be used against thedrpchttp package.

Native implementations can have some advantages, and so some support for other languages are in progress, all in various states of completeness. Join theZulip chat if you want more information or to help out with any!

LanguageRepositoryStatus
C++https://github.com/storj/drpc-cppIncomplete
Rusthttps://github.com/zeebo/drpc-rsIncomplete
Nodehttps://github.com/mjpitz/drpc-nodeIncomplete

Licensing

DRPC is licensed under the MIT/expat license. See the LICENSE file for more.


Benchmarks

These microbenchmarks attempt to provide a comparison and come with some caveats. First, it does not send data over a network connection which is expected to be the bottleneck almost all of the time. Second, no attempt was made to do the benchmarks in a controlled environment (CPU scaling disabled, noiseless, etc.). Third, no tuning was done to ensure they're both performing optimally, so there is an inherent advantage for DRPC because the author is familiar with how it works.

MeasureBenchmarkSmallMediumLarge
gRPCDRPCdeltagRPCDRPCdeltagRPCDRPCdelta
time/opUnitary24.5µs6.1µs-74.87%32.4µs8.8µs-72.89%1.43ms0.58ms-59.47%
Input Stream745ns528ns-29.13%2.63µs1.46µs-44.66%512µs236µs-53.89%
Output Stream711ns532ns-25.11%2.63µs1.51µs-42.59%515µs210µs-59.26%
Bidir Stream7.29µs2.52µs-65.46%12.3µs3.9µs-68.68%1.44ms0.44ms-69.05%
speedUnitary80.0kB/s325.0kB/s+306.25%63.4MB/s234.3MB/s+269.56%734MB/s1812MB/s+146.99%
Input Stream2.69MB/s3.79MB/s+41.00%780MB/s1409MB/s+80.67%2.05GB/s4.45GB/s+117.12%
Output Stream2.81MB/s3.76MB/s+33.52%780MB/s1360MB/s+74.23%2.04GB/s5.01GB/s+145.53%
Bidir Stream274kB/s794kB/s+189.95%166MB/s533MB/s+220.19%730MB/s2360MB/s+223.10%
mem/opUnitary8.66kB1.42kB-83.62%22.2kB7.8kB-64.83%6.61MB3.16MB-52.21%
Input Stream381B80B-79.01%7.08kB2.13kB-69.95%3.20MB1.05MB-67.17%
Output Stream305B80B-73.80%7.00kB2.13kB-69.62%3.20MB1.05MB-67.19%
Bidir Stream1.00kB0.24kB-75.90%14.5kB4.3kB-70.10%6.61MB2.10MB-68.20%
allocs/opUnitary1687-95.83%1709-94.71%4009-97.75%
Input Stream91-88.89%102-80.00%1182-98.31%
Output Stream91-88.89%102-80.00%1202-98.33%
Bidir Stream393-92.31%425-88.10%2775-98.20%

Lines of code

DRPC is proud to get as much done in as few lines of code as possible. It's the author's belief that this is only possible by having a clean, strong architecture and that it reduces the chances for bugs to exist (most studies show a linear corellation with number of bugs and lines of code). This table helps keep the library honest, and it would be nice if more libraries considered this.

PackageLines
storj.io/drpc/drpchttp478
storj.io/drpc/drpcstream470
storj.io/drpc/cmd/protoc-gen-go-drpc424
storj.io/drpc/drpcmanager374
storj.io/drpc/drpcwire362
storj.io/drpc/drpcpool276
storj.io/drpc/drpcmigrate239
storj.io/drpc/drpcserver161
storj.io/drpc/drpcsignal133
storj.io/drpc/drpcconn116
storj.io/drpc/drpcmetadata115
storj.io/drpc/drpcmux95
storj.io/drpc/drpccache54
storj.io/drpc47
storj.io/drpc/drpctest45
storj.io/drpc/drpcerr42
storj.io/drpc/drpcctx41
storj.io/drpc/internal/drpcopts27
storj.io/drpc/drpcstats25
storj.io/drpc/drpcdebug22
storj.io/drpc/drpcenc15
Total3561

Documentation

Overview

Package drpc is a light replacement for gprc.

Index

Constants

This section is empty.

Variables

View Source
var (Error         =errs.Class("drpc")InternalError =errs.Class("internal error")ProtocolError =errs.Class("protocol error")ClosedError   =errs.Class("closed"))

These error classes represent some common errors that drpc generates.

Functions

This section is empty.

Types

typeConn

type Conn interface {// Close closes the connection.Close()error// Closed returns a channel that is closed if the connection is definitely closed.Closed() <-chan struct{}// Invoke issues a unary RPC to the remote. Only one Invoke or Stream may be// open at once.Invoke(ctxcontext.Context, rpcstring, encEncoding, in, outMessage)error// NewStream starts a stream with the remote. Only one Invoke or Stream may be// open at once.NewStream(ctxcontext.Context, rpcstring, encEncoding) (Stream,error)}

Conn represents a client connection to a server.

typeDescription

type Description interface {// NumMethods returns the number of methods available.NumMethods()int// Method returns the information about the nth method along with a handler// to invoke it. The method interface that it returns is expected to be// a method expression like `(*Type).HandlerName`.Method(nint) (rpcstring, encodingEncoding, receiverReceiver, method interface{}, okbool)}

Description is the interface implemented by things that can be registered bya Server.

typeEncodingadded inv0.0.18

type Encoding interface {// Marshal returns the encoded form of msg.Marshal(msgMessage) ([]byte,error)// Unmarshal reads the encoded form of some Message into msg.// The buf is expected to contain only a single complete Message.Unmarshal(buf []byte, msgMessage)error}

Encoding represents a way to marshal/unmarshal Message types.

typeHandler

type Handler interface {// HandleRPC executes the RPC identified by the rpc string using the stream to// communicate with the remote.HandleRPC(streamStream, rpcstring) (errerror)}

Handler handles streams and RPCs dispatched to it by a Server.

typeMessage

type Message interface{}

Message is a protobuf message. It is expected to be used with an Encoding.This exists so that one can use whatever protobuf library/runtime they want.

typeMuxadded inv0.0.10

type Mux interface {// Register marks that the description should dispatch RPCs that it describes to// the provided srv.Register(srv interface{}, descDescription)error}

Mux is a type that can have an implementation and a Description registered with it.

typeReceiveradded inv0.0.10

type Receiver = func(srv interface{}, ctxcontext.Context, in1, in2 interface{}) (outMessage, errerror)

Receiver is invoked by a server for a given RPC.

typeStream

type Stream interface {// Context returns the context associated with the stream. It is canceled// when the Stream is closed and no more messages will ever be sent or// received on it.Context()context.Context// MsgSend sends the Message to the remote.MsgSend(msgMessage, encEncoding)error// MsgRecv receives a Message from the remote.MsgRecv(msgMessage, encEncoding)error// CloseSend signals to the remote that we will no longer send any messages.CloseSend()error// Close closes the stream.Close()error}

Stream is a bi-directional stream of messages to some other party.

typeTransport

type Transport interface {io.Readerio.Writerio.Closer}

Transport is an interface describing what is required for a drpc connection.Any net.Conn can be used as a Transport.

Source Files

View all Source files

Directories

PathSynopsis
cmd
protoc-gen-go-drpccommand
protoc-gen-go-drpc generates DRPC code for protobuf services.
protoc-gen-go-drpc generates DRPC code for protobuf services.
Package drpccache implements per stream cache for drpc.
Package drpccache implements per stream cache for drpc.
Package drpcconn creates a drpc client connection from a transport.
Package drpcconn creates a drpc client connection from a transport.
Package drpcctx has helpers to interact with context.Context.
Package drpcctx has helpers to interact with context.Context.
Package drpcdebug provides helpers for debugging.
Package drpcdebug provides helpers for debugging.
Package drpcenc holds some helper functions for encoding messages.
Package drpcenc holds some helper functions for encoding messages.
Package drpcerr lets one associate error codes with errors.
Package drpcerr lets one associate error codes with errors.
Package drpchttp implements a net/http handler for unitary RPCs.
Package drpchttp implements a net/http handler for unitary RPCs.
Package drpcmanager reads packets from a transport to make streams.
Package drpcmanager reads packets from a transport to make streams.
Package drpcmetadata define the structure of the metadata supported by drpc library.
Package drpcmetadata define the structure of the metadata supported by drpc library.
Package drpcmigrate provides tools to support drpc concurrently alongside gRPC on the same ports.
Package drpcmigrate provides tools to support drpc concurrently alongside gRPC on the same ports.
Package drpcmux is a handler to dispatch rpcs to implementations.
Package drpcmux is a handler to dispatch rpcs to implementations.
Package drpcpool is a simple connection pool for clients.
Package drpcpool is a simple connection pool for clients.
Package drpcserver allows one to execute registered rpcs.
Package drpcserver allows one to execute registered rpcs.
Package drpcsignal holds a helper type to signal errors.
Package drpcsignal holds a helper type to signal errors.
Package drpcstats contatins types for stat collection.
Package drpcstats contatins types for stat collection.
Package drpcstream sends protobufs using the dprc wire protocol.
Package drpcstream sends protobufs using the dprc wire protocol.
Package drpctest provides test related helpers.
Package drpctest provides test related helpers.
Package drpcwire provides low level helpers for the drpc wire protocol.
Package drpcwire provides low level helpers for the drpc wire protocol.
examples
drpcmodule
grpcmodule
internal
drpcopts
Package drpcopts contains internal options.
Package drpcopts contains internal options.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f orF : Jump to
y orY : Canonical URL
go.dev uses cookies from Google to deliver and enhance the quality of its services and to analyze traffic.Learn more.

[8]ページ先頭

©2009-2025 Movatter.jp