C
C#2y ago
Verdant

❔ ✅ Writing to response body is slow in .net core 7 web api?

Hey guys, I have a stack overflow thread about the issue, but basically, I'm getting significant performance degradation when writing directly to the response body stream, as opposed to just another stream. It's seriously affecting my download times, lowering them to 16-20 mb/s (I am serving files). Can anyone help me with this please? https://stackoverflow.com/questions/76318014/asp-net-core-web-api-writing-to-response-body-is-insanely-slow
Stack Overflow
ASP.NET Core Web API : writing to response body is insanely slow?
I have an ASP.NET Core 7.0 Web API hosted on a server 2016 bare metal box. I'm creating dynamic ZipArchives and returning them when I receive API calls. Generating a 300 MB ZipArchive from 800MB of
41 Replies
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Verdant
VerdantOP2y ago
Roger that
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Verdant
VerdantOP2y ago
No worries
Verdant
VerdantOP2y ago
Verdant
VerdantOP2y ago
Alright @vec![atreit; 1024] Top is ziparchive -> memorystream -> responsebody bottom is ziparchive -> responsebody Winsock That's on localhost too It's weird that network negotiation would cause this kind of error Let me find a way to hold the response until it's fully complete
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Verdant
VerdantOP2y ago
It's not I/O, I'm getting the ziparchive from memory Only I/O happens on startup
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Verdant
VerdantOP2y ago
What do you mean? It's a ziparchive
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Verdant
VerdantOP2y ago
responsebody writes something to disk temporarily?
Aaron
Aaron2y ago
network I/O is still I/O
Verdant
VerdantOP2y ago
Ah, I thought he meant disk i/o Maybe if it's negotiating a lot of small data That could be what's happening, each time I write to responsebody, I send a little data over the network latency each time adds to the total Hmm Need a way to wait for the zip to be fully written to the response body before I release it to the client I wonder what would happen to performance if I just ran this synchronous Nothing, same story Seems as soon as data is available in the response, the api fires it off Hmm
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Verdant
VerdantOP2y ago
Not yet, let me do that now
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Verdant
VerdantOP2y ago
No worries I'd need to go make a way to generate a ton of garbled zip data and stuff anyway, and that'll take me some time Some progress I'm awaiting on the memory stream to copy to the response body and without network traffic it still takes 2 full minutes I'm going to profile that and see what I get
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Verdant
VerdantOP2y ago
I'll grab it in a sec, right now it's crashing on localhost but not on remote for some reason
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Verdant
VerdantOP2y ago
I gotta fix this bug first Interesting On localhost I get a fatal exception, but running it remotely is fine Cannot access a disposed resource Unexpected exception in TimingPipeFlusher.FlushAsync.
Verdant
VerdantOP2y ago
Verdant
VerdantOP2y ago
Not much going on in the flame graph
Verdant
VerdantOP2y ago
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Verdant
VerdantOP2y ago
I mean you'd expect the deflate to take a while Alright, debugged from the server end instead of localhost
Verdant
VerdantOP2y ago
Verdant
VerdantOP2y ago
This is for a networked request
Verdant
VerdantOP2y ago
Verdant
VerdantOP2y ago
Found it It was a client bug Dear god Thanks for all the help guys ❤️
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Verdant
VerdantOP2y ago
Alright Wasn't a client bug, I think Hard to say I need to do some more benchmarking Server seems to be slowing itself to the top speed of whatever client you use Which is downloading slower off the wire than it should be Narrowed it down a bit tcp window isn't scaling to the request, it's doing something weird
Unknown User
Unknown User2y ago
Message Not Public
Sign In & Join Server To View
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Verdant
VerdantOP2y ago
Wasn't 0 but it was low There was a bunch of stuff going on TCP window, MTU was too small A lot of stuff that was both unrelated and related to the code but I finally got it
Verdant
VerdantOP2y ago
11gb patch from france to dallas in 5 minutes not bad
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server