49

GitHub - smallnest/rpcx: Faster multil-language bidirectional RPC framework in...

 4 years ago
source link: https://github.com/smallnest/rpcx
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

README.md

687474703a2f2f727063782e736974652f6c6f676f732f727063782d6c6f676f2d746578742e706e67

Official site: http://rpcx.site

License GoDoc travis Go Report Card coveralls QQ群 Join the chat at https://gitter.im/smallnest/rpcx

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 servies via raw protocol.

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 -u -v github.com/smallnest/rpcx/...

If you want to use reuseportquickcp, zookeeper, etcd, consul registry, use those tags to go getgo build or go run. For example, if you want to use all features, you can:

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

tags:

  • quic: support quic transport
  • kcp: support kcp transport
  • zookeeper: support zookeeper register
  • etcd: support etcd register
  • consul: support consul register
  • ping: support network quality load balancing
  • reuseport: support reuseport

Features

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

rpcx 3.0 has been refactored for targets:

  1. Simple: easy to learn, easy to develop, easy to intergate and easy to deploy
  2. Performance: high perforamnce (>= 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 Latency687474703a2f2f636f6c6f62752e636f6d2f323031382f30312f33312f62656e63686d61726b2d323031382d737072696e672d6f662d706f70756c61722d7270632d6672616d65776f726b732f70302d7468726f7567687075742e706e67687474703a2f2f636f6c6f62752e636f6d2f323031382f30312f33312f62656e63686d61726b2d323031382d737072696e672d6f662d706f70756c61722d7270632d6672616d65776f726b732f70302d6c6174656e63792e706e67687474703a2f2f636f6c6f62752e636f6d2f323031382f30312f33312f62656e63686d61726b2d323031382d737072696e672d6f662d706f70756c61722d7270632d6672616d65776f726b732f70302d7039392e706e67

mock 10ms process time

ThroughputsMean LatencyP99 Latency687474703a2f2f636f6c6f62752e636f6d2f323031382f30312f33312f62656e63686d61726b2d323031382d737072696e672d6f662d706f70756c61722d7270632d6672616d65776f726b732f7031302d7468726f7567687075742e706e67687474703a2f2f636f6c6f62752e636f6d2f323031382f30312f33312f62656e63686d61726b2d323031382d737072696e672d6f662d706f70756c61722d7270632d6672616d65776f726b732f7031302d6c6174656e63792e706e67687474703a2f2f636f6c6f62752e636f6d2f323031382f30312f33312f62656e63686d61726b2d323031382d737072696e672d6f662d706f70756c61722d7270632d6672616d65776f726b732f7031302d7039392e706e67

mock 30ms process time

ThroughputsMean LatencyP99 Latency687474703a2f2f636f6c6f62752e636f6d2f323031382f30312f33312f62656e63686d61726b2d323031382d737072696e672d6f662d706f70756c61722d7270632d6672616d65776f726b732f7033302d7468726f7567687075742e706e67687474703a2f2f636f6c6f62752e636f6d2f323031382f30312f33312f62656e63686d61726b2d323031382d737072696e672d6f662d706f70756c61722d7270632d6672616d65776f726b732f7033302d6c6174656e63792e706e67687474703a2f2f636f6c6f62752e636f6d2f323031382f30312f33312f62656e63686d61726b2d323031382d737072696e672d6f662d706f70756c61722d7270632d6672616d65776f726b732f7033302d7039392e706e67

Examples

You can find all examples at rpcx-ecosystem/rpcx-examples3.

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 := 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)

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


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK