A light-weight RPC implement of google protobuf RPC framework.

Overview

sofa-pbrpc

Build Status Join the chat at https://gitter.im/sofa-pbrpc/rpc Coverity Scan Build Status

A light-weight RPC implementation of Google's protobuf RPC framework.

Wiki: https://github.com/baidu/sofa-pbrpc/wiki

Features

  • High performace.
  • Easy to use. Refer to sample code in './sample'.
  • Supports sync call and async call. Refer to './sample/echo'.
  • Supports three level (service/method/request) timeout. Refer to './sample/timeout_sample'.
  • Supports transparent compression. Refer to './sample/compress_sample'.
  • Supports mock test. Refer to './sample/mock_sample'.
  • Supports network flow control.
  • Supports auto connecting and reconnecting.
  • Supports keep alive time of idle connections.
  • Supports statistics for profiling.
  • Supports multi-server load balance and fault tolerance.
  • Supports http protocol.
  • Provides web monitor.
  • Provides python client library.

Dependencies

This lib depends on boost-1.53.0 (only need header), protobuf-2.4.1, snappy and zlib:

ATTENTION: boost header is only needed when compiling the lib, but is not needed for user code.

Extrally, './unit-test' and './sample/mock_sample' also depends on gtest:

Build

  1. Modify the file './depends.mk' to specify depending libs.
    The necessary libs are boost, protobuf, snappy, and zlib.
  2. Run 'make' to build sofa-pbrpc.
    The default optimization level is 'O2'.
    To change it, modify the 'OPT' variable in file './Makefile'.
  3. Run 'make install' to install sofa-pbrpc.
    The default install directory is './output'.
    To change it, modify the 'PREFIX' variable in file './Makefile'.

For more details, please refer to the wiki Build Guide.

Sample

For sample code, please refer to './sample' and the wiki Quick Start.

Profiling

For Profiling feature, please refer to the wiki Profiling.

Performance

For performace details, please refer to the wiki Performance.

Implementation

For implementation details, please refer to the wiki and file doc/sofa-pbrpc-document.md.

Support

[email protected]

