-
Notifications
You must be signed in to change notification settings - Fork 787
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow large byte arrays in received messages to be allocated from ArrayPool #2592
Comments
Hello, @bill-poole, it could be quite challenging to achieve that. First of all, you need to change array allocators, so you need to customize message parsers which are emitted by protoc, and they are not partial members. It can be achieved by writing protoc plug-ins, but I'm afraid it's already out of scope of grpc-dotnet. Another important thing of general-purpose API is that it should be easy/safe to use, I mean, like implementing Some time ago I had, I guess, similar case: a service which acts like a smart proxy which receives a message with large opaque binary payload and sends this payload wrapped with another proto message to another service, in duplex mode. The only difference is than it was protobuf-over-websocket rather than gRPC. With large payloads (~1MB), of course, I faced the same issues with intense LOH allocations. I manage to write a PoC powered by Returning to your scenario, the best solution depends on your protocol (I think key point are if any original message transform occurs and if message contain single or multiple large binary payloads), but I suppose it's out of drpc-dotnet and maybe even protoc scope anyway. |
Thanks @vladislav-prishchepa for the very detailed response and explanation. There doesn't seem to be a lot of good, easy options for streaming large amounts of data to a service in .NET. I could do a large HTTP POST and read the request stream directly in ASP.NET Core, but the default Kestrel maximum request body size is 30 MB, and it's not probably a good idea to increase it significantly because it is a global setting. I could use a So, that leaves us with streaming chunks of data over a gRPC request stream. I can change the service contract so that each chunk is sent as a It seems like there should be a simpler, more "out of the box" way of streaming data to a service in .NET without creating huge amounts of GC pressure. @JamesNK, should I open an issue for that somewhere, or do we just file it under "too hard"? |
I have a gRPC service that streams data from clients in a request stream, where each message is a chunk of data up to 1 MB. Currently, the gRPC library allocates a new array for each chunk, creating a lot of GC pressure, especially because the arrays are all allocated on the LOH. It would be great if we could configure the gRPC endpoint in ASP.NET to allocate those arrays from
ArrayPool<byte>.Shared
, rather than allocating new arrays. My endpoint logic would then be responsible for returning those arrays to the array pool when processing is complete.The text was updated successfully, but these errors were encountered: