Skip to content

Akzestia/ZTX

Repository files navigation

ZTX

ZTX - a simple, fast RoQ (RPC over QUIC) framework, built using TQUIC.

Performance

ZTX can be as fast as 4x the speed of gRPC, but you should note that ZTX contains a wide range of specific optimizations, so creating a fair benchmark is a bit complicated

Usage

Setting up server

fn main() -> Result<()> {
    let mut settings = ServerSettings::default();
    settings.listen = "0.0.0.0:4433".parse().unwrap();
    // Optional: set max amount of workers
    settings.workers = num_cpus::get();

    run_server(settings)
}

Register RPC (Server side)

// Define echo RPC
#[rpc("echo")]
pub async fn echo(_ctx: RpcContext, input: Vec<u8>) -> RpcResult<Vec<u8>> {
    Ok(input)
}

// Register RPC
fn main() -> Result<()> {
    // You must register ALL of your defined RPCs before run_server()
    register_rpc(&RPC_ECHO);

    // Server setup
    // ...
    run_server(settings)
}

Setting up client

#[tokio::main]
async fn main() -> Result<()> {
    let server: SocketAddr = "127.0.0.1:4433".parse().unwrap();
    // Optional: log connection
    info!("connecting to {}", server);

    let mut client = QuicRpcClient::builder(server).idle_timeout(5_000).build()?;
}

Calling RPC (Client side)

// RPC with payload
let resp = client.call_with("echo", b"hello world")?;
println!("echo => {}", String::from_utf8_lossy(&resp));
// RPC without payload
let _ = client.call("ping")?;

Docs

More info available in docs folder

License MIT

About

ZTX - a simple, fast RoQ (RPC over QUIC) framework, built using TQUIC.

Topics

Resources

License

Stars

Watchers

Forks