Performance diagnostics of an ASP .NET MVC 5 website - c#

I have an ASP .NET MVC 5 website which runs perfectly on my local machine, but after publishing it to a hosting provider response time from the server is always about 30 seconds (on localhost it is about 100-500ms depending on a page). And I am not talking about first response after some timeout, I am talking about every response, even to pages like "Hello world" with a very simple ViewModel and maybe a couple of strings in ViewBag. At the same time, the static content (like .css and .js files) are returned quickly. I have performed several optimizations, such as:
Installed Razor Generator and compiled all .cshtml files
Got rid of dynamic variables and ViewBags
Made sure that I'm using "release" configuration
Unfortunately, my hosting provider doesn't allow me to configure IIS Application pool, so I couldn't optimize Idle Timeout etc.
Sometimes (very rarely) response time becomes normal (about 200-500ms) but this is for a very short period of time. I've tried several hosting providers and the issue is still there, so it seems to me that there are performance problems with my website but unfortunately I cannot locate and fix them. I'm using shared hosting, by the way, not VDS. So, the question is: Are there any standard diagnostic procedures intended locate and fix performance problems with ASP .NET MVC websites?

After several times of trying to find out solution for the issue with bad performance, I tried to deploy one of Visual Studio's included MVC projects (like #mjwills advised) and it didn't have any performance issues so I was pretty sure that there were problems with my project, not hosting provider. So, the solution for me was to create a new project from scratch and move all code from previous one to the new project, also deleting all the junk code and unnecessary nuget packages. I think that problems were caused either by bad entity framework configuration or by problems with nuget packages installed.

Related

What’s the benefits of Asp.net MVC projects precompilation?

