ThreeMammals / Ocelot

.NET API Gateway
https://www.nuget.org/packages/Ocelot
MIT License
8.38k stars 1.64k forks source link

RequestMapper performance issue: ToByteArray(request.Body) #1679

Closed weichaohh closed 11 months ago

weichaohh commented 1 year ago

Expected Behavior / New Feature

File: RequestMapper.cs Method: Task<HttpContent> MapContent(HttpRequest request) Line:

var content = new ByteArrayContent(await ToByteArray(request.Body));

There are performance issues. Maybe Can change to use ArrayPool like YARP, This can reduce GC byte[].

raman-m commented 1 year ago

Hi weichao! Thanks for your interest in Ocelot gateway!

Could you correct your English text description please? It is hard to read it!

In general I understand the issue, but we need to work on description and user scenario to accept the issue.

Do you have some draft solution with a fix?

weichaohh commented 1 year ago

Hi Thanks for your reply, Sorry, my english leve very low.

I have a large number of iot,they post real time data to the platform. every time convert client request httpcontent to destination must use memStream.ToArray() to allocate new new byte[]. this will increase the burden of GC.

I found that YARPStreamCopier.cs use ArrayPool<byte>.Shared to copy stream, that can buffer byte[], so reduce GC. I think this is a good choice

raman-m commented 1 year ago

Yes, this is a good choice! Are you going to create a PR to fix this problem? Have you provided some performance tests and/or comparison of YARP and Ocelot?

raman-m commented 1 year ago

The issue has been accepted due to opened PR #1724

raman-m commented 1 year ago

@ggnaegi Gui, the author doesn't want to fix and closed the issue 😄 What will we do? So, because we're close to finishing and you're working on #1724 , I've decided to reopen this issue. OK?

ggnaegi commented 1 year ago

Ok @raman-m could you assign me? Thanks!

raman-m commented 1 year ago

Ok @raman-m could you assign me? Thanks!

You're assigned.