The Go language open-source RPC service governance framework is being used by many large companies and startups

The Go language open-source RPC service governance framework is being used by many large companies and startups

2022-10-12 1 1,399
Resource Number 45265 Last Updated 2025-02-24
¥ 0HKD Upgrade VIP
Download Now Matters needing attention
Can't download? Please contact customer service to submit a link error!
Value-added Service: Installation Guide Environment Configuration Secondary Development Template Modification Source Code Installation

This issue recommends a Go language RPC service governance framework – RPCX</ em>

The Go language open-source RPC service governance framework is being used by many large companies and startups插图

RPCX is currently one of the most popular microservice frameworks in the Go ecosystem, used by many large companies and startups. The server does not require additional configuration, and RPCX also supports HTTP calls, allowing other programming languages to call RPCX services. It is currently one of the best performing RPC frameworks</ p>

Functional Features

    Easy to use: easy to get started, easy to develop, easy to integrate, easy to publish, easy to monitor

  • High performance: The performance is much higher than frameworks such as Dubbo, Motan, Thrift, and is twice the performance of gRPC
  • Cross platform, cross language: can be easily deployed on platforms such as Windows/Linux/MacOS, supporting calls from various programming languages
  • Service discovery: In addition to direct connection, it also supports registration centers such as Zookeeper, Etcd, Consul, mDNS, etc
  • Service governance: Supports failure modes such as failover, Fail fast, Fail try, Backup, etc., and supports routing algorithms such as random, polling, weight, network quality, consistent hashing, geographic location, etc

Quick Start

Install

Firstly, you need to install rpcx:

go get -u -v github.com/smallnest/rpcx/...</ code>

This step will only install the basic features of rpcx. If you want to use etcd as a registry, you need to add the etcd tag</ p>

go get -u -v -tags "etcd" github.com/smallnest/rpcx/...</ code>

If you want to use Quic, you also need to add the Quic tag</ p>

go get -u -v -tags "quic etcd" github.com/smallnest/rpcx/...</ code>

For convenience, I recommend that you install all tags, even if you don’t need them now:

go get -u -v -tags "reuseport quic kcp zookeeper etcd consul ping" github.com/smallnest/rpcx/...</ code>

Tags correspond to:

  • Quic: Supports Quic protocol
  • KCP: Supports KCP protocol
  • Zookeeper: Supports Zookeeper Registry
  • etcd: Supports etcd registry
  • Consul: Supports Consul Registry
  • Ping: Supports network quality load balancing
  • Reuseport: Supports reuseport

Implement Service

Implementing a Sevice is like writing a simple Go struct:

import "context"

type Args struct {
A int
B int
}

type Reply struct {
C int
}

type Arith int

func (t *Arith) Mul(ctx context.Context,  args *Args, reply *Reply) error {
reply.C = args.A * args.B
return nil
}

Arith is a Go type and has a method called Mul. The first parameter of method Mul is context Context。 The second parameter of the Mul method is ARGs, which contains the requested data A and B. The third parameter of method Mul is reply, which is a pointer to the Reply structure. The return type of method Mul is error (which can be nil). Method Mul assigns the result of A * B to Reply C

Now you have defined a service called Arith and implemented the Mul method for it. In the next step, we will continue to introduce how to register this service with the server and how to call it with the client</ p>

The Go language open-source RPC service governance framework is being used by many large companies and startups插图1

Implement Server

Three lines of code can register a service:

s := server. NewServer()

s.RegisterName("Arith", new(Arith), "")

s.Serve("tcp", ":8972")

Here you name your service Arith</ p>

You can register for the service using the following code</ p>

s.Register(new(example.Arith), "")

Here, the service type name is simply used as the service name</ p>

The Go language open-source RPC service governance framework is being used by many large companies and startups插图2

Implement Client

 // #1
d := client.NewPeer2PeerDiscovery("tcp@"+*addr, "")
// #2
xclient := client.NewXClient("Arith", client.Failtry, client.RandomSelect, d, client.DefaultOption)
defer xclient. Close()

// #3
args := & example.Args{
A: 10,
B: 20,
}

// #4
reply := & example.Reply{}

// #5
err := xclient.Call(context.Background(), "Mul", args, reply)
if err != < span class="hljs-literal">nil {
log.Fatalf("failed to call: %v", err)
}

log.Printf("%d * %d = %d", args.A, args.B, reply.C)

# 1 defines how to implement service discovery. Here we use the simplest Peer2PeerDiscovery. The client directly connects to the server to obtain the service address</ p>

# 2 created XClient and passed in Failed Mode, Select Mode, and default options. Failed Mode tells the client how to handle call failures: retry, fast return, or try another server. SelectMode tells the client how to select a server when multiple servers provide the same service</ p>

# 3 defines the request: here we want to get a result of 10 * 20. Of course, we can calculate the result ourselves to be 200, but we still want to confirm if this is consistent with the server’s return result</ p>

# 4 defines a response object with a default value of 0. In fact, rpcx uses it to know the type of the returned result and deserializes the result to this object</ p>

# 5 called a remote service and synchronized the results</ p>

f868809ad7604adea71a1c2fee802ae7noop.image_

Asynchronous call to Service

The following code can asynchronously call services:

    d := client.NewPeer2PeerDiscovery("tcp@"+*addr2, "")
