In this article we will discuss how to improve performance of asp.net MVC4 application.
First of all you need to debug the application to find out areas that has performance issues. Though we can find it manually but there are tools which would make our life easy. We will use Glimpse.Mvc4 tool to debug and find out performance issue in app. Note, I created a sample mvc4 app which lists 100 orders in a page.
In VS 2013, open ToolàPackage manageràManage nuget packages for solution, which would bring up “nuget package window” and search for “Glipmse.Mvc4”, you would see screen like below.
Click on “Install” button next to Glimpse.Mvc4. The nuget package manager would install glimpse!! Once it is installed, you would be prompted with web page to enable it for your application, you click on “On”.
I created a controller called “PerfController” with method called “Index”. The index method would call data access component called “DataAccess” to get list of orders.
Let’s add Thread.Sleep(2000) into “GetOrders” method of DataAccess component to create 2 second delay.
Now let’s start the app and click on “Orders” link and see what is going on inside the controller using glimpse.
The glimpse UI would be immediately available to you with all the data. Click on “Execution” tab, you would see “Perf” controller Index method takes more than 2 seconds and remaining are less than 10 Milliseconds.
We need to now look into Index method to see what is taking this much of time. Considering the fact we made a delay of 2 seconds in GetOrders method and we cannot improve it, we should see alternative ways to improve. One of handling this situation is using caching.
I just created my own cache service but you can use anything you want.
And made following changes in index method of “PerfController”
Now let run the application and see if the performance is improved.
After first call the time remains almost same as previous.
After second call, it is reduced just 0.14 Milliseconds!!