Convert Figma logo to code with AI

smallnest logorpcx

Best microservices framework in Go, like alibaba Dubbo, but with more features, Scale easily. Try it. Test it. If you feel it's better, use it! 𝐉𝐚𝐯𝐚有𝐝𝐮𝐛𝐛𝐨, 𝐆𝐨𝐥𝐚𝐧𝐠有𝐫𝐩𝐜𝐱! build for cloud!

8,066
1,160
8,066
7

Top Related Projects

20,846

The Go language implementation of gRPC. HTTP/2 based RPC

21,607

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http

26,478

A standard library for microservices.

21,795

A Go microservices framework

7,115

A simple RPC framework with protobuf service definitions

28,835

A cloud-native Go microservices framework with cli tool for productivity.

Quick Overview

rpcx is a high-performance, feature-rich RPC framework for Go. It provides a simple and efficient way to build distributed systems and microservices, offering various protocols, service discovery mechanisms, and load balancing strategies.

Pros

  • High performance and low latency compared to other RPC frameworks
  • Supports multiple serialization formats (e.g., Protocol Buffers, MessagePack, JSON)
  • Built-in service discovery and load balancing
  • Extensible plugin system for customization

Cons

  • Primarily focused on Go, limiting cross-language support
  • Documentation could be more comprehensive for advanced features
  • Steeper learning curve compared to simpler RPC frameworks
  • Less community adoption compared to gRPC

Code Examples

  1. Defining a service:
type Arith int

func (t *Arith) Mul(ctx context.Context, args *pb.Args, reply *pb.Reply) error {
    reply.C = args.A * args.B
    return nil
}
  1. Creating a server:
s := server.NewServer()
s.RegisterName("Arith", new(Arith), "")
s.Serve("tcp", ":8972")
  1. Creating a client and making a call:
d, _ := client.NewPeer2PeerDiscovery("tcp@"+*addr, "")
xclient := client.NewXClient("Arith", client.Failtry, client.RandomSelect, d, client.DefaultOption)
defer xclient.Close()

args := &pb.Args{A: 10, B: 20}
reply := &pb.Reply{}
err := xclient.Call(context.Background(), "Mul", args, reply)
if err != nil {
    log.Fatalf("failed to call: %v", err)
}
fmt.Printf("%d * %d = %d", args.A, args.B, reply.C)

Getting Started

  1. Install rpcx:

    go get -u github.com/smallnest/rpcx/...
    
  2. Define your service and methods (as shown in the first code example).

  3. Create a server and register your service (as shown in the second code example).

  4. Create a client and make RPC calls (as shown in the third code example).

  5. Run your server and client applications to test the RPC communication.

For more detailed instructions and advanced features, refer to the official rpcx documentation.

Competitor Comparisons

20,846

The Go language implementation of gRPC. HTTP/2 based RPC

Pros of grpc-go

  • Widely adopted and supported by Google, with a large community
  • Excellent performance and efficient binary serialization
  • Strong support for streaming and bidirectional communication

Cons of grpc-go

  • Steeper learning curve due to protocol buffer definitions
  • Less flexibility in message formats compared to rpcx
  • Requires more boilerplate code for setup and configuration

Code Comparison

rpcx example:

func main() {
    s := server.NewServer()
    s.RegisterName("Arith", new(Arith), "")
    s.Serve("tcp", ":8972")
}

grpc-go example:

func main() {
    s := grpc.NewServer()
    pb.RegisterGreeterServer(s, &server{})
    lis, _ := net.Listen("tcp", ":50051")
    s.Serve(lis)
}

Summary

rpcx is a lightweight, easy-to-use RPC framework with a focus on simplicity and performance. It offers more flexibility in message formats and easier setup compared to grpc-go. However, grpc-go benefits from wider adoption, stronger streaming support, and the backing of Google. The choice between the two depends on specific project requirements, team expertise, and desired features.

21,607

Fast HTTP package for Go. Tuned for high performance. Zero memory allocations in hot paths. Up to 10x faster than net/http

Pros of fasthttp

  • Extremely high performance HTTP server and client implementation
  • Low memory footprint and minimal allocations
  • Supports HTTP/1.1 and WebSockets out of the box

Cons of fasthttp

  • Limited to HTTP/1.1, no built-in HTTP/2 support
  • Less feature-rich compared to rpcx for RPC-specific functionality
  • Steeper learning curve due to its low-level nature

Code Comparison

fasthttp example:

func requestHandler(ctx *fasthttp.RequestCtx) {
    fmt.Fprintf(ctx, "Hello, world!")
}
fasthttp.ListenAndServe(":8080", requestHandler)

rpcx example:

type Arith int

func (t *Arith) Mul(args *Args, reply *int) error {
    *reply = args.A * args.B
    return nil
}

