• Stars
    star
    196
  • Rank 198,553 (Top 4 %)
  • Language
    Rust
  • License
    Apache License 2.0
  • Created over 5 years ago
  • Updated about 1 month ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Rust implementation of ttrpc (GRPC for low-memory environments)

ttrpc-rust

ttrpc-rust is a non-core subproject of containerd

ttrpc-rust is the Rust version of ttrpc. ttrpc is GRPC for low-memory environments.

The ttrpc compiler of ttrpc-rust ttrpc_rust_plugin is modified from gRPC compiler of gRPC-rs grpcio-compiler.

Usage

1. Generate with protoc command

To generate the sources from proto files:

  1. Install protoc from github.com/protocolbuffers/protobuf

  2. Install protobuf-codegen

cargo install --force protobuf-codegen
  1. Install ttrpc_rust_plugin from ttrpc-rust/compiler
cd ttrpc-rust/compiler
cargo install --force --path .
  1. Generate the sources:
$ protoc --rust_out=. --ttrpc_out=. --plugin=protoc-gen-ttrpc=`which ttrpc_rust_plugin` example.proto

2. Generate programmatically

API to generate .rs files to be used e. g. from build.rs.

Example code:

fn main() {
    protoc_rust_ttrpc::Codegen::new()
        .out_dir("protocols")
        .inputs(&[
            "protocols/protos/agent.proto",
        ])
        .include("protocols/protos")
        .rust_protobuf() // also generate protobuf messages, not just services
        .run()
        .expect("Codegen failed.");
}

async/.await

ttrpc-rust supports async/.await. By using async/.await you can reduce the overhead and resource consumption caused by threads.

Usage

1. Generate codes in async version

Currently we only support generating async codes by using ttrpc-codegen

    ttrpc_codegen::Codegen::new()
        .out_dir("protocols/asynchronous")
        .inputs(&protos)
        .include("protocols/protos")
        .rust_protobuf()
        .customize(Customize {
            async_all: true, // It's the key option.
            ..Default::default()
        })
        .run()
        .expect("Gen async codes failed.");

Provide customize option

  • async_all: generate async codes for both server and client
  • async_server: generate async codes for server
  • async_client: generate async codes for client

See more in example/build.rs

2. Write your implemention in async/.await's way

Please follow the guidlines in example/async-server.rs and example/async-client.rs

Run Examples

  1. Go to the directory

    $ cd ttrpc-rust/example
    
  2. Start the server

    $ cargo run --example server
    

    or

    $ cargo run --example async-server
    
  3. Start a client

    $ cargo run --example client
    

    or

    $ cargo run --example async-client
    

Notes: the version of protobuf

protobuf-codegen, ttrpc_rust_plugin and your code should use the same version protobuf. You will get following fail if use the different version protobuf.

27 | const _PROTOBUF_VERSION_CHECK: () = ::protobuf::VERSION_2_8_0;
   |                                                 ^^^^^^^^^^^^^ help: a constant with a similar name exists: `VERSION_2_10_1`

The reason is that files generated by protobuf-codegen are compatible only with the same version of runtime

To fix this issue:

  1. Rebuild protobuf-codegen with new protobuf:
cd grpc-rs
cargo clean
cargo update
cargo install --force protobuf-codegen
  1. Rebuild ttrpc_rust_plugin with new protobuf:
cd ttrpc-rust/compiler
cargo clean
cargo update
cargo install --force --path .
  1. Build your project.

More Repositories

1

containerd

An open and reliable container runtime
Go
16,882
star
2

nerdctl

contaiNERD CTL - Docker-compatible CLI for containerd, with support for Compose, Rootless, eStargz, OCIcrypt, IPFS, ...
Go
7,909
star
3

cgroups

cgroups package for Go
Go
1,085
star
4

runwasi

Facilitates running Wasm / WASI workloads managed by containerd
Rust
1,047
star
5

cri

Moved to https://github.com/containerd/containerd/tree/master/pkg/cri . If you wish to submit issues/PRs, please submit to https://github.com/containerd/containerd
Go
905
star
6

stargz-snapshotter

Fast container image distribution plugin with lazy pulling
Go
884
star
7

ttrpc

GRPC for low-memory environments
Go
548
star
8

accelerated-container-image

A production-ready remote container image format (overlaybd) and snapshotter based on block-device.
Go
405
star
9

imgcrypt

OCI Image Encryption Package
Go
332
star
10

overlaybd

Overlaybd: a block based remote image format. The storage backend of containerd/accelerated-container-image.
C++
257
star
11

console

console package for Go
Go
178
star
12

rust-extensions

Rust crates to extend containerd
Rust
170
star
13

nydus-snapshotter

A containerd snapshotter with data deduplication and lazy loading in P2P fashion
Go
165
star
14

go-runc

runc bindings for Go
Go
163
star
15

go-cni

A generic CNI library to provide APIs for CNI plugin interactions
Go
146
star
16

continuity

A transport-agnostic, filesystem metadata manifest system
Go
142
star
17

nri

Node Resource Interface
Go
128
star
18

protobuild

Build protobufs in Go, easily
Go
122
star
19

fifo

fifo pkg for Go
Go
86
star
20

project

Cross-project utilities, scripts, etc.
Shell
72
star
21

btrfs

Btrfs bindings for Go
Go
68
star
22

zfs

ZFS snapshotter plugin for containerd
Go
64
star
23

typeurl

Go package for managing marshaled types to protobuf.Any
Go
49
star
24

containerd.io

Website repo for https://containerd.io
JavaScript
37
star
25

fuse-overlayfs-snapshotter

fuse-overlayfs plugin for rootless containerd
Go
37
star
26

release-tool

A release tool for generating detailed release notes
Go
34
star
27

aufs

AUFS Snapshotter for containerd
Go
26
star
28

ltag

Prepends project files with given template.
Go
16
star
29

project-checks

This cross-project repository holds utilities, scripts, and common files used across the containerd master project and many sub-projects within the containerd organization
Shell
5
star