askuy / braid-go

简单易用的微服务框架 | Ease used microservice framework

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Braid


Go Report Card CI Coverage Status

中文

Intro

Description of Service Node Module RPC Pub-sub

image.png


  • RPC Client/Server - Used for request / response from service to service
  • Pub-sub - Used to publish & subscribe messages from module to module
  • Discover - Automatic service discovery, and broadcast the node's entry, exit, update and other messages
  • Balancer - Client side load balancing which built on service discovery. Provide smooth weighted round-robin balancing by default
  • Elector - Select a unique master node for the same name service
  • Tracer - Distributed tracing system, used to monitor the internal state of the program running in microservices
  • Linkcache - Link cache used to maintain connection information in distributed systems

Modules

Discovery Balancing Elector RPC Pub-sub Tracer LinkCache
discoverconsul balancerrandom electorconsul grpc-client mailbox jaegertracer linkerredis
balancerswrr electork8s grpc-server

Quick start

s := braid.NewService("gate")   // create a new node in the service gate

// register module in node
s.Register(
    braid.Module(braid.LoggerZap),
    braid.Module(braid.PubsubNsq,
        pubsubnsq.WithLookupAddr([]string{mock.NSQLookupdAddr}),
        pubsubnsq.WithNsqdAddr([]string{mock.NsqdAddr}, []string{mock.NsqdHttpAddr}),
    ),
    braid.Module(
        braid.DiscoverConsul,    // discover module
        discoverconsul.WithConsulAddr(consulAddr)
    ),
)

s.Init()
s.Run()

defer s.Close()

Pub-sub Benchmark

  • ScopeProc
$ go test -benchmem -run=^$ -bench ^BenchmarkTestProc -cpu 2,4,8
cpu: 2.2 GHz 4 Cores Intel Core i7
goos: darwin
goarch: amd64
pkg: github.com/pojol/braid-go/modules/mailboxnsq
BenchmarkTestProc-2   4340389   302 ns/op   109 B/op   3 allocs/op
BenchmarkTestProc-4   8527536   151 ns/op   122 B/op   3 allocs/op
BenchmarkTestProc-8   7564869   161 ns/op   118 B/op   3 allocs/op
PASS
  • ScopeCluster
$ go test -benchmem -run=^$ -bench ^BenchmarkClusterBroadcast -cpu 2,4,8
tencent cloud 4 Cores
goos: linux
goarch: amd64
BenchmarkClusterBroadcast-2   70556   17234 ns/op   540 B/op   16 allocs/op
BenchmarkClusterBroadcast-4   71202   18975 ns/op   676 B/op   20 allocs/op
BenchmarkClusterBroadcast-8   62098   19037 ns/op   662 B/op   20 allocs/op

About

简单易用的微服务框架 | Ease used microservice framework

License:MIT License


Languages

Language:Go 99.1%Language:Shell 0.8%Language:Dockerfile 0.1%