xclient := client.NewXClient("Arith", client.Failtry, client.RandomSelect, d, client.DefaultOption)
defer xclient. Close()

args := & example.Args{
A: 10,
B: 20,
}

reply := & example.Reply{}
call, err := xclient.Go(context.Background(), "Mul", args, reply, nil)
if err != < span class="hljs-literal">nil {
log.Fatalf("failed to call: %v", err)
}

replyCall := <- call.Done
if replyCall. Error != < span class="hljs-literal">nil {
log.Fatalf("failed to call: %v", replyCall.Error)
} else {
log.Printf("%d * %d = %d", args.A, args.B, reply.C)
}

You must use xcerver Go to replace xcerver Call and return the result to a channel. You can listen for the call results from chnenel</ p>

Performance testing

Test Environment

    • CPU : Intel(R) Xeon(R) CPU E5-2630 v3 @ 2.40GHz, 32 cores
    • Memory: 32GB
    • Go version: 1.9.0

Operating System: CentOS 7/3.10.0-229.el7.x86_64

Adopt

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

Test results

Simulate 0ms processing time:

  • Throughput

The Go language open-source RPC service governance framework is being used by many large companies and startups插图4

  • Average latency

The Go language open-source RPC service governance framework is being used by many large companies and startups插图5

  • P99 latency

The Go language open-source RPC service governance framework is being used by many large companies and startups插图6

Simulate 10ms processing time:

  • Throughput

The Go language open-source RPC service governance framework is being used by many large companies and startups插图7

  • Average latency

The Go language open-source RPC service governance framework is being used by many large companies and startups插图8

  • P99 latency

The Go language open-source RPC service governance framework is being used by many large companies and startups插图9

Simulate 30ms processing time:

  • Throughput

The Go language open-source RPC service governance framework is being used by many large companies and startups插图10

  • Average latency

The Go language open-source RPC service governance framework is being used by many large companies and startups插图11

  • P99 latency

The Go language open-source RPC service governance framework is being used by many large companies and startups插图12

—END—

Open source license: Apache 2.0

资源下载此资源为免费资源立即下载
Telegram:@John_Software

Disclaimer: This article is published by a third party and represents the views of the author only and has nothing to do with this website. This site does not make any guarantee or commitment to the authenticity, completeness and timeliness of this article and all or part of its content, please readers for reference only, and please verify the relevant content. The publication or republication of articles by this website for the purpose of conveying more information does not mean that it endorses its views or confirms its description, nor does it mean that this website is responsible for its authenticity.

Ictcoder Free Source Code The Go language open-source RPC service governance framework is being used by many large companies and startups https://ictcoder.com/go-language-open-source-rpc-service-governance-framework/

Share free open-source source code

Q&A
  • 1. Automatic: After making an online payment, click the (Download) link to download the source code; 2. Manual: Contact the seller or the official to check if the template is consistent. Then, place an order and make payment online. The seller ships the goods, and both parties inspect and confirm that there are no issues. ICTcoder will then settle the payment for the seller. Note: Please ensure to place your order and make payment through ICTcoder. If you do not place your order and make payment through ICTcoder, and the seller sends fake source code or encounters any issues, ICTcoder will not assist in resolving them, nor can we guarantee your funds!
View details
  • 1. Default transaction cycle for source code: The seller manually ships the goods within 1-3 days. The amount paid by the user will be held in escrow by ICTcoder until 7 days after the transaction is completed and both parties confirm that there are no issues. ICTcoder will then settle with the seller. In case of any disputes, ICTcoder will have staff to assist in handling until the dispute is resolved or a refund is made! If the buyer places an order and makes payment not through ICTcoder, any issues and disputes have nothing to do with ICTcoder, and ICTcoder will not be responsible for any liabilities!
View details
  • 1. ICTcoder will permanently archive the transaction process between both parties and snapshots of the traded goods to ensure the authenticity, validity, and security of the transaction! 2. ICTcoder cannot guarantee services such as "permanent package updates" and "permanent technical support" after the merchant's commitment. Buyers are advised to identify these services on their own. If necessary, they can contact ICTcoder for assistance; 3. When both website demonstration and image demonstration exist in the source code, and the text descriptions of the website and images are inconsistent, the text description of the image shall prevail as the basis for dispute resolution (excluding special statements or agreements); 4. If there is no statement such as "no legal basis for refund" or similar content, any indication on the product that "once sold, no refunds will be supported" or other similar declarations shall be deemed invalid; 5. Before the buyer places an order and makes payment, the transaction details agreed upon by both parties via WhatsApp or email can also serve as the basis for dispute resolution (in case of any inconsistency between the agreement and the description of the conflict, the agreement shall prevail); 6. Since chat records and email records can serve as the basis for dispute resolution, both parties should only communicate with each other through the contact information left on the system when contacting each other, in order to prevent the other party from denying their own commitments. 7. Although the probability of disputes is low, it is essential to retain important information such as chat records, text messages, and email records, in case a dispute arises, so that ICTcoder can intervene quickly.
View details
  • 1. As a third-party intermediary platform, ICTcoder solely protects transaction security and the rights and interests of both buyers and sellers based on the transaction contract (product description, agreed content before the transaction); 2. For online trading projects not on the ICTcoder platform, any consequences are unrelated to this platform; regardless of the reason why the seller requests an offline transaction, please contact the administrator to report.
View details

Related Source code

ICTcoder Customer Service

24-hour online professional services