Description
Hi, I'm having performance and memory allocation problems with AsyncServerStreamingCall
with a large response object size.
It seems the ArrayPool
is trimming heavily making things worse.
I've looked at the Grpc.Net.Client
code and I don't think I get anywhere by creating my own Marshallers.
As far as I understand HttpClientCallInvoker
calls GrpcCall<TRequest, TResponse>
which calls StreamExtensions.ReadMessageAsync
.
This method uses:
- 4096 byte array from the
ArrayPool
- message size byte array from the
ArrayPool
- a
MemoryStream
to copy to for compression (so multiple nonArrayPool
arrays will be allocated) - Gives a
ReadOnlySequence
to the Marshaller method with theMemoryStream
buffer.
I've tried implementing gRPC over WebSockets and that seems to work better because I can use my own ArrayPool
that doesn't get trimmed and can also use System.IO.Pipelines
efficiently.
Possibly improving the code in ReadMessageAsync
to use a custom ArrayPool
and also use System.IO.Pipelines
would achieve the same result.
Have you seen this ArrayPool trimming problem and do you have any ideas on what I can do?
Thanks