Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ASP.NET WebAPI output gets 40× slower when single byte is added to response

I have a simple action method like this:

public class TestApiController : ApiController
{
    [Route("api/string"), HttpGet]
    public string GetString(int length)
    {
         return new string('x', length);
    }
}

Response times (as observed by Fiddler):

GET /api/string?length=1186
  0.008
  0.007
  0.007
  ...

GET /api/string?length=1187
  0.208
  0.212
  0.205
  ...

That is, by adding a single byte to the response, the processing time increased 40×.

This behavior is absolutely consistent and I observe it both in the Visual Studio's Web Server and in IIS 8.5 (however, the specific response size threshold is slightly different).

Why on earth would it behave like this?


EDIT: In my case, ESET NOD32 antivirus inspecting HTTP protocol was the culprit.

like image 432
twoflower Avatar asked Feb 15 '16 15:02

twoflower


2 Answers

AntiVirus software is scanning incoming/outgoing data from your PC.

They are programmed to know how to understand data with standard types, and do not make scanning on simple strings ints datatable. When you are manipulating this data directly, you are telling to given antivirus software "Hi, I am strange please check me", antiviruses "rules" are hidden but I know for sure there is something "for size", "for format" etc. it depends on software. In your case it was slower, It had to do additional scanning jobs to be sure that you are safe. This is a very known issue over Intranet solutions that are running custom apps that are sending some custom data.

like image 146
Sebastian 506563 Avatar answered Sep 21 '22 21:09

Sebastian 506563


It's likely you are passing over the MTU for the network and the packets are getting fragmented when passing over the network. Packets on a typical network max out just under 1500 after which they get split up.

Try running Wireshark and see if that can help you track down the issue. You can also try enabling Jumbo Frames on your network adapter and see if that helps.

like image 22
C. Burnette Avatar answered Sep 20 '22 21:09

C. Burnette