How to force gRPC to use Arena for memory allocation

1,732 views
Skip to first unread message

Srikanth

unread,
Jan 18, 2019, 4:06:32 PM1/18/19
to grpc.io
We are currently using a C++ grpc server implementation and would like to make use of arena for memory allocations. We have enabled arena on our protobufs following the steps mentioned in https://developers.google.com/protocol-buffers/docs/reference/arenas and I see that the generated files have the logic to use Arena. But when the RPCs are called I see that the protobuf request and response objects were not allocated using arena. This results in Arena being unused completely. How do I force grpc to make use of Arena for memory allocations?

Yang Gao

unread,
Jan 22, 2019, 6:12:28 PM1/22/19
to Srikanth, grpc.io
I guess you are asking about synchronous server API. Unfortunately, there is no arena or general allocator support in a sync server.
There are a couple of ways to workaround it if you really want to use arena:
1. You can switch to use an async server, where your application would control the creation of the proto messages.
2. You can switch to use your own code generator so that you do not rely on grpc's generated service classes. And then you would have the freedom of control the messages. This could be more hacky. 

There was some discussion on generating a service with generic data (ByteBuffer) rather than the proto message in the generated grpc code, but it has not been implemented.

On Fri, Jan 18, 2019 at 1:06 PM Srikanth <srik...@pensando.io> wrote:
We are currently using a C++ grpc server implementation and would like to make use of arena for memory allocations. We have enabled arena on our protobufs following the steps mentioned in https://developers.google.com/protocol-buffers/docs/reference/arenas and I see that the generated files have the logic to use Arena. But when the RPCs are called I see that the protobuf request and response objects were not allocated using arena. This results in Arena being unused completely. How do I force grpc to make use of Arena for memory allocations?

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/7103263f-ff82-4950-98d5-15fe5f03703b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages