Go to file
liyingxin 3796acb33f
Some checks failed
ci build / ubuntu (push) Has been cancelled
ci build / fedora (push) Has been cancelled
ci build / bazel (push) Has been cancelled
srpc tools: fix default transport_type and retry_max in config (#415)
2024-12-16 19:29:01 +08:00
.github/workflows 1. Add .bazelignore and add bazel in ci.yml; 2023-07-26 20:17:35 +08:00
benchmark cmake : Add checking Gtest_VERSION for cmake 3.26.0; Use static link for macOS; 2023-04-17 21:45:03 +08:00
docs Update always_print_fields_with_no_presence to ensure compatibility with protobuf v26.x (#408) 2024-09-06 17:16:15 +08:00
src Fix http server module memory leak. (#411) 2024-10-18 16:16:47 +08:00
test Update C++ standard to c++14. (#400) 2024-07-17 18:10:35 +08:00
third_party update snappy and lz4 to newest release 2021-11-04 16:21:29 +08:00
tools srpc tools: fix default transport_type and retry_max in config (#415) 2024-12-16 19:29:01 +08:00
tutorial Update tutorial CMakeLists.txt : regenerate when files updated. 2024-07-30 22:49:37 +08:00
workflow@3e8f57160a Update workflow submodule. 2024-08-01 22:01:14 +08:00
.bazelignore 1. Add .bazelignore and add bazel in ci.yml; 2023-07-26 20:17:35 +08:00
.editorconfig initialize 2020-08-09 15:54:33 +08:00
.gitignore add bazel support 2021-08-15 19:56:37 +08:00
.gitmodules update snappy and lz4 to newest release 2021-11-04 16:21:29 +08:00
BUILD Update bazel : liblibsrpc -> libsrpc 2023-09-18 18:16:50 +08:00
CMakeLists_Headers.txt rpc_module : support semantic conventions for HTTP spans 2023-04-13 18:01:10 +08:00
CMakeLists.txt 0.10.2 -> 0.10.3 2024-06-25 16:13:52 +08:00
CODE_OF_CONDUCT.md add CODE_OF_CONDUCT.md 2020-09-14 15:07:28 +08:00
GNUmakefile cmake : Add checking Gtest_VERSION for cmake 3.26.0; Use static link for macOS; 2023-04-17 21:45:03 +08:00
LICENSE initialize 2020-08-09 15:54:33 +08:00
README_cn.md Fix typo (#375) 2024-04-07 16:46:22 +08:00
README.md Fix typo (#375) 2024-04-07 16:46:22 +08:00
srpc-config.cmake.in fix targets in srpc-config.cmake.in 2023-01-16 10:44:04 +00:00
srpc.bzl Update bazel : liblibsrpc -> libsrpc 2023-09-18 18:16:50 +08:00
WORKSPACE Update workflow submodule. 2024-08-01 22:01:14 +08:00

中文版入口


srpc-logo

NEW !!! 👉 SRPC tools : build Workflow and SRPC projects easily.

Introduction

SRPC is an enterprise-level RPC system used by almost all online services in Sogou. It handles tens of billions of requests every day, covering searches, recommendations, advertising system, and other types of services.

Bases on Sogou C++ Workflow, it is an excellent choice for high-performance, low-latency, lightweight RPC systems. Contains AOP aspect-oriented modules that can report Metrics and Trace to a variety of cloud-native systems, such as OpenTelemetry, etc.

Its main features include:

  • Support multiple RPC protocols: SRPC, bRPC, Thrift, tRPC
  • Support multiple operating systems: Linux, MacOS, Windows
  • Support several IDL formats: Protobuf, Thrift
  • Support several data formats transparently: Json, Protobuf, Thrift Binary
  • Support several compression formats, the framework automatically decompresses: gzip, zlib, snappy, lz4
  • Support several communication protocols transparently: tcp, udp, sctp, tcp ssl
  • With HTTP+JSON, you can communicate with the client or server in any language
  • Use it together with Workflow Series and Parallel to facilitate the use of calculations and other asynchronous resources
  • Perfectly compatible with all Workflow functions, such as name service, upstream and other components
  • Report Tracing to OpenTelemetry
  • Report Metrics to OpenTelemetry and Prometheus
  • More features...

Installation

srpc has been packaged for Debian and Fedora. Therefore, we can install it from source code or from the package in the system.

reference: Linux, MacOS, Windows Installation and Compilation Guide

Quick Start

Let's quickly learn how to use it in a few steps.

For more detailed usage, please refer to Documents and Tutorial.

1. example.proto

syntax = "proto3";// You can use either proto2 or proto3. Both are supported by srpc

message EchoRequest {
    string message = 1;
    string name = 2;
};

message EchoResponse {
    string message = 1;
};

service Example {
    rpc Echo(EchoRequest) returns (EchoResponse);
};

2. generate code

protoc 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

These compile commands are only for Linux system. On other system, complete cmake in tutorial is recommanded.

g++ -o server server.cc example.pb.cc -std=c++11 -lsrpc
g++ -o client client.cc example.pb.cc -std=c++11 -lsrpc

6. run

Terminal 1:

./server

Terminal 2:

./client

We can also use CURL to post Http request:

curl 127.0.0.1:8811/Example/Echo -H 'Content-Type: application/json' -d '{message:"from curl",name:"CURL"}'

Output of Terminal 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"

Output of Terminal 2:

message: "Hi, workflow"

Output of CURL:

{"message":"Hi, CURL"}

Benchmark

  • CPU 2-chip/8-core/32-processor Intel(R) Xeon(R) CPU E5-2630 v3 @2.40GHz
  • Memory all 128G
  • 10 Gigabit Ethernet
  • BAIDU brpc-client in pooled (connection pool) mode

QPS at cross-machine single client→ single server under different concurrency

Client = 1
ClientThread = 64, 128, 256, 512, 1024
RequestSize = 32
Duration = 20s
Server = 1
ServerIOThread = 16
ServerHandlerThread = 16

IMG

QPS at cross-machine multi-client→ single server under different client processes

Client = 1, 2, 4, 8, 16
ClientThread = 32
RequestSize = 32
Duration = 20s
Server = 1
ServerIOThread = 16
ServerHandlerThread = 16

IMG

QPS at same-machine single client→ single server under different concurrency

Client = 1
ClientThread = 1, 2, 4, 8, 16, 32, 64, 128, 256
RequestSize = 1024
Duration = 20s
Server = 1
ServerIOThread = 16
ServerHandlerThread = 16

IMG

QPS at same-machine single client→ single server under different request sizes

Client = 1
ClientThread = 100
RequestSize = 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768
Duration = 20s
Server = 1
ServerIOThread = 16
ServerHandlerThread = 16

IMG

Latency CDF for fixed QPS at same-machine single client→ single server

Client = 1
ClientThread = 50
ClientQPS = 10000
RequestSize = 1024
Duration = 20s
Server = 1
ServerIOThread = 16
ServerHandlerThread = 16
Outiler = 1%

IMG

Latency CDF for fixed QPS at cross-machine multi-client→ single server

Client = 32
ClientThread = 16
ClientQPS = 2500
RequestSize = 512
Duration = 20s
Server = 1
ServerIOThread = 16
ServerHandlerThread = 16
Outiler = 1%

IMG

Contact