Performance of Asp.NET Core on Linux vs Windows

Published On 八月 14, 2024

category http | tags benchmark HTTP


Motivation

Linux is widely used on servers in the production. The biggest exception is Microsoft who is using its own Windows server (e.g., M365 the largest commercial cloud in the world). Regarding Windows vs Linux, I have always had these questions:

  1. Does Linux perform better than Windows on the same hardware resource? Windows always gives me a feeling that it is very heavy and slow.
  2. Is Asp.NET Core performing well in Linux? As a web framework, Asp.NET Core is achieving very good result. It has been optimized well for Windows. It's not clear whether it is ready for production on Linux or now.
  3. How does it compare with NGINX which is one of the best HTTP servers available in Linux?

I did a benchmark to answer the questions above.

SetUp

Server

Server is a simple web app built using Asp.NET Core. It's using the default Kestrel http server.

I created 2 VMs on Azure:

  • Linux
    • OS: Ubuntu Server 24.04 LTS - x64 Gen2
    • IP: 10.0.0.4
  • Windows
    • OS: Windows Server 2022 Datacenter: Azure Edition - x64 Gen2
    • IP: 10.0.0.6

Both share these configurations. Hopefully, they should have everything equal except the OS.

  • SKU: Standard D16lds v5 (16 vcpus, 32 GiB memory)
  • .NET version: 8.0.7

Client

I am using wrk as the client. It is invoked from a separate Linux VM with the same configuration as the Linux server above.

I have a benchmark tool my repo but it does not perform as well as wrk on Linux.

Results

For web app built on Asp.NET Core, I tested 2 different scenarios: * hello world: the simpliest web server that just ruturns "Hello World" * home page: a bit more complicated because it has static files. It's a template generated by dotnet new webapp -o KestrelService. Same set up as my previous post

I also got some results for NGINX running on the Linux server. Since NGINX is not availabe on Windows, so I couldn't get the counterpart results on Windows.

Scenarios Linux Windows
Home Page 91,581 93,756
Hello World 359,620 361,596
NGINX 487,439

Each number is the median of 3 runs. The raw data can be found here: Benchmark result raw data

Benchmark result chart

Findings

  1. Windows performs as well as Linux when used a server. One might argue that this benchmark does not really compare the 2 operating systems. It is only a benchmark for Asp.NET Core which is OS agnostic. I agree. Howver, this comparison is still meaningful. We know that under the hood, Asp.NET Core (as well as most wonderful web servers) are using epoll on Linux and I/O completion ports on Windows to process multiple async IO requests. This comparison tells us the mechanism on Windows is not worse than that on Linux at all. Linux is not always better.
  2. Asp.NET Core performs equally well on both Windows and Linux. .NET Core allows us to run c# program on OS other than Windows. People might doubt its performance because there might be a lack of optimization. This benchmark shows it's not a problem.
  3. Even though it's not an apple-to-apple comparison, we can still get some intuitive conclusion that NGINX performs much better than Asp.NET Core (actually it's the built web server called Kestrel) from the perspective of a http server because the Asp.NET Core app that just returns "Hello World" is not comparable to the NGINX server that returns much more data. This is of course not a fair comparison because they are playing different roles in a server. NGINX is a reverse server and does not allow us programming on it (except using OpenResty) whereas we can build various services using Asp.NET Core.

qq email facebook github
© 2024 - Xurui Yan. All rights reserved
Built using pelican