Performance comparison between LiteApi and MVC Core

First time I have compared LiteApi performance with performance of MVC using a single controller with single action I was pleasantly surprised, LiteApi was outperforming MVC. I never tried to investigate why, my only guess is that LiteApi has a lot less lines of code in it.

If you don't know what LiteApi is or how to use it, please check my introductory post

The Setup

For comparison I have created two super simple projects which you can find here on GitHub.

Both projects use identical Program.cs file.

public static void Main(string[] args)  
{
    var host = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        //.UseIISIntegration()
        .UseStartup<Startup>()
        .Build();

    host.Run();
}

And both projects use only what is necessary for them to run, here are dependencies from project.json files:

// LiteApi version
"dependencies": {
  "Microsoft.NETCore.App": {
    "version": "1.0.0",
    "type": "platform"
  },
  "Microsoft.AspNetCore.Server.Kestrel": "1.0.0",
  "LiteApi": "0.1.1-beta"
}

// and MVC version
"dependencies": {
  "Microsoft.NETCore.App": {
    "version": "1.0.0",
    "type": "platform"
  },
  "Microsoft.AspNetCore.Mvc": "1.0.0",
  "Microsoft.AspNetCore.Server.Kestrel": "1.0.0"
}

Here are the Startup.cs files:

// for LiteApi
public class Startup  
{
    public void ConfigureServices(IServiceCollection services)
    {
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        app.UseLiteApi();
    }
}

// and for MVC:
public class Startup  
{
    public Startup(IHostingEnvironment env)
    {
    }

    public IConfigurationRoot Configuration { get; }

    public void ConfigureServices(IServiceCollection services)
    {
        services.AddMvc();
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
    {
        app.UseMvc();
    }
}

Both apps were run and tested on localhost using dotnet CLI with Release build and disabled telemetry. Here are the controllers:

// LiteApi controller:
public class ValuesController : LiteController  
{
    public int Add(int a, int b)
    {
        return a + b;
    }
}

// and MVC controller:
[Route("api/[controller]")]
public class ValuesController : Controller  
{
    [HttpGet]
    public int Add(int a, int b)
    {
        return a + b;
    }
}

The Tool

For load testing I have first tried to use WebSurge, but for some reason it was freezing and I couldn't get to see the results of the test session. Then I have tried Netling and it was working without an issue. Only downside of the Netling is that you have to compile it yourself.

The Hardware

Hardware used for both client and server (same PC) is 64-bit Windows 10 Pro PC, running on i7-4720HQ @ 2.60GHz with 8GB of DDR3L memory and Samsung 840 Pro SSD.

The Results

Tests for both apps were run for 10 minutes with same client settings. Each app was running while the other one was not.

Here are the results for MVC Core app:


Here are the results for LiteApi app:


And here is comparison of both:


As you can see LiteApi can handle about 90% more requests per second. I am not sure why is there such an enormous difference in the bandwidth, both apps were running on localhost on Kester. I will deploy both apps to actual (physical) Linux servers to check if the difference will stay in the same range and update this post with the results.

Update

After testing on real hardware from Scaleway (Intel(R) Atom(TM) CPU C2750 @ 2.40GHz (8 Cores, 8 Threads) with 32GB of RAM) on Ubuntu 14.4 LTS server no significant difference was found between MVC and LiteApi (about 10% in favor of LiteApi). I imagine the small difference is to be attributed to the client which was not able to generate more than 200 concurrent users. I will try to setup local Ubuntu server and check again.