在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:srpc开源软件地址:https://gitee.com/sogou/srpc开源软件介绍:English version | Wiki:SRPC架构介绍 IntroductionSPRC是全搜狗业务线上使用的企业级RPC系统,目前每天承载上百亿的请求量,涵盖搜广推及其他类型业务。主要功能和特点:
Installation
git clone --recursive https://github.com/sogou/srpc.gitcd srpcmake Tutorial
简单的命令即可编译示例: cd tutorial make Quick Start1. example.protosyntax = "proto3";//这里proto2和proto3都可以,srpc都支持message EchoRequest { string message = 1; string name = 2;};message EchoResponse { string message = 1;};service Example { rpc Echo(EchoRequest) returns (EchoResponse);}; 2. generate codeprotoc example.proto --cpp_out=./ --proto_path=./srpc_generator protobuf ./example.proto ./ 3. server.cc#include <stdio.h>#include <signal.h>#include "example.srpc.h"using namespace srpc;class ExampleServiceImpl : public Example::Service{public: void Echo(EchoRequest *request, EchoResponse *response, RPCContext *ctx) override { response->set_message("Hi, " + request->name()); printf("get_req:\n%s\nset_resp:\n%s\n", request->DebugString().c_str(), response->DebugString().c_str()); }};void sig_handler(int signo) { }int main(){ signal(SIGINT, sig_handler); signal(SIGTERM, sig_handler); SRPCServer server_tcp; SRPCHttpServer server_http; ExampleServiceImpl impl; server_tcp.add_service(&impl); server_http.add_service(&impl); server_tcp.start(1412); server_http.start(8811); getchar(); // press "Enter" to end. server_http.stop(); server_tcp.stop(); return 0;} 4. client.cc#include <stdio.h>#include "example.srpc.h"using namespace srpc;int main(){ Example::SRPCClient client("127.0.0.1", 1412); EchoRequest req; req.set_message("Hello, srpc!"); req.set_name("workflow"); client.Echo(&req, [](EchoResponse *response, RPCContext *ctx) { if (ctx->success()) printf("%s\n", response->DebugString().c_str()); else printf("status[%d] error[%d] errmsg:%s\n", ctx->get_status_code(), ctx->get_error(), ctx->get_errmsg()); }); getchar(); // press "Enter" to end. return 0;} 5. make在Linux系统下的编译示例如下,其他平台建议到tutorial目录下使用完整的cmake文件协助解决编译依赖问题。 g++ -o server server.cc example.pb.cc -std=c++11 -lsrpcg++ -o client client.cc example.pb.cc -std=c++11 -lsrpc 6. run终端1: ./server 终端2: ./client 也可以用CURL发送http请求: curl 127.0.0.1:8811/Example/Echo -H 'Content-Type: application/json' -d '{message:"from curl",name:"CURL"}' 终端1输出: get_req:message: "Hello, srpc!"name: "workflow"set_resp:message: "Hi, workflow"get_req:message: "from curl"name: "CURL"set_resp:message: "Hi, CURL" 终端2输出: message: "Hi, workflow" CURL收到的回复: {"message":"Hi, CURL"} Benchmark
跨机单client→单server在不同并发的QPSClient = 1ClientThread = 64, 128, 256, 512, 1024RequestSize = 32Duration = 20sServer = 1ServerIOThread = 16ServerHandlerThread = 16 跨机多client→单server在不同client进程数的QPSClient = 1, 2, 4, 8, 16ClientThread = 32RequestSize = 32Duration = 20sServer = 1ServerIOThread = 16ServerHandlerThread = 16 同机单client→单server在不同并发下的QPSClient = 1ClientThread = 1, 2, 4, 8, 16, 32, 64, 128, 256RequestSize = 1024Duration = 20sServer = 1ServerIOThread = 16ServerHandlerThread = 16 同机单client→单server在不同请求大小下的QPSClient = 1ClientThread = 100RequestSize = 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768Duration = 20sServer = 1ServerIOThread = 16ServerHandlerThread = 16 同机单client→单server在固定QPS下的延时CDFClient = 1ClientThread = 50ClientQPS = 10000RequestSize = 1024Duration = 20sServer = 1ServerIOThread = 16ServerHandlerThread = 16Outiler = 1% 跨机多client→单server在固定QPS下的延时CDFClient = 32ClientThread = 16ClientQPS = 2500RequestSize = 512Duration = 20sServer = 1ServerIOThread = 16ServerHandlerThread = 16Outiler = 1% 与我们联系
|
请发表评论