After building an MVC web application, I'm used to experiencing a slow load time for the very first web page that's accessed, and I know why this happens, but I'm also noticing that the load time is slow for the initial access of every single web page.
As an example, here are the load times for my home page under various conditions. The home page does not make any database calls:
Built project and loaded hope page (first web site hit, and first home page hit): 10.31 sec (expected)
Built project, loaded contact page (first web site hit), and then loaded home page (first home page hit): 757 ms (not expected)
All subsequent load times for home page (2nd, 3rd, 4th, etc. home page hits): 4 ms (expected)
I have reproduced these same results for all web pages, not just the home page. I.e., if you replace "home page" with "about us page" and "contact page" with "faq page" the load times will be nearly exactly the same as above.
These number are for my local environment, and if I push my project to the production environment, they skyrocket, and the initial load of every page is dozens of seconds.
What's interesting is that I can only remember this starting to happen a few days ago. For the last several months, from what I can remember, the initial web site load was always slow, but after that, all pages would load very quickly on their initial load.
What is causing the slow initial load time of every page?
The application pool needs time to build the libraries before it can begin processing them. This can be speed up by using some kind of script. It also depends on whether you're using a website or a web application project. A website for every page the very first hit is slow and each new page hit has an extra compile time. Web application projects are precompiled should be little faster, but the libraries still need to be loaded up. The more libraries and tools you have the worse this hit tends to be.
You could also looking for IIS Auto-Start feature and setup it on your server may help speed up the process. By default Application pool gets shutdown in case of user inactivity default value of 1740 mins. You can also disable idle TimeOut by setting to 0 can help a lot.
My best bet is using Application Initialization plugin to get better performance
http://www.iis.net/learn/get-started/whats-new-in-iis-8/iis-80-application-initialization
It is occured after I move my project from VS2017 to VS2019. I found the problem I guess. Every page is compiled once on first visit. Check publish options. You will see an option "Precompile During Publishing" Enable this option. Delete BIN and WIEWS folders. Copy folders from publish location (do not overwrite)
Related
My Goal: Cache basically all the pages all the time so that users rarely ever have to hit my CMS for content.
I have a c#/.Net MVC 5 Web App deployed in Azure. I also have all the OutputCache's on my controllers set for 1 week [604800s] (content rarely changes). I assume, maybe naively, that the cached outputs are stored in memory in Azure. However, when I start my app and crawl the website, I'd expect the Azure memory to fill up with cached content, but in practice, there might be a bump in memory utilization. It goes back to its "resting state" of like 60% utilization after about 5 mins, though. I've also tried using MemoryCache, but it has a similar result - a bump in memory usage, and it goes down to normal shortly after.
In any case, the result is that the pages act like they weren't cached. For example, if I crawl 1 page and visit it - it loads in about 1 second (it's cached). If i crawl 2000 pages and visit a random one, it loads in 3-4 seconds (it's not cached). I've tested this by putting a datetime in the view itself.
So... the bottom line is: cached = fast, not cached = average. I want it to be fast!
I've looked at Redis Cache, which could be a way to do this, and seems easy enough... but my gut says this should be basic functionality (since it's built into the framework).
Azure Web App did support in-memory OutputCache. We can easily confirm it using following code. The output datetime will not be changed after you refresh the TestCache page.
[OutputCache(Duration = 3600)]
public ActionResult TestCache()
{
return Content(DateTime.Now.ToString());
}
But there are some problems when using in-memory cache in Azure Web App.
First problem with this is that it limits you to the memory that is available on your web app instance and this may create an out of memory issue when you cache a large amount of page output data. Your web app will be restarted if your memory is full. If the web app is restart, all the cached content will be lost. Another issue is that your application runs on multiple load balanced instances. The next request might go to another instance, which creates a new copy of ASP.NET Output Cache data in this instance, as well. These redundant copies of page outputs in each Web Role instance consume a lot of extra memory.
To avoid the upper problems, I suggest you use Redis Cache to store the cached content. For how to use Redis Cache, link below is for your reference.
ASP.NET Output Cache Provider for Azure Redis Cache
I maintain a legacy (7yr old) ASP.NET 4.0 WebForm site. Our user base is around 2K-3K concurrent users during peak activity, usually in the spring of each year.
I've been able to trap in the code, a user submitting the same webform more than once to the server...however the user is only clicking the submit button once. I've witnessed the activity to verify single-click submission.
For some odd reason, the browser (chrome) is posting the same web form 2,3, sometimes 4 times to the server. It seems to happen to most everyone using the app and varies from once every 5th button click to as high as every 20th button click. These duplicate submissions happen within milliseconds of one another.
Is there a good way for the server to recognize another request from the user and ignore it? Since it appears the browser is the culprit, the page content for the submission would be identical on subsequent submissions.
fwiw, I'm aware of the anti-forgery methods for crossSiteScripting in MVC, but this app is strictly WebForm (no MVC).
I'm not a heavy web programmer, but can learn just about anything. Most of my time is spent in T-SQL. But such is the way with funding for maintaining older apps. :)
(WebApp/LoadBalancer uses sticky-sessions, with ASP.NET State Server supporting 3 web servers for this app, if it matters. Once a user logs in against a specific web server, all traffic from that user stays on that specific web server.)
edit: i did find this: Generating AntiForgeryToken in WebForms which I think is a good solution...need to absorb it for a bit and see how it works in my prototype project.
I am using ASP.NET MVC5 and Visual Studio 2015 for own web application. My application is deployed on the IIS 8.5 server. I have very slow performance during first loading of the each page. The next each request for the specific page is very fast. I think that this is due to compilation of the page. Please help me, how i can setup pre-compilation of the views during publishing process on the build server?
The question here is, how heavy are you pages, it sounds to me browser caching is making the pages faster on your second call. it dosnt to do anything with IIS. in IIS the first load is always slow once the project gets built the next requests will be quick.
so I suggest look at your view, optimize images and scripts and etc...
We use Razor Generator for this, it's a VS extension.
Is it possible in ASP.NET MVC to display a downtime page when publishing a project out to a server?
Right now, if I hit the page while I am publishing I get an error:
Could not load type "App.MvcApplication"
It would be awesome if we could setup a downtime page so that users know to come back at a later time, instead of thinking that the app is busted.
You could add an app_offline.htm page to your application root, traffic will be redirected to that page until you remove or rename it.
More info
Scott Gu's App_Offline.htm
App_Offline.htm and working around the "IE Friendly Errors" feature
Will app_offline.htm stop current requests or just new requests?
An alternative to doing this in the application is to have IIS sort this out for you.
Application Initialization Module gives this feature, and also allows you to run warm-up scripts.
Whenever we deploy an application and the client reviews the app, sometimes the javascript doesn't work (not totally). But when the browser is refreshed, the page works as intended.
I'm suspecting that it has something to do with the cache. Is there a way to disable caching of pages? I'm using Azure with .NET 4.0
Thank you in advance!
The only way I know of to reliably stop caching of files and links in most browsers is to append a random number or time to the file. e.g.
http://www.domain.com/js/script.js?date=20120409120003
This will mean it is a new link each time the page is loaded and next time it goes to get the file it won't have it available in cache.