-
Notifications
You must be signed in to change notification settings - Fork 191
Excessively large number of StringBuilder objects allocated in FormReader for big input data #583
Comments
@yuwaMSFT Is this in Music Store? |
@muratg It's not. It's a stress app |
We can pool StringBuilders. #578 will help a little by removing the backing buffer. A workaround for large forms is using the WebUtilties libraries to read them in a streamed fashion without building up a large collection. |
Also for large forms, they could stack up in Gen 2 quickly since the request takes time to finish. I ran the test for <5mins and disconnected all clients. Checked the StringBuilder objs in heap: |
The string builders are only used in the initial parsing, they aren't held for the duration of the request are they? |
From the code it's supposed to be cleared after we read the complete key/value pair...But if the form data is big it may take a while to finish reading I guess. Also since there are more allocations, we may do GC more frequently and push the objs to the next generate faster? |
What does your data look like? form-url-encoded? Lots of small keys/values, or large keys/values? |
Yes, the default content type. It's a single pair with big value. |
What is the difference between this bug and #561? |
@dougbu Based on you dotpeek screenshots it looks like the strings from For some reason, @yuwaMSFT is seeing tens of thousands of StringBuilders (2000 per 16MB post and that's StringBuilders not strings) remaining in the heap leading to the process running out of memory and being killed by the Linux kernel. |
Is it because he's only sending a single big value and it's taking a while to receive and build? |
I'm assuming @yuwaMSFT is hitting TextContentController.AddContent with this type of request. So probably. @yuwaMSFT Is this correct? I assume EnableRewind is also exacerbating this issue. |
Note EnableRewind is being removed: #578 |
@halter73 Yes that should be the requests hitting the issue, |
This issue was moved to dotnet/aspnetcore#2722 |
In one stress run on Linux we hit OOM. During investigation, we saw excessive StringBuilder objects allocated in FormReader. The implementation will keep reading the stream until reaching a separator. In the test, we were posting faked large data ( > 16MB), which could cause the allocation of 2000 StringBuilder objects (8K chunk for each). If keep them all in memory we could only support very small number of clients. We probably can either reject big form or save data to temp cache file.
The text was updated successfully, but these errors were encountered: