High CPU on IIS sites - asp.net-mvc

I have a webserver with 10 mvc sites that I have created. All sites "link" to the same code in a folder. So all 10 sites run on same code. This is done have different languages on the site.
My problem is that 1 site goes up to use 40-60% of the CPU for a few minutes. Then it drops down and another sites rises in CPU. Normally the sites use 300mb in w3wp process, but sometimes rises to 8-900mb!
There's 20GB of memory, 18,9 is constantly used. There is also a SQL server running that takes 13GB.
The site is a MVC 3 site. Uses caching on the SQL data.
Every site has its own pool.
I know its a very vague question. But can anyone see any obvious problems with this setup?
Why does the CPU rise periodically?
There are about constantly 100-150 users on the sites.
Any ideas or thought would be very appreciated.

CPU utilization is result of web application so application developers would know best where is the problem. If application developers aren't "in-house" you as administrator will have to find is there problem in setup (less likely) or in application (more likely in my opinion).
Since IIS NEED tool from Microsoft like IIS Tracer, debugging high CPU utilization with "DebugDiag & friends" require lots of knowledge and effort.
Here is one nice article how to troubleshoot high CPU usage
Do your web apps use caching ?
OutputCache duration="180" varybyparam="*"
Sorry if this isn't helpful, but I'm administrator and when IIS server have high CPU usage in 95% problem is in poor SQL queries or bad programming which we fix after analyzing source code.

Related

ASP.NET MVC5 app memory leak

I have an ASP.NET MVC5 web application that is consuming excessive amounts of memory on our production server (excessive in that it increases over time and doesn't seem to stop until we recycle the application pool at ~8 GB, the max we've let it reach is 30 GB). The application does not perform like this on my dev machine or on our test server.
The production server is Windows Server 2012 R2 running IIS 8.5.9600.
I have written a small test tool which creates 50 concurrent threads and sends 1000 sequential requests each thread. In development the web application's memory stays around 400 MB, as it does in our test environment. On the production server, the memory just increases on and on. It doesn't matter what the endpoint does, I've just got it returning a vanilla .cshtml Razor view.
I've been trying figure out what could be causing the memory leak for some time and tried a few things:
Taking memory dumps and using a profiler (I've tried several different profilers). They all indicate that managed memory is within a reasonable amount (~100 - 200 MB), even on memory dumps of 8 GB!
Deploying a copy of the default "empty" ASP.NET MVC app generated by Visual Studio and running my test tool pointing to that. Same symptoms; memory is stable in dev and test environments but increases on the production server. I'm going to let it run for a while and see how high it goes, but so far it's 3 GB and climbing with each request.
The production server does have 96 GB of RAM, and from my understanding of how IIS uses this, it can get very greedy. But my dev machine has 32 GB and the max application pool size I've seen is around 600 MB and then it gets GC'd and reduces back to around ~400 MB.
What is taking up all the memory? Is this normal behaviour for IIS?
Update:
I've created a new VM server on Azure with similar specifications (112 GB RAM) and the memory stops at around 400 MB also. There must be something specific to our production server causing the problem.
In our case, it was our hosting provider who had installed some monitoring tool which used the .NET profiling API poorly.
I suggest anyone who is observing similar symptoms in their app to try configuring a new server instance.

Azure Websites and ASP.NET, how much inactivity before the app pool is recycled causing a recompilation?

I have a MVC3, .NET4.5 asp.net web application hosted on Azure Websites.
I am experimenting with "Free", "Shared" and "Standard" scaling configurations.
I have noticed that after a period of inactivity the compiled code get dropped from memory, or the app pool gets recycled forcing a JIT recompile.
My main question is what is time period before the compiled code gets dropped forcing a recompile? I assume this is as a result of the application pool recycling? I have come across this on standard shared hosts such as DiscountASP.
My second question is: What is the best approach to minimise this issue as I would not like my users bumping into this recompilation lag? My initial thoughts are precompilation.
Many thanks in advance.
EDIT:
I have a found a related SO post on this here: App pool timeout for azure web sites
However it seems, as like standard Shared hosting, one cannot change App Pool recycling. One has more flexibility with the "Standard" scale option, since it is dedicated. So the likely options at present are:
1) Precompilation
2) Use of "Keep alive" ping sites.
EDIT2:
1) "Keep Alive" approach seems to be working. I have a 10 minute monitor running.
I believe the inactivity period is 20 minutes by default. I haven't used web sites yet so I'm not famailiar with rescrtictions on changing settings but one quick way to keep your site activie is to use a uptime monitoring service like Pingdom (you can check one site for free at time of writing), this will ping your site regularly and prevent it from becoming idle.

performance counters tips for server

I have an mvc4 application that communicates to my sql server database via a wcf layer. Each layer is co located on the same server with the database located on a different server.
I am seeing CPU issues on my server which holds the applications, in particular with my mvc4 application. The server is windows server 2008 R2¬ running IIS7.5.
I would like to put some performance counters on my server to analyze where the problem on the server may be and is causing the high cpu problems.
I am new to setting up such and looking for pointers as to what counters to set up that may assist me, how I should analyze and best plan in gaining more knowledge on such.
Performance counters are generally good for production monitoring. On dev environnement (and I suppose you are at this stage), there are many profiling tools & apis.
On Sql Server
The best tool is Sql Server Profiler. You can find and diagnose slow-running queries by capturing all Transact-SQL statements and/or Sql Server Events.
On Asp.net MVC
I highly suggest you install a profiler like asp.net mini-profiler or Glimpse. When browsing you website, this will tell you which controller/action/partial/ajax is slow and sometimes why.
Visual Studio includes a Profiler. This let you measure, evaluate, and target performance-related issues in your code. It's fully integrated into the IDE. Once you have ran a performance session, several reports are available to help visualize and detect performance issues from the data gathered.
If you can't find why, you could run a load test using Visual Studio Web & Load Tests. You will rarely have performance issues for a single user, but for many concurrent users it's not generally the case.

How to increase the performance on my ASP.NET MVC 2 website?

I run a social community site for card players. I currently have 7,000+ members and getting 2,000 visitors/15k+ pageviews a day. Recently the site has started to really slow down during peak hours of the day and I am starting to think my site needs some serious performance optimizations in the code and settings. I really don't want to purchase a second server to run the site as I am pretty sure my current server should be able to handle this kind of load easily.
During peak hours, when the pages load, they still load very quickly. The problem is that a lot of times it will timeout and give a "website not available" error in the browser. Then you refresh it and it loads up quickly. Then a couple of pageviews later it will do it again. My CPU and RAM usage do not even get very high during these times, so I must believe it is in my IIS settings or something. I have done some searching and cannot find any good answers or ideas of what a fix could be.
Here are some stats of my setup:
ASP.NET MVC 2 w/ Output Caching and Partial View caching
IIS 7
Windows Web Server 2008 RC2 64-Bit
AMD Athlon II X2
4GB of RAM
My heavier pages on the site have quite a bit of database reads and a lot of image requests. I am not sure if this is the problem, because when a page does load it is VERY fast.
I did purchase a new server I am building and was thinking about switching everything to this instead. The new server I just got is gonna run an Intel Xeon X3430 2.4GHz Quad-Core w/ HT and 8GB RAM.
I am looking for a few possible things I could look into for this problem and if there are any possible solutions or settings I could implement to stop the "website not available" messages and also help my server handle future traffic increases as the site grows. Would upgrading the server to this new one make the difference?
It looks like this is more of an IIS issue than your code or hardware. There is a default setting for max concurrent connections per cpu and queue length that you may be reaching.
See Optimising IIS Performance and someone with a similar problem (and resolution).

Web App Performance Problem

I have a website that is hanging every 5 or 10 requests. When it works, it works fast, but if you leave the browser sit for a couple minutes and then click a link, it just hangs without responding. The user has to push refresh a few times in the browser and then it runs fast again.
I'm running .NET 3.5, ASP.NET MVC 1.0 on IIS 7.0 (Windows Server 2008). The web app connects to a SQLServer 2005 DB that is running locally on the same instance. The DB has about 300 Megs of RAM and the rest is free for web requests I presume.
It's hosted on GoGrid's cloud servers, and this instance has 1GB of RAM and 1 Core. I realize that's not much, but currently I'm the only one using the site, and I still receive these hangs.
I know it's a difficult thing to troubleshoot, but I was hoping that someone could point me in the right direction as to possible IIS configuration problems, or what the "rough" average hardware requirements would be using these technologies per 1000 users, etc. Maybe for a webserver the minimum I should have is 2 cores so that if it's busy you still get a response. Or maybe the slashdot people are right and I'm an idiot for using Windows period, lol. In my experience though, it's usually MY algorithm/configuration error and not the underlying technology's fault.
Any insights are appreciated.
What diagnistics are available to you? Can you tell what happens when the user first hits the button? Does your application see that request, and then take ages to process it, or is there a delay and then your app gets going and works as quickly as ever? Or does that first request just get lost completely?
My guess is that there's some kind of paging going on, I beleive that Windows tends to have a habit of putting non-recently used apps out of the way and then paging them back in. Is that happening to your app, or the DB, or both?
As an experiment - what happens if you have a sneekly little "howAreYou" page in your app. Does the tiniest possible amount of work, such as getting a use count from the db and displaying it. Have a little monitor client hit that page every minute or so. Measure Performance over time. Spikes? Consistency? Does the very presence of activity maintain your applicaition's presence and prevent paging?
Another idea: do you rely on any caching? Do you have any kind of aging on that cache?
Your application pool may be shutting down because of inactivity. There is an Idle Time-out setting per pool, in minutes (it's under the pool's Advanced Settings - Process Model). It will take some time for the application to start again once it shuts down.
Of course, it might just be the virtualization like others suggested, but this is worth a shot.
Is the site getting significant traffic? If so I'd look for poorly-optimized queries or queries that are being looped.
Your configuration sounds fine assuming your overall traffic is relatively low.
To many data base connections without being release?
Connecting some service/component that is causing timeout?
Bad resource release?
Network traffic?
Looping queries or in code logic?

Resources