Issues
  • RpcServer 调用stop之后,程序core dump。

    RpcServer 调用stop之后,程序core dump。

    #0 0x00007f89817f4625 in raise () from /lib64/libc.so.6 #1 0x00007f89817f5e05 in abort () from /lib64/libc.so.6 #2 0x00007f898204fa55 in __gnu_cxx::__verbose_terminate_handler () at ../../.././libstdc++-v3/libsupc++/vterminate.cc:95 #3 0x00007f898204dbf6 in __cxxabiv1::__terminate (handler=) at ../../.././libstdc++-v3/libsupc++/eh_terminate.cc:38 #4 0x00007f898204dc23 in std::terminate () at ../../.././libstdc++-v3/libsupc++/eh_terminate.cc:48 #5 0x00007f898204e6df in __cxxabiv1::__cxa_pure_virtual () at ../../.././libstdc++-v3/libsupc++/pure.cc:50 #6 0x0000000000631318 in sofa::pbrpc::RpcByteStream::on_connect(boost::system::error_code const&) () #7 0x000000000062aaed in boost::asio::detail::reactive_socket_connect_op<boost::bi::bind_t<void, boost::mfi::mf1<void, sofa::pbrpc::RpcByteStream, boost::system::error_code const&>, boost::bi::list2boost::bi::value<sofa::pbrpc::shared_ptr<sofa::pbrpc::RpcByteStream >, boost::arg<1> > > >::do_complete(boost::asio::detail::task_io_service, boost::asio::detail::task_io_service_operation, boost::system::error_code const&, unsigned long) () #8 0x000000000062dee9 in boost::asio::detail::epoll_reactor::descriptor_state::do_complete(boost::asio::detail::task_io_service, boost::asio::detail::task_io_service_operation, boost::system::error_code const&, unsigned long) () #9 0x000000000063081e in boost::asio::detail::task_io_service::run(boost::system::error_code&) () #10 0x000000000063118e in sofa::pbrpc::ThreadGroupImpl::thread_run(void*) () #11 0x00007f89827749d1 in start_thread () from /lib64/libpthread.so.0

    opened by gandalf000 33
  • 当client通过http以json格式发送数据时server 2s才会收到请求

    当client通过http以json格式发送数据时server 2s才会收到请求

    不知道是json字段太多导致的还是json数据包太大导致的 请问谁能帮忙回答下吗

    opened by fengyindiehun 14
  • 客户端与服务端连接释放问题请教

    客户端与服务端连接释放问题请教

    hi 客户端和服务端建立链接后 关闭服务端,发现客户端和服务的链接仍然处于ESTABLISHED状态 我看客户端有定时检测机制 超过keep_alive_time会主动发起关闭 但是没有生效,帮忙看下

    谢谢

    opened by panshiming 13
  • 支持用户自定义web请求的处理函数

    支持用户自定义web请求的处理函数

    主要改动

    • 增加WebService类
    • 路由及拼装页面从HttpRpcRequest中移至WebService中
    • 提供用户RegisterWebServlet接口以及HttpRequest和HttpResponse的数据结构

    功能描述

    • 用户使用RegisterWebServlet接口,注册路径及其处理函数,rpc框架收到http请求后准发至用户函数并返回
    • 用户现在可以覆盖框架默认的处理函数
    • 假如用户只注册了 /dfs 路径,那么 /dfs/* 都会被转发到 /dfs 的处理函数
    opened by cyshi 11
  • Add timeout to connect action

    Add timeout to connect action

    A new option of rpc_controller connect_timeout is used for connect action.

    When rpc_client use rpc_stream to create a connect, it will use rpc_controller::connect_timeout for connect action if it is > 0.

    The default of rpc_controller::connect_timeout is -1.

    Signed-off-by: Dong Yuan [email protected]

    opened by yuandong1222 11
  • 不用官方的客户端程序,要发RPC数据吗?

    不用官方的客户端程序,要发RPC数据吗?

    你好, 我们打算用这套框架做游戏服务器,但是客户端是基于Unity的C#开发,所以想扩展到根据,不同Message不同处理的模式,客户端如果自己重新写,要改RPCDATA吧?多谢。

    opened by LazyPlanet 9
  • Bazel build

    Bazel build

    Hi,

    I've added Bazel config files to allow reproductible builds. I tested them on OS X and Linux (Ubuntu).

    When building using Bazel, it will download all required dependencies and will compile static binaries for host platform.

    To build sofa-pbrpc-client, run:

    $ bazel build sofa-pbrpc-client
    

    To build examples:

    $ bazel build sample/compress_sample:server
    $ bazel build sample/compress_sample:client
    
    $ bazel-bin/sample/compress_sample/server
    $ bazel-bin/sample/compress_sample/client
    
    opened by teodor-pripoae 9
  • client大包发送速率较低

    client大包发送速率较低

    client的发送速率受限于boost::socket的发送速率(async_write_some ~ on_write_some间的延迟),当发送较大的数据包时,如果数据跨越多个bufhandle,发送速率会成比例下降。可通过提高bufhandle的大小,降低buf数来提高大包发送速率。

    opened by 00k 8
  • 请问支持windows环境吗?

    请问支持windows环境吗?

    请问支持windows环境吗?

    opened by markqiu 8
  • RpcClientImpl 在调用stop的时候hung死

    RpcClientImpl 在调用stop的时候hung死

    栈状态 #0 0x00007f1834e7b22d in pthread_join () from /lib64/libpthread.so.0 #1 0x00000000006215ab in sofa::pbrpc::ThreadGroupImpl::stop (this=0x228f6b0) at src/sofa/pbrpc/thread_group_impl.h:182 #2 0x00000000006176c7 in sofa::pbrpc::RpcClientImpl::Stop (this=0x22be000) at src/sofa/pbrpc/rpc_client_impl.cc:109

    查看io_service的内存信息如下 (gdb) p *(boost::asio::detail::task_io_service * const) 0x22738e0 $26 = {boost::asio::detail::service_baseboost::asio::detail::task_io_service = {boost::asio::io_service::service = {boost::noncopyable_::noncopyable = {}, vptr.service = 0xa24a90 <vtable for boost::asio::detail::task_io_service+16>, key = {type_info_ = 0xa245a0 <typeinfo for boost::asio::detail::typeid_wrapperboost::asio::detail::task_io_service>, id_ = 0x0}, owner_ = @0x228f6d0, next_ = 0x0}, static id = {boost::asio::io_service::id = {boost::noncopyable_::noncopyable = {}, }, }}, one_thread_ = false, mutex_ = {boost::noncopyable_::noncopyable = {}, mutex_ = {__data = {__lock = 0, __count = 0, __owner = 0, _nusers = 7, kind = 0, spins = 0, list = { prev = 0x0, next = 0x0}}, size = '\000' <repeats 12 times>, "\a", '\000' <repeats 26 times>, align = 0}}, task = 0x2266e10, task_operation = {boost::asio::detail::task_io_service_operation = {next = 0x0, func = 0x0, task_result = 0}, }, task_interrupted = false, outstanding_work = {value = 3}, op_queue = {boost::noncopyable::noncopyable = {}, front = 0x0, back = 0x0}, stopped = false, shutdown = false, first_idle_thread = 0x7f182991fce0}

    我理解调用后stop函数后task_io_service 的 outstanding_work_变量会被减为0 并退出他的run函数。 从而使得pthread_join函数成功返回。可能的问题点在哪里呢?

    opened by baimushan 7
  • 有没有这种服务互相调用的方法

    有没有这种服务互相调用的方法

    例子中的接收到什么输出什么

    询问一下,如何在处理的时候再去调用别的处理 类似有几部需要处理,怎么能自动触发下一步,我这里现在是两步 怎么能再第一个Echo中调用Echo2

    class EchoServerImpl : public sofa::pbrpc::test::EchoServer { public: EchoServerImpl() {} virtual ~EchoServerImpl() {}

    private: virtual void Echo(google::protobuf::RpcController* controller, const sofa::pbrpc::test::EchoRequest* request, sofa::pbrpc::test::EchoResponse* response, google::protobuf::Closure* done) { sofa::pbrpc::RpcController* cntl = static_castsofa::pbrpc::RpcController*(controller); SLOG(INFO, "Echo(): request message from %s: %s", cntl->RemoteAddress().c_str(), request->message().c_str()); if (cntl->IsHttp()) { SLOG(INFO, "HTTP-PATH="%s"", cntl->HttpPath().c_str()); std::map<std::string, std::string>::const_iterator it; const std::map<std::string, std::string>& query_params = cntl->HttpQueryParams(); for (it = query_params.begin(); it != query_params.end(); ++it) { SLOG(INFO, "QueryParam["%s"]="%s"", it->first.c_str(), it->second.c_str()); } const std::map<std::string, std::string>& headers = cntl->HttpHeaders(); for (it = headers.begin(); it != headers.end(); ++it) { SLOG(INFO, "Header["%s"]="%s"", it->first.c_str(), it->second.c_str()); } } response->set_message("echo message: " + request->message()); done->Run(); } virtual void Echo2(google::protobuf::RpcController* controller, const sofa::pbrpc::test::EchoRequest* request, sofa::pbrpc::test::EchoResponse* response, google::protobuf::Closure* done) { sofa::pbrpc::RpcController* cntl = static_castsofa::pbrpc::RpcController*(controller); SLOG(INFO, "Echo(): request message from %s: %s", cntl->RemoteAddress().c_str(), request->message().c_str()); if (cntl->IsHttp()) { SLOG(INFO, "HTTP-PATH="%s"", cntl->HttpPath().c_str()); std::map<std::string, std::string>::const_iterator it; const std::map<std::string, std::string>& query_params = cntl->HttpQueryParams(); for (it = query_params.begin(); it != query_params.end(); ++it) { SLOG(INFO, "QueryParam["%s"]="%s"", it->first.c_str(), it->second.c_str()); } const std::map<std::string, std::string>& headers = cntl->HttpHeaders(); for (it = headers.begin(); it != headers.end(); ++it) { SLOG(INFO, "Header["%s"]="%s"", it->first.c_str(), it->second.c_str()); } } response->set_message("echo message: " + request->message()); done->Run(); } };

    opened by JackyLucifer 0
  • 关于volatile变量相关的问题

    关于volatile变量相关的问题

    看了代码中有很多volatile修饰的变量,目的是什么,为了statistics更加准确以及为了使用sofa-pbrpc中提供的原子操作吗? 代码中有这样的注释: // And here we need not lock "_pending_lock" because the "_pending_message_count" is // an volatile value. 请教一下volatile与锁有关系吗?

    opened by pengwang7 0
  • server端如何主动发消息?

    server端如何主动发消息?

    如题

    opened by hjhj111 0
  • bugs on weak memory model arch.(arm/power)

    bugs on weak memory model arch.(arm/power)

    RpcMessageStream::try_start_send() 1can miss pending messages because it first performs a relaxed load of _send_token which can miss store/store_release of _send_token.

    RpcMessageStream::get_from_pending_queue() 2can miss pending messages because it performs a relaxed load of _pending_message_count before entering the critical section guarded by _pending_lock, again, the relaxed load can miss store/store_release of _pending_message_count.

    With the above two defects combined, the current message calling try_start_send() and the previous message calling get_from_pending_queue() (on_write_some() ---> try_start_send() ---> get_from_pending_queue() ) both may miss the chance to send the current pending message, which lead to the current pending message siting idle in _pending_callsuntil timeout.

    I believe the scenario described above is quite likely to happen under weak memory model such as aarch64 and ppc64.

    opened by zergvszerg 0
  • server如何主动向client发送消息?

    server如何主动向client发送消息?

    demo里面的消息都是client发起,server回复。如何实现server主动向server发消息?

    opened by RgznLbq 1
  • 内存问题

    内存问题

    NewClosure产生的指针什么时候释放?连续new client70个时导致内存不够而崩溃。

    opened by RgznLbq 2
  • CPU使用问题

    CPU使用问题

    为什么运行multi_server_sample中的server一个client都没有就会占用20%以上的cpu?

    opened by RgznLbq 3
  • 什么时候支持window?

    什么时候支持window?

    环境:win10+QT+mingw32。boost、protobuf、zlib、snappy都可以单独在这个环境下使用,但是sofa-pbrpc还是有一堆清理不完的报错。求教怎样才能在这个环境下使用。

    opened by RgznLbq 2
  • Too many threads in sofa ,how use epoll to overlap large number of socket events

    Too many threads in sofa ,how use epoll to overlap large number of socket events

    Too many threads in sofa ,how use epoll to overlap large number of socket events?thank you

    opened by Cooliodtryl 2
  • sofa-pbrpc-client health超时

    sofa-pbrpc-client health超时

    机器负载不重 十秒钟调用一次,一天会出现几十次health情况

    opened by namelij 0
Releases(v1.1.3)
Owner
Baidu
Baidu Open Source Projects
Baidu
PHP Protobuf - Google's Protocol Buffers for PHP

This repository is no longer maintained Since Google's official Protocol Buffers supports PHP language, it's unjustifiable to maintain this project. P

Allegro Tech 908 Dec 22, 2021
Php-rpc-server - JSON RPC server implementation for PHP.

JSON RPC Server implementation for PHP. The json-rpc is a very simple protocol. You can see this by reading the protocol specification. This library i

null 4 Dec 25, 2021
Weight conversions in PHP

Weight conversions in PHP This is where your description should go. Try and limit it to a paragraph or two. Consider adding a small example. Installat

Spatie 2 Nov 12, 2021
Inventory manager - Light Bootstrap Dashboard

Light Bootstrap Dashboard is an admin dashboard template designed to be beautiful and simple. It is built on top of Bootstra

Ranaivonampoizina Mikajy 1 Nov 17, 2021
Calibre OPDS (and HTML) PHP Server : web-based light alternative to Calibre content server / Calibre2OPDS to serve ebooks (epub, mobi, pdf, ...)

COPS COPS stands for Calibre OPDS (and HTML) Php Server. See : COPS's home for more details. Don't forget to check the Wiki. Why ? In my opinion Calib

Sébastien Lucas 1.2k Jan 17, 2022
The light version of NexoPOS 4.x, which is a web-Based Point Of Sale (POS) System build with Laravel, TailwindCSS, and Vue.Js.

About NexoPOS 4.x NexoPOS 4 is a free point of sale system build using Laravel, TailwindCSS, Vue and other open-source resources. This POS System focu

Blair Jersyer 103 Jan 19, 2022
A cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services.

Motan Overview Motan is a cross-language remote procedure call(RPC) framework for rapid development of high performance distributed services. Related

Weibo R&D Open Source Projects 5.8k Jan 12, 2022
Tars is a high-performance RPC framework based on name service and Tars protocol, also integrated administration platform, and implemented hosting-service via flexible schedule.

TARS - A Linux Foundation Project TARS Foundation Official Website TARS Project Official Website WeChat Group: TARS01 WeChat Offical Account: TarsClou

THE TARS FOUNDATION PROJECTS 9.3k Jan 13, 2022
The only way to implement the pipe operator in PHP.

Pipe Operator in PHP Introduction This package is based on the pipe operator RFC by Sara Golemon and Marcelo Camargo (2016), who explains the problem

BoostPHP 19 Dec 9, 2021
a simple pastebin implement in php

alcohol/pastebin-php I mostly use this demo application to keep myself up to date with the various changes introduced by new (major) Symfony releases.

Rob 22 Jan 10, 2022
Here are few exercises to practice how to implement API Security with NGINX App-Protect WAF.

api-security-lab This repo contains files for customers and partners to practice an API Security with NGINX App-Protect WAF. To demonstrate the capabi

null 3 Nov 18, 2021
Simple class that implement a CAPTCHA for your PHP App.

simple-captcha Simple class that implement a CAPTCHA for your PHP App. Installation Use the package manager composer to install. composer require will

WILLIAM B. SAMPAIO 2 Dec 3, 2021
Hprose is a cross-language RPC. This project is Hprose 3.0 for PHP

Hprose 3.0 for PHP Introduction Hprose is a High Performance Remote Object Service Engine. It is a modern, lightweight, cross-language, cross-platform

Hprose 2k Jan 12, 2022
Hprose RPC 服务 in Laravel/Lumen

基于 hprose/hprose-php 开发的Laravel扩展:whereof/laravel-hprose

wangzhiqiang 6 Dec 23, 2021
Zilliqa PHP is a typed PHP-7.1+ interface to Zilliqa JSON-RPC API.

Zilliqa PHP is a typed PHP-7.1+ interface to Zilliqa JSON-RPC API. Check out the latest API documentation. Add library in a composer.json file.

Patrick Falize 6 Oct 7, 2021
Simple XML-RPC API

Readme Ripcord: Easy XML-RPC Client and Server for PHP 5 ========================================================================

Saravanakumar Arumugam 1 Nov 22, 2021
:passport_control: Helper for Google's new noCAPTCHA (reCAPTCHA v2 & v3)

noCAPTCHA (new reCAPTCHA) By ARCANEDEV© What is reCAPTCHA? reCAPTCHA is a free service that protects your site from spam and abuse. It uses advanced r

ARCANEDEV 325 Dec 16, 2021
Adds a header to every response to try and twart Google's usage of your site in it's FLoC tracking method.

Laravel No FLoC This package will add the Permissions-Policy: interest-cohort=() to try and twart Google's usage of your site in it's FLoC tracking me

Jean-Philippe Murray 11 Jul 28, 2021
Get mobile app version and other related data from Google Play Store, Apple App Store and Huawei AppGallery

Mobile App Version Get mobile app version and other related data from Google Play Store, Apple App Store and Huawei AppGallery. Installation Add to co

Omer Salaj 11 Aug 31, 2021