Tips to improve the performance of an ASP.NET MVC site

Asked

Viewed 923 times

5

I attended Devday 2015 and had the opportunity to participate in the Roberta Arcoverde about the architecture of Stackoverflow. I found her approach on the issue of performance interesting, including how she emphasized well that they use certain more rudimentary techniques to maintain the site with greater performance and efficiency.

Well, recently I created my first web application using ASP.NET MVC and I see that although using more advanced design standards increase extensibility and reuse of code, 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 via a Webservice by another Desktop application. Below the resources used to develop the site:

  • Entityframework (Performing class mapping through 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 the responsiveness of the screen.
  • I haven’t implemented cache or routing in the application yet (I hope to have some tips while at it in this question)

Despite being a broad theme, I wanted to know if you have some tips or a starting point to guide me on how to improve the performance of the application. Tips like: how to use cache? need to use routing? Need to quit Entityframework and migrate to a micro ORM like Dapper?

  • 3

    I’d try to see what’s taking longer, the bank or website?

  • Yes, this is certainly the starting point, I am evaluating possible improvements, but I will begin by assessing what I may be doing wrong. Valeu Paulohdsousa

1 answer

2


Despite being a broad theme, I wanted to know if you have some tips or a starting point to guide me on how to improve application performance.

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

I don’t know if you’ve noticed, but on project startup, IIS needs to load a series of Class Libraries to work. This is why the time of the first screen is really time-consuming, and as for this has not much to do. Times go down as you access other screens.

What you can do to lower this initial time is to uninstall packages which you are absolutely sure will not be used in the application. Open the file packages.config 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 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 quoted, Roberta said that Stack Overflow uses four levels of cache. One of them is the Redis, that has its own implementation made by the staff of the Stack Overflow team itself. That is, everything that is accessed goes into 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 home page.

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

A third level of cache comes from the Dapper.

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

Use of routing is required?

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

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

It depends on what you need regarding performance. Those times shown in the talk (and who are on Dapper’s Github until today) are outdated. Entity Framework is a product that improves very quickly and this time is guaranteed to be shorter.

If you really need performance, I’d say switching to Dapper is a good option, but be ready to do a lot of things manually, like writing darlings at hand or mount your own SQL generator.

  • 2

    I think the cache tips will help me a lot, because this application is read only and in this context I will probably have better evolution generating a better structured cache.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.