https://github.com/sile/fibers_rpc
Rust RPC library built on top of fibers crate
https://github.com/sile/fibers_rpc
asynchronous rpc rust
Last synced: about 1 month ago
JSON representation
Rust RPC library built on top of fibers crate
- Host: GitHub
- URL: https://github.com/sile/fibers_rpc
- Owner: sile
- License: mit
- Created: 2018-03-07T03:57:48.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2020-09-07T14:36:06.000Z (over 4 years ago)
- Last Synced: 2025-03-25T07:12:39.160Z (about 2 months ago)
- Topics: asynchronous, rpc, rust
- Language: Rust
- Size: 199 KB
- Stars: 7
- Watchers: 3
- Forks: 3
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
fibers_rpc
==========[](https://crates.io/crates/fibers_rpc)
[](https://docs.rs/fibers_rpc)
[](https://travis-ci.org/sile/fibers_rpc)
[](https://codecov.io/gh/sile/fibers_rpc/branch/master)
[](LICENSE)Rust RPC library built on top of [fibers] crate.
[Documentation](https://docs.rs/fibers_rpc)
[fibers]: https://github.com/dwango/fibers-rs
Features
---------- Asynchronous RPC server/client using [fibers] crate
- Support two type of RPC:
- Request/response model
- Notification model
- Strongly typed RPC using [bytecodec] crate
- You can treat arbitrarily Rust structures that support [serde] as RPC messages
- It is possible to handle huge structures as RPC messages without compromising efficiency and real-time property by implementing your own encoder/decoder
- Multiplexing multiple RPC messages in a single TCP stream
- Prioritization between messages
- Expose [Prometheus] metrics[fibers]: https://github.com/dwango/fibers-rs
[bytecodec]: https://github.com/sile/bytecodec
[serde]: https://crates.io/crates/serde
[Prometheus]: https://prometheus.io/Technical Details
-----------------See [doc/].
[doc/]: https://github.com/sile/fibers_rpc/tree/master/doc
Examples
--------Simple echo RPC server:
```rust
use bytecodec::bytes::{BytesEncoder, RemainingBytesDecoder};
use fibers_rpc::{Call, ProcedureId};
use fibers_rpc::client::ClientServiceBuilder;
use fibers_rpc::server::{HandleCall, Reply, ServerBuilder};
use futures::Future;// RPC definition
struct EchoRpc;
impl Call for EchoRpc {
const ID: ProcedureId = ProcedureId(0);
const NAME: &'static str = "echo";type Req = Vec;
type ReqEncoder = BytesEncoder>;
type ReqDecoder = RemainingBytesDecoder;type Res = Vec;
type ResEncoder = BytesEncoder>;
type ResDecoder = RemainingBytesDecoder;
}// RPC server
struct EchoHandler;
impl HandleCall for EchoHandler {
fn handle_call(&self, request: ::Req) -> Reply {
Reply::done(request)
}
}
let server_addr = "127.0.0.1:1919".parse().unwrap();
let mut builder = ServerBuilder::new(server_addr);
builder.add_call_handler(EchoHandler);
let server = builder.finish(fibers_global::handle());
fibers_global::spawn(server.map_err(|e| panic!("{}", e)));// RPC client
let service = ClientServiceBuilder::new().finish(fibers_global::handle());
let service_handle = service.handle();
fibers_global::spawn(service.map_err(|e| panic!("{}", e)));let request = Vec::from(&b"hello"[..]);
let response = EchoRpc::client(&service_handle).call(server_addr, request.clone());
let response = fibers_global::execute(response)?;
assert_eq!(response, request);
```Informal benchmark result (v0.2.1):
```console
$ uname -a
Linux DESKTOP 4.4.0-43-Microsoft #1-Microsoft Wed Dec 31 14:42:53 PST 2014 x86_64 x86_64 x86_64 GNU/Linux$ lscpu | grep 'Model name:'
Model name: Intel(R) Core(TM) i7-7660U CPU @ 2.50GHz// Runs the example echo server in a shell.
$ cargo run --example echo --release -- server// Executes a benchmark command in another shell.
$ echo "hello" | cargo run --example echo --release -- bench -c 1024 -n 1000000
# ELAPSED: 8.111424
# RPS: 123282.91555218912
```