dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.19k stars 9.93k forks source link

Performance issue with reading Requies.Form collection #8510

Closed yevgenyka closed 5 years ago

yevgenyka commented 5 years ago

Hi, We have a service, which runs kestrel. Our customers sometimes send big requests with 4MB data in the Request.Form collection. In that case, it takes more than 10 sec to read the form collection, using Request.ReadFormAsync method. When running kestrel on the service, based on dotnetframework, it may take more than 30 sec

We found, that this happens when the request contains a mix of Unicode characters, like text, translated to other languages (in our case there are many languages) with some quotes, "<>" characters or even "abc". The main problem seems to be in the fact, that ReadFormAsync uses Uri.UnescapeDataString method, which takes most of the time (see enclosed dotTrace snapshot) In our benchmarks (enclosed) we can see that Uri.UnescapeDataString takes about 39 sec, but WebUtility.UrlDecode takes 14 ms

Steps to reproduce the behavior:

  1. In enclosed solution restore packages
  2. Run with Ctrl+F5 (that will load the servers and perform benchmarks)
  3. See benchmarks results

Enclosed are demo solution to reproduce the issue, benchmarks results and dotTrace snapshot:

EscapeTest.zip readFormSnapshot.zip dotTrace BenchmarkDotNet.Artifacts.zip

mkArtakMSFT commented 5 years ago

This issue was moved to dotnet/corefx#36050