Posts

Showing posts with the label IIS

C#13 params collection performance benchmark

Image
 Microsoft released the latest version of C# i.e. C#13 and now it allows params to be any of the collections supported by collection expressions rather than just arrays. So, I quickly wrote the benchmark code to test the performance and overall, it did improve the performance. public class ParamsBenchmark{ // Dummy methods to illustrate the params collections public int SumOld(params int[] numbers) { var sum = 0; foreach (var num in numbers) { sum += num; } return sum; } public int SumNew(params Span<int> numbers) { int sum = 0; foreach (var num in numbers) { sum += num; } return sum; } [Benchmark] public int SumOldParams() { return SumOld(1, 2, 3, 4, 5); } [Benchmark] public int SumNewParams() { return SumNew([1, 2, 3, 4, 5]); } } Below are my benchmark results:

Deploying Asp.net Core Background Service on IIS

Image
The main purpose of having Background Service within Asp.Net core web api is to make sure that once we start the application pool than Background Service should start immediately. But in general the design of IIS is such that unless you receive the first request worker process is never started and hence background service won't start automatically. So basically to achieve that we need to do some config changes on IIS which will help to start the background service automatically. Below are the steps: Firstly we need to make sure that "Application Initialization" is installed. If not you can add it via "Add Roles and Features Wizard". Once installed make sure you restart you server. Deploy your Asp.Net Core Web Api which has Background Service implemented. Go to "Application Pools" in IIS and select the corresponding application pool. Right Click on it and select "Advanced Settings" and you will see the below screen. Make sure the "Start M...

Map IIS Worker Process to PID

Image
Once you deploy your application in IIS, its bit difficult to find the corresponding PID of the application pool if you want to see which worker process is taking more memory. Generally in the Task Manager it will just show the worker process (w3wp.exe) and through task manager its difficult to say which Application Pool is taking more memory. But there is way to identify that through IIS Manager. You can view the Worker Process assignments by going into the Worker Processes section of the server. Once you click the "Worker Processes", it will show all the PIDs mapped with corresponding application pool. Sleeping or Suspended application pool will not be visible. As you can see above, IIS listed all the PID and now I can check in the Task Manager for the corresponding memory details.