s := server.NewServer()
s.RegisterName("Arith", new(Arith), "")
s.Serve("tcp", ":8972")

While fasthttp focuses on high-performance HTTP handling, rpcx is designed specifically for RPC (Remote Procedure Call) scenarios. fasthttp excels in raw HTTP performance, while rpcx provides a more comprehensive RPC framework with features like service discovery, load balancing, and multiple protocols support.

26,478

A standard library for microservices.

Pros of kit

  • More comprehensive toolkit for building microservices
  • Stronger focus on observability and instrumentation
  • Larger community and ecosystem of third-party integrations

Cons of kit

  • Steeper learning curve due to its complexity
  • Can be overkill for simpler projects
  • Requires more boilerplate code

Code Comparison

kit:

func main() {
    svc := service.New(logger, db)
    endpoints := endpoint.New(svc, logger)
    httpHandler := httptransport.NewServer(endpoints, logger)
    http.ListenAndServe(":8080", httpHandler)
}

rpcx:

func main() {
    s := server.NewServer()
    s.RegisterName("Arith", new(Arith), "")
    s.Serve("tcp", ":8972")
}

rpcx offers a simpler, more straightforward approach to creating RPC services, while kit provides a more structured and feature-rich framework for building microservices. rpcx is generally easier to get started with and requires less setup code, but kit offers more built-in features for monitoring, tracing, and service discovery. The choice between the two depends on the specific requirements of your project and the level of complexity you're comfortable with.

21,795

A Go microservices framework

Pros of go-micro

  • More comprehensive ecosystem with additional tools and plugins
  • Better support for cloud-native and microservices architectures
  • Stronger community and wider adoption in the industry

Cons of go-micro

  • Steeper learning curve due to more complex architecture
  • Potentially overkill for simpler projects or smaller-scale applications
  • Slower performance in some benchmarks compared to rpcx

Code Comparison

rpcx example:

func main() {
    s := server.NewServer()
    s.RegisterName("Arith", new(Arith), "")
    s.Serve("tcp", ":8972")
}

go-micro example:

func main() {
    service := micro.NewService(micro.Name("greeter"))
    service.Init()
    proto.RegisterGreeterHandler(service.Server(), new(Greeter))
    service.Run()
}

Both frameworks provide simple ways to create and register services, but go-micro's approach is more aligned with microservices patterns, while rpcx focuses on RPC-style communication. go-micro requires more setup and configuration, reflecting its broader feature set, while rpcx offers a more straightforward implementation for basic RPC needs.

7,115

A simple RPC framework with protobuf service definitions

Pros of Twirp

  • Simpler and more lightweight, making it easier to learn and implement
  • Built-in support for both JSON and Protocol Buffers, offering flexibility in data serialization
  • Designed to work well with HTTP/1.1 and HTTP/2, providing better compatibility with existing infrastructure

Cons of Twirp

  • Limited feature set compared to rpcx, which offers more advanced functionalities
  • Less focus on performance optimizations, potentially resulting in slower execution in some scenarios
  • Smaller community and ecosystem, leading to fewer third-party tools and extensions

Code Comparison

Twirp service definition:

service Haberdasher {
  rpc MakeHat(Size) returns (Hat);
}

rpcx service definition:

type Arith int

func (t *Arith) Mul(args *Args, reply *int) error {
    *reply = args.A * args.B
    return nil
}

Both rpcx and Twirp aim to simplify RPC (Remote Procedure Call) implementations, but they take different approaches. rpcx offers a more comprehensive set of features and focuses on high performance, while Twirp prioritizes simplicity and ease of use. The choice between the two depends on the specific requirements of your project, such as performance needs, desired feature set, and integration with existing systems.

28,835

A cloud-native Go microservices framework with cli tool for productivity.

Pros of go-zero

  • More comprehensive microservices framework with built-in service governance
  • Stronger focus on API gateway and service mesh capabilities
  • Better documentation and examples for getting started quickly

Cons of go-zero

  • Steeper learning curve due to more complex architecture
  • Less flexible for simple RPC use cases
  • Potentially more overhead for smaller projects

Code Comparison

go-zero service definition:

type (
    UserReq {
        Name string `json:"name"`
    }

    UserResp {
        Id   int64  `json:"id"`
        Name string `json:"name"`
    }

    UserService interface {
        GetUser(ctx context.Context, req *UserReq) (*UserResp, error)
    }
)

rpcx service definition:

type Args struct {
    Name string
}

type Reply struct {
    Id   int64
    Name string
}

type UserService struct{}

func (s *UserService) GetUser(ctx context.Context, args *Args, reply *Reply) error {
    // Implementation
    return nil
}

