0%

为了开发测试方便,我实现了一个基于brpc框架的测试软件。它主要用于远程控制和监测被测试机的状态,由于之前开发上层软件比较少,所以见此记录一下。

BRPC简介

它把网络交互类比为“client访问server上的函数”:client向server发送request后开始等待,直到server收到、处理、回复client后,client又再度恢复并根据response做出反应。

img

我们来看看上面的一些问题是如何解决的:

数据需要序列化,protobuf在这方面做的不错。用户填写protobuf::Message类型的request,RPC结束后,从同为protobuf::Message类型的response中取出结果。protobuf有较好的前后兼容性,方便业务调整字段。http广泛使用json作为序列化方法。
用户无需关心连接如何建立,但可以选择不同的连接方式:短连接,连接池,单连接。
大量机器一般通过命名服务被发现,可基于DNS, ZooKeeper, etcd等实现。在百度内,我们使用BNS (Baidu Naming Service)。brpc也提供“list://“和”file://”。用户可以指定负载均衡算法,让RPC每次选出一台机器发送请求,包括: round-robin, randomized, consistent-hashing(murmurhash3 or md5)和 locality-aware.
连接断开时可以重试。
如果server没有在给定时间内回复,client会返回超时错误。

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment