Sylvain C.
Sylvain C.

Reputation: 1073

ASP.Net vs ASP.Net Core compression & IIS

I have developed the same application which delivers a JSON file in 2 different projects. One is based on ASP.Net MVC4 and the other is based on ASP.Net Core 1.1.0. The JSON generated by my controller is around 5MB.

However when publishing the 2 apps, i have a difference of sizes for this file if it is compressed or not on both plateforms.

For ASP.Net Core, I have also tried to enable the compression middleware in the Startup.cs to see the difference:

    services.AddResponseCompression(
        options =>
            options.MimeTypes = ResponseCompressionMimeTypes.Defaults);

    app.UseResponseCompression()
       .UseStaticFiles();

This is the summary of my tests for my original 5Mo JSON returned to the client:

Run on Visual Studio, size of my JSON on:

On my local IIS Express with dynamic and static compression enabled, size of my JSON on:

On my production IIS server with dynamic and static compression enabled, size of my JSON on:

So we can see that for MVC4, we go from a not compressed file to a highly compressed file in production.

For ASP.Net Core, when the compression is enabled in the Startup.cs, the size of the file is constant but not as small as it could be.

For ASP.Net Core, when the compression is not enabled in Startup.cs, the file is gzip by default but I am not sure it is using the compression capabilities of the IIS server.

My question is what could I do to obtain a compressed JSON in ASP.Net Core as small as the one I obtained on my older plateform based on MVC4.

Thank you

Sylvain

Upvotes: 1

Views: 1104

Answers (1)

Dmitry
Dmitry

Reputation: 17350

Just a wild guess, but there could be something wrong with your baseline experiment. Why is uncompressed json ~5 times bigger in MVC than in Core (5MB vs 1.3MB)? I would start with making sure they are roughly the same.

Coincidentally your core-compressed-by-iis size (675KB) is ~5 times bigger than mvc-compressed-by-iis (136KB).

Is there a chance you mixed up the numbers? That would explain the discrepancy and confirm that IIS compression is about 20% more effective than Core Middleware in your scenario.

My question is what could I do to obtain a compressed JSON in ASP.Net Core as small as the one I obtained on my older plateform based on MVC4.

Looks like you already taking advantage of IIS compression by:

  • not using Core Middleware (app.UseResponseCompression)
  • and having dynamic compression enabled in IIS
  • and a proper content type configured in system.webServer/httpCompression/dynamicTypes

It might also be worth looking at Optimal vs Fastest compression levels in Core Middleware, eg:

services.Configure<GzipCompressionProviderOptions>(options => 
{
    options.Level = CompressionLevel.Fastest;
});

Upvotes: 1

Related Questions