Exploring PhxRPC: A Lightweight High-Performance RPC Framework for Backend Development
PhxRPC is a compact, 450KB RPC framework from the WeChat backend team that uses Protobuf for IDL, offers semi‑sync/async processing with Epoll‑based IO threads, provides built‑in overload protection, and includes performance benchmarks, usage instructions, and code generation details.
Overview
Uses Protobuf as IDL to describe RPC interfaces and data structures.
Automatically generates client and server code from Protobuf files.
Hybrid sync‑async model with independent IO threads managed by Epoll and a fixed‑size worker thread pool; IO and workers communicate via memory queues.
Built‑in overload protection that adapts dynamically without manual thresholds.
Simple client/server configuration loading.
Supports Google’s Backup Requests pattern via lambda‑based concurrent server access.
Limitations
Does not support multi‑process mode.
Performance
Benchmark using the Search RPC C/S sample under idle worker conditions.
Test Environment
CPU: 24 x Intel(R) Xeon(R) CPU E5-2620 v3 @ 2.40GHz
Memory: 32 GB
Network: 1 Gbps
Ping between client/server: 0.05 ms
Concurrent request threads: 1000
Business data size (excluding HTTP header): 20 B
Worker threads: 20Short Connection QPS
System (1 thread): 4.1w
System (3 threads): 8.5w
System (8 threads): 9.0w
System (20 threads): 9.2w
Boost (1 thread): 4.5w
Boost (3 threads): 9.5w
Boost (8 threads): 9.5w
Boost (20 threads): 9.5wLong Connection QPS
System (1 thread): 5.5w
System (3 threads): 16w
System (8 threads): 36w
System (20 threads): 50w
Boost (1 thread): 6.2w
Boost (3 threads): 17.5w
Boost (8 threads): 41w
Boost (20 threads): 50wHow to Use
Write proto file
Example proto file is shown below.
Generate code
(PhxRPC root)/codegen/phxrpc_pb2server -I (PhxRPC root) -I (Protobuf include) -f (proto path) -d (output dir)
# sample
../codegen/phxrpc_pb2server -I ../ -I ../third_party/protobuf/include -f search.proto -d .After running the tool, execute make in the output directory to generate all RPC code.
Enable Boost optimization
Edit the generated Makefile to uncomment the Boost LDFLAGS line, then run make clean && make. Ensure the Boost plugin for PhxRPC is compiled first.
Add custom code
Server implementation (xxx_service_impl.cpp)
Client implementation (xxx_client.cpp)
Client concurrent call example
The following macros are provided by PhxRPC for coroutine handling: uthread_begin, uthread_end, uthread_s, uthread_t. They enable implementation of Google’s Backup Requests pattern, where two servers are called concurrently and the first response ends the operation. The macros allow writing asynchronous I/O in a synchronous style.
Server configuration (xxx_server.conf)
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
WeChat Backend Team
Official account of the WeChat backend development team, sharing their experience in large-scale distributed system development.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