My ASP.NET MVC project is taking more time than usual on the first hit,and it gets better afterwards, but the response goes slow again every next day. so It's a continuous performance issue
I googled the issue and most of the solutions are choosing precompilation during publishing, but Microsoft officials seemly didn’t confirm the operation can result in fast startup time for every request at any time.
So what exactly are the benefits of ASP.NET MVC Precompilation? Please advise
You can basically find the information here, there is also a fair amount of other relevant information on the advantages
ASP.NET Web Site Project Precompilation Overview
Precompiling an ASP.NET Web site project provides the following
advantages:
> Faster initial response time for users, because pages and code files
do not have to be compiled the first time that they are requested.
This is especially useful on large sites that are frequently updated.
A means to identify compile-time bugs before users see a site. (You
can also accomplish this when you compile a project in Visual Studio.)
The ability to create a compiled version of the site that can be
deployed to a production server without source code. This makes sure
that that people who have access to the production server will not be
able to view the source code.
You can also find similar questions here
What is the advantage of the ASP.NET precompilation?
What effect does the new precompile during publishing option have on MVC4 applications?
And some related information here
Precompiling Your Website (C#)
Because the pages must be automatically compiled when they are first
visited, there can be a short but noticeable delay when an ASP.NET
page is requested for the first time after being deployed.

VS2015 MVC No compile experience

It was my understanding that with the new compiler it is possible to run code without restarting an ASP.NET MVC project, e.g. the no-compile experience.
For example changing the model or controller requires restarting the entire project, which can take quite some time in VS2013 (especially with Code First).
Is this, basically edit&continue for ASP.NET, now possible in VS2015? I tried CTP5 but could not get this working.
Edit: The actual question
Does VS2015, or will it, support edit and continue or a similar experience (not having to restart for model/controller changes) for ASP.NET MVC?
Does VS2015, or will it, support edit and continue or a similar experience (not having to restart for model/controller changes) for ASP.NET MVC?
Visual Studio Edit and Continue is available and works for ASP.Net all the way back to version 2010 with constraints (IIS Express etc...).
Is this, basically edit&continue for ASP.NET
No. Scott Hanselman did a very detailed explanation of all the new features in vNext in this blog post Introducing ASP.NET vNext.
Excerpt:
One of the great aspects of environments like node or rails is that they are "no compile." Just change some code and hit refresh. With the next version of ASP.NET you get the power and throughput of the .NET runtime plus the "Roslyn" compiler-as-a-service for a "no-compile compile." That means means during development time you can just change your C# classes and hit Refresh in the browser. It's the power of .NET with the dynamism of a refresh-and-go development experience.
and
NOTE: This isn't ASP.NET Websites, or Razor View compilation - this is the whole thing, compiled in memory. You can use Visual Studio for development, or text editors like Sublime, or freakin' Notepad. (Of course, if you want assemblies on disk, you can do that too.)
and
See my web app’s bin folder in the screenshot below? There’s no assemblies in there because the assemblies never exist on the disk. It’s actually faster and easier to have the compiler do all the work in memory.

Running MVC and Umbraco 4.7 applications in parallel

We are using Umbraco 4.7.1 and it's very slow sometimes, taking more than 10-14 secs to load certain web pages.
Is it possible to create a new MVC web application and use this to display the slow pages instead of Umbraco? The important thing is that it should run on same web server and should replace a specific path currently existing in Umbraco, e.g. http://127.0.0.1/Product.
Any suggestions how to improve the performance are also welcome.
There are two parts to the answer. Firstly, yes you can. You can host the MVC application as an application within the site in IIS. You will need to ensure that you override all the web.config settings as these settings will be inherited. You will also need to add an the path of your MVC application to the umbracoReservedUrls and/or umbracoReservedPaths appSetting in the Umbraco web.config.
However, the second part of the answer is: don't.
Do not create and host a separate MVC application purely because you have performance issues in your Umbraco application. Figure out what is causing the performance issues and fix it. It sounds like you are possibly making too many calls to the database, or the calls that you are making aren't optimized.
My advise would be to run SQL profiler over the site on these pages and check what is happening. You should then review the indexes on the non-umbraco elements of your database, using views where appropriate, and also review whether you are using appropriate caching.

Asp.net Mvc site running out of memory

I have a weird scenario in which the website seems to randomly run out of memory from time to time: it works for weeks then suddenly everything throws an out of memory exception, and it stays so until the server is rebooted. It may happen after weeks or after days. We weren't able to identify a regular pattern.
Here a list of tech stuff used for this site:
Net framework 3.5
Mvc 2.0 with C#
IIS 6.0 on a dedicated server (no policy restrictions, etc)
3 layer architecture (ui - bll - dal)
Automapper 1.1.0.118
Elmah 1.1
FluentValidation 2.0
MvcContrib 2.0.95.0
MvcSiteMapProvider 3.0.0.1
Castle 2.5.2
NHibernate 3.0.0.4
FluentNHibernate 1.1.0.0
PdfSharp 1.31.1789.0
MarkdownSharp
Other than this, the site includes (via iframes) some old legacy asp forms. Those forms are the same that were on the old version of the site (which was entirely in asp), they have some problems but the old site never ran out of memory.
I've already checked common stuff, like all IDisposable implementing classes are inside using statements, no infinite loops, etc.
The site doesn't do anything strange, it pulls some data from the DB like news, generates some pdf on the fly after certain form submissions, allows users to subscribe to a newsletter. The usual stuff.
I'm really clueless, I've developed many sites, used the mentioned libraries almost everywhere, but this is the first time I experience this kind of problem.
I know this information isn't enough to "find" the problem, but if anyone can think of something I might have overlooked, or anything, it will be very welcome :)
EDIT: A detail that might be important. We have another website running on the same server (made with old asp) and it runs just fine, while the other is stuck. So it seems like the overall server memory isn't depleted, otherwise it wouldn't work too.
Install DebugDiag. Trigger it to take dumps of the process as it breaches memory thresholds (say at 300Mb and then at every 100Mb after that).
Comparing the dump files should give you a clue as to what is suddenly occupying all that memory
I would have a look at how Castle is configured and used, do you use castle to resolve your controller dependencies, using the ControllerBuilder.Current.SetControllerFactory method? If you do, you also have to remember to release the controller instances.
If your hosting multi application pool on IIS7/7.5 and high load, try change gc mode.
aspnet.config
[ Element](http://msdn.microsoft.com/en-us/library/ms229357.aspx Element)

No Compilation Needed - Compile On Run

Something weird that I've been seeing, a web application written in ASP.Net (C#) that got the source code on the production server and compile that way. So when I deploy to the server I deploy the source code.
Why does .Net have this functionality? Doesn't make sense.
I have already posted as a comment that I believe that this is a "Web Site" project and not a "Web Application" project, but I wanted to also add this link, which includes some nice links to comparisons of the two project types.
http://www.codersbarn.com/post/2008/06/ASPNET-Web-Site-versus-Web-Application-Project.aspx
This is the way ASP.Net Web Sites work.
Notice that it's very similar to ASP classic, which ASP.Net superseded.
You can also deploy pre-compiled sites, if you want to.
Faster debugging cycle is my guess. For very large projects compiling everything takes time. If you're not interested in bleeding-edge performance (ie debugging a page or 2 over and over and over and over), you can choose not to recompile every time you make an adjustement.

Categories

Resources