72bf13a395
* add ubring transport * fix the bug for ub ring transport * fix the bug for ub ring transport and other * add the license for ub transport * Modifying the variable naming style * optimize the log message and some field name * fix some bug for ubring * add some log ubring endpoint * add todo * fix the bug for handshake for ub endpoint * fix the bug for client ub endpoint * optimize the iobuf file code * modify the log level * fix the declare_shm_ubs define not found bug * add the timer_mgr support for macos and format code style * fix the bug for macos epoll * fix the timespece bug * adaptor the itimerspec for macos platform * optimize the cmakelist config * add the ubring docs for ubring transport * modify some file name and directory structure * modify some code style and optimize code logical * add the cmake ubshm transport ci/testing * add the dependency header * bug fix the code * Fix UB shm allocation cleanup crashes (#11) Co-authored-by: 郭业昌 <lvpengfei@MacBook-Air.local> * remove the brpc_ubshm_unittest * Found and fixed two stability issues (#13) * 修复ubring server端关闭连接coredump问题 * 修复PollIn/PollOut解引用已释放Socket指针的问题 PollIn/PollOut通过ep->_socket(裸指针)读取data socket,当data socket 被销毁时该指针悬空,导致Socket::Address读到垃圾id触发SIGSEGV。 改为存储_socket_id(SocketId),用Address获取引用计数的Socket, 并在整个回调期间持有该引用,避免解引用悬空指针。 * 修复client非正常退出导致UBRING shm残留的问题 client被强杀(SIGTERM/崩溃/OOM)时teardown没跑完,localShm(_C)的 shm_unlink未执行,导致/dev/shm残留_C文件。server的remoteShm只munmap 不unlink(正确),无法清理client的名字。 在握手ESTABLISHED时(client/server都确认对方已mmap自己的localShm) 立即unlink localShm名字。此时对端已持有mmap引用,unlink只删名字不 影响通信;进程任意时刻退出都不会残留文件名。 * Address chenBright's review: use English comments and BAIDU_CACHELINE_ALIGNMENT - Convert all Chinese comments in ubshm to English (per chenBright's 'Please use English' on ub_endpoint.cpp:723, ub_ring.cpp:337, shm_ubs.cpp:316, and similar) - Replace __attribute__((aligned(64))) with BAIDU_CACHELINE_ALIGNMENT in ubr_msg.h (per chenBright's comment on ubr_msg.h:41) - Remove unnecessary TODO comment in ub_ring.cpp:551 (per chenBright's 'Unnecessary comments, please delete') * Remove unused lock macros in thread_lock.h Per chenBright's review, the functions and macros defined in thread_lock.h are largely unused. Verified usage across ubshm: - LOCK_GUARD / UnlockMutex: 8 call sites in shm_ubs.cpp and ub_ring_manager.cpp, kept. - SPIN_LOCK_GUARD, R_LOCK_GUARD, W_LOCK_GUARD, SEMAPHORE_WAIT_GUARD, SEMAPHORE_WAIT_GUARD_WITH_CLOSE and their helper functions (UnlockSpinLock, UnlockRWLock, PostSem, PostSemWithClose): 0 call sites, removed. * Apply chenBright's review on timer_mgr globals Per chenBright's review on timer_mgr.cpp:32-37: - Add explicit default values to uninitialized globals (g_total_timer_num=0, g_max_system_fd=0, g_epoll_execute_thread=0, g_timer_module_initialized=0) - Rename globals to snake_case (g_epollFd -> g_epoll_fd, g_totalTimerNum -> g_total_timer_num, g_timerFdCtxMap -> g_timer_fd_ctx_map, maxSystemFd -> g_max_system_fd, g_epollExecuteThread -> g_epoll_execute_thread, g_timerModuleInitialized -> g_timer_module_initialized) - maxSystemFd also gains the g_ prefix to match global naming style Also fix the missing std:: qualifier on atomic_fetch_sub/add/load (per chenBright's earlier comment on timer_mgr.cpp:80). * Change CloseTimerFd fd type from uint32_t to int Per chenBright's review on timer_mgr.cpp:399 (uint32_t -> int). fd is a system file descriptor; POSIX APIs use int and -1 denotes an invalid fd, which uint32_t cannot represent. Changed the CloseTimerFd signature (header + definition) and removed the now-unnecessary (uint32_t) casts at the two call sites. * Use BAIDU_LIKELY/BAIDU_UNLIKELY instead of custom __builtin_expect Per chenBright's review on common.h:27. Rather than redefine the macros with __builtin_expect directly, forward LIKELY/UNLIKELY to brpc's standard BAIDU_LIKELY/BAIDU_UNLIKELY (from butil/compiler_specific.h). The 122 call sites keep using LIKELY()/UNLIKELY() unchanged; only the macro bodies change, preserving semantics. * Add unit tests for UBShmEndpoint Per chenBright's request to add unit tests for UBShmTransport in this PR (rather than a follow-up). Adds test/brpc_ubring_unittest.cpp with tests covering the public interface of UBShmEndpoint under the g_skip_ub_init=true mode (which skips real shared-memory/poller setup): - construct_and_destruct: lifecycle safety - is_writable_false_when_skip_init: skip-mode behavior - reset_is_idempotent: Reset() is safe to call repeatedly The file follows the brpc_*_unittest.cpp naming convention so it is auto-collected by test/CMakeLists.txt's file(GLOB). Verified: compiles, links, and all 3 tests pass (g++ 15.2, C++17, gtest, BRPC_WITH_UBRING=ON). * Rewrite UBShmEndpoint unit tests with real coverage Per chenBright's feedback that the previous tests were too simple and did not cover the main methods. Source changes to enable testing: - Move HelloMessage struct declaration from ub_endpoint.cpp to ub_endpoint.h so tests can access it - Expose private members under #ifdef UNIT_TEST (precedent: butil/containers/stack_container.h) so tests can call AllocateClientResources without -Dprivate=public (which breaks GCC 15 + new libstdc++ <any>/<sstream>) Tests (9, all passing on Ubuntu 26.04 g++ 15.2 C++17 gtest): HelloMessageTest (5): serialize/deserialize roundtrip, network byte order verification, uint64 max boundary, full shm_name, toString UBShmEndpointTest (4): construct, real IPC shm AllocateClientResources (g_skip_ub_init=false), reset cleanup, reset idempotency * rename the variable to snake_case style --------- Co-authored-by: YeChang Guo <52730608+YChange01@users.noreply.github.com> Co-authored-by: 郭业昌 <lvpengfei@MacBook-Air.local> Co-authored-by: gure <740684863@qq.com>
119 lines
7.2 KiB
Markdown
119 lines
7.2 KiB
Markdown
[中文版](README_cn.md)
|
|
|
|
[](https://github.com/apache/brpc/actions/workflows/ci-linux.yml)
|
|
[](https://github.com/apache/brpc/actions/workflows/ci-macos.yml)
|
|
|
|

|
|

|
|
|
|
[bRPC](https://brpc.apache.org/) is an Industrial-grade RPC framework using C++ Language, which is often used in high performance system such as Search, Storage, Machine learning, Advertisement, Recommendation etc.
|
|
|
|
### "bRPC" means "better RPC".
|
|
|
|
You can use it to:
|
|
* Build a server that can talk in multiple protocols (**on same port**), or access all sorts of services
|
|
* restful http/https, [h2](https://httpwg.org/specs/rfc9113.html)/[gRPC](https://grpc.io). using http/h2 in bRPC is much more friendly than [libcurl](https://curl.haxx.se/libcurl/). Access protobuf-based protocols with HTTP/h2+json, probably from another language.
|
|
* [redis](docs/en/redis_client.md) and [memcached](docs/en/memcache_client.md), thread-safe, more friendly and performant than the official clients.
|
|
* [rtmp](https://github.com/apache/brpc/blob/master/src/brpc/rtmp.h)/[flv](https://en.wikipedia.org/wiki/Flash_Video)/[hls](https://en.wikipedia.org/wiki/HTTP_Live_Streaming), for building [streaming services](https://github.com/brpc/media-server).
|
|
* hadoop_rpc (may be opensourced)
|
|
* [rdma](https://en.wikipedia.org/wiki/Remote_direct_memory_access) support
|
|
* [thrift](docs/en/thrift.md) support, thread-safe, more friendly and performant than the official clients.
|
|
* all sorts of protocols used in Baidu: [baidu_std](docs/en/baidu_std.md), [streaming_rpc](docs/en/streaming_rpc.md), hulu_pbrpc, [sofa_pbrpc](https://github.com/baidu/sofa-pbrpc), nova_pbrpc, public_pbrpc, ubrpc and nshead-based ones.
|
|
* Build [HA](https://en.wikipedia.org/wiki/High_availability) distributed services using an industrial-grade implementation of [RAFT consensus algorithm](https://raft.github.io) which is opensourced at [braft](https://github.com/brpc/braft)
|
|
* Servers can handle requests [synchronously](docs/en/server.md) or [asynchronously](docs/en/server.md#asynchronous-service).
|
|
* Clients can access servers [synchronously](docs/en/client.md#synchronus-call), [asynchronously](docs/en/client.md#asynchronous-call), [semi-synchronously](docs/en/client.md#semi-synchronous-call), or use [combo channels](docs/en/combo_channel.md) to simplify sharded or parallel accesses declaratively.
|
|
* Debug services [via http](docs/en/builtin_service.md), and run [cpu](docs/en/cpu_profiler.md), [heap](docs/en/heap_profiler.md) and [contention](docs/en/contention_profiler.md) profilers.
|
|
* Get [better latency and throughput](docs/en/overview.md#better-latency-and-throughput).
|
|
* [Extend bRPC](docs/en/new_protocol.md) with the protocols used in your organization quickly, or customize components, including [naming services](docs/en/load_balancing.md) (dns, zk, etcd), [load balancers](docs/en/load_balancing.md) (rr, random, consistent hashing)
|
|
|
|
# Try it!
|
|
|
|
* Read [overview](docs/en/overview.md) to know where bRPC can be used and its advantages.
|
|
* Read [getting started](docs/en/getting_started.md) for building steps and play with [examples](https://github.com/apache/brpc/tree/master/example/).
|
|
* Docs:
|
|
* [Performance benchmark](docs/en/benchmark.md)
|
|
* [bvar](docs/en/bvar.md)
|
|
* [bvar_c++](docs/en/bvar_c++.md)
|
|
* [bthread](docs/en/bthread.md)
|
|
* [bthread or not](docs/en/bthread_or_not.md)
|
|
* [thread-local](docs/en/thread_local.md)
|
|
* [Execution Queue](docs/en/execution_queue.md)
|
|
* [bthread tracer](docs/en/bthread_tracer.md)
|
|
* [bthread tagged task group](docs/en/bthread_tagged_task_group.md)
|
|
* Client
|
|
* [Basics](docs/en/client.md)
|
|
* [Error code](docs/en/error_code.md)
|
|
* [Combo channels](docs/en/combo_channel.md)
|
|
* [Access http/h2](docs/en/http_client.md)
|
|
* [Access gRPC](docs/en/http_derivatives.md#h2grpc)
|
|
* [Access thrift](docs/en/thrift.md#client-accesses-thrift-server)
|
|
* [Access UB](docs/en/ub_client.md)
|
|
* [Streaming RPC](docs/en/streaming_rpc.md)
|
|
* [Access redis](docs/en/redis_client.md)
|
|
* [Access memcached](docs/en/memcache_client.md)
|
|
* [Backup request](docs/en/backup_request.md)
|
|
* [Dummy server](docs/en/dummy_server.md)
|
|
* Server
|
|
* [Basics](docs/en/server.md)
|
|
* [Serve http/h2](docs/en/http_service.md)
|
|
* [Serve gRPC](docs/en/http_derivatives.md#h2grpc)
|
|
* [Serve thrift](docs/en/thrift.md#server-processes-thrift-requests)
|
|
* [Serve Nshead](docs/en/nshead_service.md)
|
|
* [Debug server issues](docs/en/server_debugging.md)
|
|
* [Server push](docs/en/server_push.md)
|
|
* [Avalanche](docs/en/avalanche.md)
|
|
* [Auto ConcurrencyLimiter](docs/en/auto_concurrency_limiter.md)
|
|
* [Media Server](https://github.com/brpc/media-server)
|
|
* [json2pb](docs/en/json2pb.md)
|
|
* [Builtin Services](docs/en/builtin_service.md)
|
|
* [status](docs/en/status.md)
|
|
* [vars](docs/en/vars.md)
|
|
* [connections](docs/en/connections.md)
|
|
* [flags](docs/en/flags.md)
|
|
* [rpcz](docs/en/rpcz.md)
|
|
* [cpu_profiler](docs/en/cpu_profiler.md)
|
|
* [heap_profiler](docs/en/heap_profiler.md)
|
|
* [contention_profiler](docs/en/contention_profiler.md)
|
|
* Tools
|
|
* [rpc_press](docs/en/rpc_press.md)
|
|
* [rpc_replay](docs/en/rpc_replay.md)
|
|
* [rpc_view](docs/en/rpc_view.md)
|
|
* [benchmark_http](docs/en/benchmark_http.md)
|
|
* [parallel_http](docs/en/parallel_http.md)
|
|
* Others
|
|
* [IOBuf](docs/en/iobuf.md)
|
|
* [Streaming Log](docs/en/streaming_log.md)
|
|
* [FlatMap](docs/en/flatmap.md)
|
|
* [Coroutine](docs/en/coroutine.md)
|
|
* [Circuit Breaker](docs/en/circuit_breaker.md)
|
|
* [UBRing](docs/en/ubring.md)
|
|
* [RDMA](docs/en/rdma.md)
|
|
* [Bazel Support](docs/en/bazel_support.md)
|
|
* [Wireshark baidu_std dissector plugin](docs/en/wireshark_baidu_std.md)
|
|
* [bRPC introduction](docs/cn/brpc_intro.pptx)(training material)
|
|
* [A tutorial on building large-scale services](docs/en/tutorial_on_building_services.pptx)(training material)
|
|
* [bRPC internal](docs/en/brpc_internal.pptx)(training material)
|
|
* RPC in depth
|
|
* [New Protocol](docs/en/new_protocol.md)
|
|
* [Atomic instructions](docs/en/atomic_instructions.md)
|
|
* [IO](docs/en/io.md)
|
|
* [Threading Overview](docs/en/threading_overview.md)
|
|
* [Load Balancing](docs/en/load_balancing.md)
|
|
* [Locality-aware](docs/en/lalb.md)
|
|
* [Consistent Hashing](docs/en/consistent_hashing.md)
|
|
* [Memory Management](docs/en/memory_management.md)
|
|
* [Timer keeping](docs/en/timer_keeping.md)
|
|
* [bthread_id](docs/en/bthread_id.md)
|
|
* Use cases
|
|
* [User cases](community/cases.md)
|
|
|
|
# Contribute code
|
|
Please refer to [here](CONTRIBUTING.md).
|
|
|
|
# Feedback and Getting involved
|
|
* Report bugs, ask questions or give suggestions by [Github Issues](https://github.com/apache/brpc/issues)
|
|
* Subscribe to the mailing list(dev-subscribe@brpc.apache.org) to get updated with the project
|
|
|
|
# Code of Conduct
|
|
We follow the code of conduct from Apache Software Foundation, please refer it here [Link](https://www.apache.org/foundation/policies/conduct)
|