Go to file
Wei Fu 225de2c936 client: add UserOnCloseWait function
ttrpc provides WithOnClose option for user and ttrpc will call the
callback function when connection is closed unexpectedly or the ttrpc
client's Close() method is called. containerd runtime plugin uses it
to handle cleanup the resources created by containerd shim.

But the ttrpc client's Close() is only trigger and the shim's cleanup
resource callback is called asynchronously, which might make part of
resources leaky. There is an example from containerd-runtime-v2 for
runc:

```happy
[Task.Delete goroutine]         [cleanupCallback goroutine]

call ttrpc client.Close() -->

                                  read bundle and call runc delete

delete bundle
```

If the cleanupCallback is called after deleting bundle, the callback
will fail to call runc delete. If there is any running processes, the
resource becomes leaky.

```unhappy
[Task.Delete goroutine]         [cleanupCallback goroutine]

call ttrpc client.Close() -->

delete bundle

                                  failed to read bundle and call runc delete
```

In order to avoid this, introduces the UserOnCloseWait to make sure that
the cleanupCallback has been called synchronously, like:

```
[Task.Delete goroutine]         [cleanupCallback goroutine]

call ttrpc client.Close() -->

wait for callback

                               read bundle and call runc delete

                          <--  finish sync

delete bundle
```

Signed-off-by: Wei Fu <fuweid89@gmail.com>
2020-09-07 23:09:55 +08:00
cmd/protoc-gen-gogottrpc Add apache license to files 2018-06-27 17:49:06 -04:00
example metadata as KeyValue type 2019-06-13 18:06:27 +00:00
plugin Add apache license to files 2018-06-27 17:49:06 -04:00
.gitignore Initial commit 2017-11-13 14:12:46 -08:00
.travis.yml Add codecov integration 2020-01-20 19:13:18 -05:00
channel_test.go Revert "Copy codes and status from grpc project" 2019-10-28 14:46:51 -04:00
channel.go Revert "Copy codes and status from grpc project" 2019-10-28 14:46:51 -04:00
client_test.go client: add UserOnCloseWait function 2020-09-07 23:09:55 +08:00
client.go client: add UserOnCloseWait function 2020-09-07 23:09:55 +08:00
codec.go Add apache license to files 2018-06-27 17:49:06 -04:00
config.go Add godocs for interceptors 2019-06-12 20:26:36 +00:00
go.mod Bump the dependencies 2020-01-20 19:05:20 -05:00
go.sum Bump the dependencies 2020-01-20 19:05:20 -05:00
handshake.go Add apache license to files 2018-06-27 17:49:06 -04:00
interceptor.go Add godocs for interceptors 2019-06-12 20:26:36 +00:00
LICENSE Initial commit 2017-11-13 14:12:46 -08:00
metadata_test.go metadata as KeyValue type 2019-06-13 18:06:27 +00:00
metadata.go metadata as KeyValue type 2019-06-13 18:06:27 +00:00
README.md Add common check scripts and project references 2018-10-01 10:33:38 -04:00
server_test.go client: add UserOnCloseWait function 2020-09-07 23:09:55 +08:00
server.go server: add a connections leak unit test 2020-04-21 11:20:11 +08:00
services_test.go Fix method full name generation 2019-08-23 13:28:19 -07:00
services.go Revert "Copy codes and status from grpc project" 2019-10-28 14:46:51 -04:00
types.go metadata as KeyValue type 2019-06-13 18:06:27 +00:00
unixcreds_linux.go Add apache license to files 2018-06-27 17:49:06 -04:00

ttrpc

Build Status

GRPC for low-memory environments.

The existing grpc-go project requires a lot of memory overhead for importing packages and at runtime. While this is great for many services with low density requirements, this can be a problem when running a large number of services on a single machine or on a machine with a small amount of memory.

Using the same GRPC definitions, this project reduces the binary size and protocol overhead required. We do this by eliding the net/http, net/http2 and grpc package used by grpc replacing it with a lightweight framing protocol. The result are smaller binaries that use less resident memory with the same ease of use as GRPC.

Please note that while this project supports generating either end of the protocol, the generated service definitions will be incompatible with regular GRPC services, as they do not speak the same protocol.

Usage

Create a gogo vanity binary (see cmd/protoc-gen-gogottrpc/main.go for an example with the ttrpc plugin enabled.

It's recommended to use protobuild to build the protobufs for this project, but this will work with protoc directly, if required.

Differences from GRPC

  • The protocol stack has been replaced with a lighter protocol that doesn't require http, http2 and tls.
  • The client and server interface are identical whereas in GRPC there is a client and server interface that are different.
  • The Go stdlib context package is used instead.
  • No support for streams yet.

Status

Very new. YMMV.

TODO:

  • Plumb error codes and GRPC status
  • Remove use of any type and dependency on typeurl package
  • Ensure that protocol can support streaming in the future
  • Document protocol layout
  • Add testing under concurrent load to ensure
  • Verify connection error handling

Project details

ttrpc is a containerd sub-project, licensed under the Apache 2.0 license. As a containerd sub-project, you will find the:

information in our containerd/project repository.