C# loading an unmanaged DLL: big performance difference between console application and webapp on IIS

Viewed 403

I have a webapp written in C#, based on ASP.NET. It loads (with LoadLibraryEx) an unmanaged DLL written with C++Builder.

As I have performance issues I made some tests and comparisons, running always the same method in the DLL, for many times, obtaining average times.

I discovered that the DLL:

  1. loaded by a C++Builder console application, takes: 4.922 s
  2. loaded by a C# console application, takes: 5.484 s
  3. loaded by a minimal C# ASP.NET application hosted on IIS 7.5, takes: 9.551 s

As you see case 1 and 2 have very similar performance.

Why case 3 is so slow? Maybe IIS slows down the DLL?

For it I ran a profiling with JetBrains dotTrace: enter image description here

Is there any suggested IIS tuning?

Is there any suggested fast alternative to IIS for hosting ASP.NET webapps?

Should I consider porting the webapp to C++Builder?

EDIT:

I tried to migrate my webapp to ASP.NET Core (instead of .NET Framework) and run it on Kestrel. It takes 6.042 seconds. So, not so much overhead compared to the console app. It seems that IIS is the culprit... why?

1 Answers

One cause that may explain your results is that IIS does not (by default) load your web app until the first time it is accessed. This can cause it to take longer as it will spin up the entire app after you navigate to the site whereas a console app will load the library as soon as the class that calls it is loaded into memory.

Related