I have an ASP.NET website that seems to be using a lot of memory. I left it for 7 hours on Sunday and it reached 3.2gb. I thought .NET handled all it's own garbage collection / free'd objects and so on, so I am not really sure where to start looking for a solution.
The website uses XML's heavily so I thought this could be the issue but I have implemented the global use of the XMLSerializer to try and rule this out.
I also have a custom handler that deals with all the images, resizes, caches and then loads from cache where it can. Could this be causing any issues?
Sorry to be so vague but the problem is that I don't know where to start with the issue really. Any help appreciated.
Server info:
.NET 2.0
Windows 2008 server
IIS7
Thanks in advance.
Best place to start is using a profiler. RedGate has the ANTS Memory Profiler which is really good and has a free trial. Product page here.
You run the application, attach the profiler then start using the page as normal. The profiler collects information about the objects in use and this should allow you to pinpoint the root cause of the problem.
Once in my application, it turned out to be that we were accidentally creating a NHibernate SessionFactory for every single query that we performed. These were all referenced internally by NHibernate, which meant that they were never freed in addition to being horribly slow and inefficient. The profiler lead us right to it and we never would have found it otherwise.
An alternative to RedGate is using adplus and WinDbg. Also read this blog:
http://blogs.msdn.com/tess/
This is an excellent source of help with debugging issues.
My SysAdmin and I had successfully used adplus and WinDbg to find a memory leak in an ASP.NET Application. My developers mistake was, that they accidentally used ASP.NET's cache without an expiration timeout.
Another Bug was, that a developer used Attribute overloads with XMLSerialization. With that feature .net will allays create a new serializer helper (whatever) assembly. Assemblies cannot be unloaded, so the application eats a lot of memory
When dealing with the file system its really important that you dispose your readers and temporary objects.
You say that you are using XmlSerializer a lot. This causes a memory leak if you are not using the default constructors XmlSerializer(type) and XmlSerializer(type, defaultNameSpace).
See this MSDN article for more info
Related
Due to some memory leaks, some memory is not released except when doing IISreset.
I found some code where I have a class of properties and methods, where only 10% of the methods are specific for the class, 90% can be moved to another class.
how bad is that? is this is affecting my memory, because I am initiating this class with every user using the application?
It is a ASP.NET Application on IIS6.
I suppose if the methods require no instance state but require an instance to call (i.e. they are instance methods that never reference 'this'), they could be made into static methods and save you one object allocation. However, if you have to allocate the object anyway (as it sounds like you do, for the other "10% of functionality" you mention) that doesn't sound like it will fix the issue.
You should probably do an analysis of memory usage in your application using the debugger. Rico Mariani has a pretty good blog post about tracking down managed memory leaks here: http://blogs.msdn.com/b/ricom/archive/2004/12/10/279612.aspx . It is old but still relevant. (Note: If you happen to be using .NET 4.0 you'll need to do ".loadby sos clr" instad of ".loadby sos mscorwks" to load the SOS debugger extension in WinDBG.)
Any recommendations for transition from single server to load balancing environment of 3 servers?
I considered using Sql Server session management, but I am storing linq2sql objects in session which has serialization issues. With a quick search I found a workaround .But I am skeptical to use this approach considering code-change/readability/performance issues. Any suggestions are welcome.
Just a suggestion : Can't you use sticky sessions in your load balancer?
We use memcached but it sounds like you want something to be a more critical portion of your app than just caching if you're placing LINQ to SQL objects up there (and I btw agree with RPM that you should consider getting out of that business...)
Anyway, this is a nice blog post that gives you a few options. Velocity is definitely one to look at since it's what Microsoft is offering (this is an asp.net app) and it seems to be gaining steam these days.
I have a web service running and I consume it from my desk application that is written on Compact Framework.
It takes 13 seconds to retrieve 8 results which is kinda slow. I also expect to be retrieving more results in the future. The database query runs fast.
Two questions: how do I detect where the speed slow down occurs? Do I put timers in the Web services code?
I would like to detect whether it is the network or the application code.
This is my first exposure to web services in a real environment so please bear with me.
i used asp.net 2.0 and c# to write a simple web service.
Another good profiler is the EQATEC Profiler. I did a write up on it here: http://elegantcode.com/2009/07/02/eqatec-profiler-and-net-cf-profiling-and-regular-net/
And it works find for .net CF projects. But this will allow you to see if there performance issues in unexpected places.
Your already on the right track of adding event logging, and include timers in them. Note, doing so will add to the over all time it takes, so you'll want to remove them after you track down the culprit. Also look into running the same webservice call multiple-times without re-initiating the connection, that may be cause as well.
-Jay
A starting point is to profile your web service to see where the delay is comming from
Did you know the CLR Profiler? There are some tools you can use to see what is happening
http://msdn.microsoft.com/en-us/library/ms998579.aspx
The database connectivity from your service to the DB could be a possible cause for slowdown. Adding timers should do the trick. If the code isnt too huge, you can look at the coding constructs to come up with an informed decision of where exactly things can be slow. Then add the timers. You would get a fair idea of where things are slowing down.
Two biggest pain points are going to be instantiating the web service reference and transferring all the data over the network. Pending anything turning up where some obvious blunder was made, I would look at ways of reducing the size of your xml and ways of better handling your web service reference.
All I know about the compact framework is that it is a pain to work in. I've worked on a number of web projects though and profiling your server, putting in logging to record the time taken will be helpful. If all the time is being taking post server response, however, it won't do much more than prove your server is working quickly.
SoapUI is a fantastic java application for consuming web services. It has a lot of functionality, including time metrics. I would start with that and see how long it takes to consume the same thing your client would be. Failing issues there, start with what I recommended above.
Is there a summary somewhere of the issues around calling an unmanaged DLL from ASP.NET? I know how to do p-invoke, but does IIS need extra configuration? Is it likely to be a performance or scalability problem? Is it necessary to use COM interop or a mixed-mode assembly? Context: early planning stages of migrating a Windows app to an ASP.NET web app.
The main issue will be that the native code was written in a different context. It expects to be a desktop application, running for a single user, and probably on a single thread. If you run it in ASP.NET, it will be handling multiple users, and will be running on multiple threads at the same time. This can easily break it.
Probably security would be your big problem; I take it your not in some sort of partial trust situation though.
I mean it's obvious; generally you'd avoid it, but if you can't, then do it as little as possible for as least time as possible.
I think many developers know that uncomfortable feeling when users tell them that "The application is slow (again)."
In a complex web application there can be many possible reasons for a degradation in (perceived) performance: slow database response, bandwidth issues, bad caching etc. There certainly are issues which will never occur in a development or staging environment.
Now my question:
Is there a set of tools and/or methods which would provide a comprehensive "live" state on a IIS/ASP.NET/SQL Server production system in a visually way (not just performance counters):
Current HTTP requests (say the last n minutes)
Exceptions / timeouts
Bandwidth data
Number of open database connections / database calls
...
The primary goal is to see at a glance (or after looking closer) what problem is causing the performance problems.
I think the category of software you're looking for is ".net profiler" or ".net tracer". One such tool that you might consider is JetBrains' dotTrace. It gives you runtime stack traces and an array of counters that indicate possible bottlenecks.
Previously mentioned tools will certainly work. At our shop we needed finer information and built our own solution (long story: it was easier to code than to argue about tools and retrievable data).
I used LogParser to flip through the IIS logs and create output reports of those logs (e.g. result code breakdowns etc).
I used a combination of performance counters and WMI values to get the rest - you can read these using some pretty straightforward C# - this gives you full control that you can then dump to .csv etc for viewing/processing in excel or if you are updating a page as a control center.
I would probably also look at IIS.net as a great resource for IIS tools including debugging, security etc.
I followed urig's advice and found this software called SmartInspect.
Does anybody know this logging/monitoring tool? It seems to be a combination of real time console and developer library.
CLR 4.5 will have some new capabilities that will help you monitor ASP.NET performance live - without restarting your app. Basically you can re-JIT your code to include some monitoring-hooks in it, and then inspect time spent in classes/methods etc.
I'm sure dotTrace and other profiling tools will leverage this automatically, but it's worth checking out: C9 - Inside Re-JIT with David Broman