Tips for improving the performance of an ASP.NET MVC site [closed]

5

I participated in DevDay 2015 and had the opportunity to take part in the Roberta Arcoverde lecture on the StackOverflow architecture. I found her approach to performance questioning interesting, including how well she stressed that they use certain rudimentary techniques to keep the site performing and performing better.

Well, recently I created my first Web application using ASP.NET MVC and I see that although using more advanced design patterns increase code extensibility and reuse, the performance presented is unsatisfactory. To get an idea, the main page of my application takes an average of 614 ms.

This application is simple, it is an application for displaying information stored in a SQLServer database that has been updated through a Webservice by another Desktop application. Below are the resources used to develop the site:

  • EntityFramework (I perform class mapping through the EntityTypeConfiguration ;
  • classes instead of DataAnnotations).
  • SQLServer 2014 database with indexed tables.
  • In the views I use some components of DevExpress and Twitter Bootstrap to adjust screen responsiveness.
  • I have not yet implemented caching or routing in the application (I hope to have some tips while doing this in this question)

Although it is a broad topic, I wanted to know if you have any tips or a starting point to guide me on how to improve application performance. Tips like: how to use the cache? do I need to use routing? Do I need to exit the EntityFramework and migrate to a micro ORM like Dapper?

    
asked by anonymous 05.11.2015 / 12:03

1 answer

2

Although it is a broad topic, I wanted to know if you have any tips or a starting point to guide me on how to improve application performance.

There are several. I'll try to be succinct in the answer, but I think it will be a little long.

I do not know if you've noticed, but at project startup, IIS needs to load a series of Class Libraries to work. This is why the time of the first screen is very slow, and this does not have much to do. Times go down as you go to other screens.

What you can do to lower this initial time is to uninstall packages that you are sure will not be used in the application. Open the packages.config file and see which packages have been installed. Then open the Package Manager Console (View> Other Windows & Package Manager Console) and use the following command to uninstall:

PM> Uninstall-Package NomeDoPacote

How to use the cache?

There are several types of cache that can be used in ASP.NET MVC. One of them is the Output Cache , which is for Razor.

In the talk you cited, Roberta said that Stack Overflow uses four levels of cache . One of them is Redis , which has its own implementation made by Stack Overflow's own staff . That is, everything that is accessed goes to the cache and stays there for at least 24 hours. This helps a lot for, for example, recent questions and answers. That's why the screen seems to blink when we read questions and answers that are at the top of the homepage.

Another form of caching is Elasticsearch (the original version is in Java, but was ported to .NET ), which makes this section of related links that we have on the side.

A third level of caching comes from Dapper .

The last level I confess I did not find, but I should update this answer when I find it.

Do I need to use routing?

Yes, this comes from the MVC architecture itself, and is not costly in performance.

Do I need to exit the Entity Framework and migrate to a micro ORM like Dapper?

It depends on what you need in relation to performance. Those times shown in the lecture ( are on Dapper's GitHub until today ) are outdated. The Entity Framework is a product that improves very quickly and this time is guaranteed to be less.

If you really need performance, I'd say switching to Dapper is a good option, but be prepared to do lots of things manually, such as writing queries on hand or building your own SQL generator .

    
05.11.2015 / 15:16