Both frameworks offer efficient RPC communication for Go microservices. rpcx is more focused on pure RPC functionality, making it simpler for basic use cases. go-zero provides a more comprehensive solution for building and managing microservices at scale, but with added complexity. The choice between them depends on project requirements and team expertise.

Convert Figma logo designs to code with AI

Visual Copilot

Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.

Try Visual Copilot

README

  • stable branch: v1.7.x
  • development branch: master

Official site: http://rpcx.io

License GoDoc github actions Go Report Card coveralls QQ3群

Notice: etcd

since rpcx 1.7.6, some plugins have been moved to the independent project:

Announce

A tcpdump-like tool added: rpcxdump。 You can use it to debug communications between rpcx services and clients.

Cross-Languages

you can use other programming languages besides Go to access rpcx services.

  • rpcx-gateway: You can write clients in any programming languages to call rpcx services via rpcx-gateway
  • http invoke: you can use the same http requests to access rpcx gateway
  • Java Services/Clients: You can use rpcx-java to implement/access rpcx services via raw protocol.
  • rust rpcx: You can write rpcx services in rust by rpcx-rs

If you can write Go methods, you can also write rpc services. It is so easy to write rpc applications with rpcx.

Installation

install the basic features:

go get -v github.com/smallnest/rpcx/...

If you want to use quic、kcp registry, use those tags to go get 、 go build or go run. For example, if you want to use all features, you can:

go get -v -tags "quic kcp" github.com/smallnest/rpcx/...

tags:

  • quic: support quic transport
  • kcp: support kcp transport

Which companies are using rpcx?

Features

rpcx is a RPC framework like Alibaba Dubbo and Weibo Motan.

rpcx is created for targets:

  1. Simple: easy to learn, easy to develop, easy to integrate and easy to deploy
  2. Performance: high performance (>= grpc-go)
  3. Cross-platform: support raw slice of bytes, JSON, Protobuf and MessagePack. Theoretically it can be used with java, php, python, c/c++, node.js, c# and other platforms
  4. Service discovery and service governance: support zookeeper, etcd and consul.

It contains below features

  • Support raw Go functions. There's no need to define proto files.
  • Pluggable. Features can be extended such as service discovery, tracing.
  • Support TCP, HTTP, QUIC and KCP
  • Support multiple codecs such as JSON, Protobuf, MessagePack and raw bytes.
  • Service discovery. Support peer2peer, configured peers, zookeeper, etcd, consul and mDNS.
  • Fault tolerance:Failover, Failfast, Failtry.
  • Load banlancing:support Random, RoundRobin, Consistent hashing, Weighted, network quality and Geography.
  • Support Compression.
  • Support passing metadata.
  • Support Authorization.
  • Support heartbeat and one-way request.
  • Other features: metrics, log, timeout, alias, circuit breaker.
  • Support bidirectional communication.
  • Support access via HTTP so you can write clients in any programming languages.
  • Support API gateway.
  • Support backup request, forking and broadcast.

rpcx uses a binary protocol and platform-independent, which means you can develop services in other languages such as Java, python, nodejs, and you can use other prorgramming languages to invoke services developed in Go.

There is a UI manager: rpcx-ui.

Performance

Test results show rpcx has better performance than other rpc framework except standard rpc lib.

The benchmark code is at rpcx-benchmark.

Listen to others, but test by yourself.

Test Environment

  • CPU: Intel(R) Xeon(R) CPU E5-2630 v3 @ 2.40GHz, 32 cores
  • Memory: 32G
  • Go: 1.9.0
  • OS: CentOS 7 / 3.10.0-229.el7.x86_64

Use

  • protobuf
  • the client and the server on the same server
  • 581 bytes payload
  • 500/2000/5000 concurrent clients
  • mock processing time: 0ms, 10ms and 30ms

Test Result

mock 0ms process time

ThroughputsMean LatencyP99 Latency

mock 10ms process time

ThroughputsMean LatencyP99 Latency

mock 30ms process time

ThroughputsMean LatencyP99 Latency

Examples

You can find all examples at rpcxio/rpcx-examples.

The below is a simple example.

Server

    // define example.Arith
    ……

    s := server.NewServer()
	s.RegisterName("Arith", new(example.Arith), "")
	s.Serve("tcp", addr)

Client

    // prepare requests
    ……

    d, err := client.NewPeer2PeerDiscovery("tcp@"+addr, "")
	xclient := client.NewXClient("Arith", client.Failtry, client.RandomSelect, d, client.DefaultOption)
	defer xclient.Close()
	err = xclient.Call(context.Background(), "Mul", args, reply, nil)

Contributors

Contribute

see contributors.

Welcome to contribute:

  • submit issues or requirements
  • send PRs
  • write projects to use rpcx
  • write tutorials or articles to introduce rpcx

License

Apache License, Version 2.0