Skip to content

ArrayPool trimming issue for large response messages #2626

Open
@AnthonyLloyd

Description

@AnthonyLloyd

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 non ArrayPool arrays will be allocated)
  • Gives a ReadOnlySequence to the Marshaller method with the MemoryStream 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions