CPU usage extremely high on TS deployment - c#

Our application is written in .NET (framework 3.5). We are experiencing problems with the applications performance when deployed in a terminal services environment. The client is using a TS farm. They have 4GB ram and a decent xeon processor.
When the application is opened in this environment, it sits at 25% CPU usage even when idle. When deployed in a normal client - server environment, it behaves normally, spiking the CPU usage when necessary and drops down to 0 when idle.
Does anyone have any ideas what could be causing this? Or, what I could do to investigate? We have no memory leaks that we can find using performance profiling tools.
This is a WinForms application
We dont have a TS environment avialable to test on
The application is a Business Application.
Basically, capturing and updating of data. Its a massive business application, but there is little multithreading, listeners etc. We do have ANTS profiler (memory / performance) but as mentioned in our environment we dont have the problem - it only occurs on the TS environment

Well, there are a few questions before we can really get you too far.
Is this a Console Application? WinForms Application? or Windows Service?
Do you have a Terminal Services environment available?
What does your application do?
Depending on what the application does, you might check to see if there is unusually high activity on their hardware that you have not accounted for. Examples that I have noticed in the past are items such as having a FileSystemWatcher accidentally listening to a "drop location" for reporting on a client server. Things of that nature, items that while "idle" shouldn't be busy, but are.
Otherwise, if you have the ability to do so, you could also use a tool such as ANTS Profiler from RedGate to see WHAT is using the CPU time on the environment.

Look for sections in your application that constantly repaints the window. Factor those out so that when sitting idle it isn't constantly repainting the window.

Related

clr.Dll!MetaDataGetDispenser and higher than expected CPU usage

I have a Windows Service written in C# which is running on a customer's server and seems to be working fine without any problems, but the CPU usage for this process is often much higher than I would expect. It is never over 50%, but is still a lot higher than the single figures I see when running in house.
This may simply be due to a higher workload, but I was attempting to determine what exactly the service was doing and process explorer is reporting a lot of threads with a start address of clr.Dll!MetaDataGetDispenser, each with small CPU Usage, but they all add up.
Does anyone know what this and what sort of code would be using it?
The service will be using WCF to connect to various clients (and presumably that will involve some sort of serialisation) and will also be accessing a Microsoft SQL Server, but no explicit reflection.

Monitor WCF service memory usage

Good day,
Is there a way to monitor the memory usage of a WCF service?
I Googled and couldn't find any proper answer. Unfortunately I don't have access to 3rd party tools like RedGate ANTS or the JetBrains memory profiler.
I have enabled all performance counters in my service web config in order to see if I can use the Performance Monitor to view the memory usage but I don't know where to look to get the amount of memory being used by the service.
I also created a load test for one of the wcf methods just as a test to see if it can tell me how much memory was used by the service during the test, but also don't think it gives me the info I need.
Does anyone know how I could do this or point me in the right direction?
Thank you in advance.
I you want to watch Performance counters by standart means you should use PerfMon utilite. Launch it from cmd and open System monitor link. There you should add new monitor (CTRL+N). Depending on the CLR version and hosting paramenters of your service you can select two options from the appeared list, which could probably help you:
1) ServiceModelServices (3.0 or 4.0) - monitors the information about your services, number of instances, processor loading, transactions, security, numbers of calls and so on.
2) Memory in CLR. NET - helps you to monitor the memory usage by .NET FrameWork applications. There you should choose your service hosting process (w3wp for IIS for example). After this you can watch the required infromation.

How do I log the CPU/Network usage for my console app, alternative a unittest in c#

I have profiling and optimizing a set of code. For now I have actually just manual looked at the runtime of a unittest and been looking in Resource Manager in windows.
My unit-test now work and everything is working as it should. I would like to documentate my findings, and need to log the CPU and Network Usage instead of just viewing it myself.
If i can do it directly on my unit-test that would be fine, but there properly are some overhead and therefore i did put the code in a console app instead.
How do i easiest log the CPU / Network usage like the number shown in the Resource Manger in windows 8 (its nicely detailed).
Solution for calculating performance CPU / Memory Address
If you want to do it manually, you can add the "namespace"
"System.Diagnostic" and use the class "StopWath" that allows you to
retrieve time to calculate the performance of your applications and
the time to call your functions.
Look here to use the class "StopWath" by microsoft example with
computing performance.
StopWatch How to use it ?
Or else you can also use a fabulous tool called Microsoft "CLR
Profiler" is an application to calculate the performance of your
application. Net C # or ASP. Application complete with visual speech
on the memory and the time between each call over the management of
"garbage collector"
How use Clr profiler
Download Clr profiler
Solution for calculating performance Network traffic
You can use the network simulation from visual studio
Or this applications :
A network sniffer c#
Network sniffer and connection Analyser
sniff web client

High CPU and Memory usage from .NET MVC app

We are seeing a very high amount of CPU and memory usage from one of our .NET MVC apps and can't seem to track down what the cause of it is. Our group does not have access to the web server itself but instead gets notified automatically when certain limits are hit (90+% of CPU or memory). Running locally we can't seem to find the problem. Some items we think might be the culprit
The app has a number of threads running in the background when users take certain actions
We are using memcached (on a different machine than the web server)
We are using web sockets
Other than that the app is pretty standard as far as web applications go. Couple of forms here, login/logout there, some admin capabilities to manage users and data; nothing super fancy.
I'm looking at two different solutions and wondering what would be best.
Create a page inside the app itself (available only to app admins) that shows information about memory and CPU being used. Are there examples of this or is it even possible?
Use some type of 3rd party profiling service or application that gets installed on the web servers and allows us to drive down to find what is causing the high CPU and memory usage in the app.
i recommed the asp.net mvc miniprofiler. http://miniprofiler.com/
it is simple to implement and to extend, can run in production mode, can store its results to SQL Server. i used it many times to find difficult performance issues.
Another possibility is to use http://getglimpse.com/ in combination with the miniprofiler glimpse-plugin https://github.com/mcliment/miniprofiler-glimpse-plugin
both tools are open source and don't require admin access to the server.
You can hook up Preemptive's Runtime Intelligence to it. - http://www.preemptive.com/
Otherwise a profiler, or load test could help find the problem. Do you have anything monitoring the actual machine health? (Processor usage, memory usage, disk queue lengths, etc..).
http://blogs.msdn.com/b/visualstudioalm/archive/2012/06/04/getting-started-with-load-testing-in-visual-studio-2012.aspx
Visual studio has a built-in profiler (depending on version and edition). You may be able to WMI query the web server that has the issues, or write/provide diagnostic recording/monitoring tools to hand them over to someone that does have access.
Do you have any output caching? what version of IIS? Is the 90% processor usage you are getting alerted to showing that your web process is actually the one doing it? ( Perhaps it's not your app if the alert is improperly configured)
I had a similar situation and I created a system monitor to my app admins based on this project

.NET Application very slow after long period of inactivity

I'm not sure if the question title is the best one but it was the best one I could come up with...
I have this .NET (C#) applications which starts up with Windows and remains opened until the computer is turned off. The app stays on the tray and I open it by clicking the tray icon and close it the same way.
The app is not slow at first, it works normally, no problems there. But after long periods of inactivity of itself, it gets very slow when showing it again for the first time in a long period. Know what I mean.
For instance, I could not use/open (click the tray icon) for a few days and between those days I opened and closed and used lots of other apps, heavy apps too and I probably hibernated and resumed the computer a few times and when I needed to open my app again, it was slow. After a few minutes of using it, it goes back to normal and works fine.
I believe this has something to with memory management and the system probably frees up most of my app's memory so other programs can use it more efficiently. And maybe .NET memory management as something to do with it...
Whatever the reason, is there anything I can do to optimize my app regarding that issue?
This is almost certainly due to memory being paged out to disk.
When you cease using your application and other applications or tasks start exerting memory pressure, pages of memory from your app can be written out to disk. When you try to use your application again, all this data must then be read in causing the stalls that you see.
Unfortunately, there is no good solution - if you run as administrator or have the SeLockMemoryPrivilege, you can lock parts of your application into physical memory. You can try "touching" pages periodically to keep them in physical memory. Unfortunately, both these options will cause your application to interact badly with other applications on the system - your memory is getting paged out because the physical memory is needed for something else. You can attempt to lower your overall memory footprint, but you will still run into this issue in some cases. There are options for tweaking your working set size, but the OS is free to ignore those, and will in many cases.
You can use the .NET memory profiler to get a good idea of what your application is doing with memory over time. You can check if anything is building up where you don't expect it to (collections, lists, etc.) and causing your memory footprint to grow.
Have you tried double-clicking in Process Explorer on your running app and observe it for leaks? Is it CPU utilization, UI leak, memory leak, recurrent I/O?
If the issue is indeed that the program is being paged out due to an extended period of inactivity, have you tried setting a "keep-alive" timer, that fires every few minutes, that basically keeps the application in a state where the paging system doesn't ever see it as idle?
I reckon that this behavior is normal in Windows. Windows will serve the application that is need it most, ie, the application that is currently in used. Thus, if an application is minimized or not active for pro-long duration, like the case specified above, it will be the best candidate for Windows to page the application memory and make available memory to active application. Windows will restore the application memory when it get active from paging memory (hard disk), thus this explain why it is slow.
This might be not the best answer, but if I were you, I will experiment by increasing the base priority of the application. This can be done by using Thread object in .NET framework.
Thanks.
This isn't a root cause answer or solution, but if Michael is right and there's nothing you can really do about it, then you might just want to consider visually informing the user that your application is active with a progress bar or nifty progress circle.
It won't speed up your program, but it may ease the minds of your users just a little bit.

Categories

Resources