Solved

CPU utilization goes from 10% to 100% gradually over ~60mins of use

Posted on 2004-09-19
11
595 Views
Last Modified: 2008-02-01
I have a CPU creep problem in my application and don't know how to troubleshoot it.  What happens is I will start up the app and turn on perfmon looking specifically at the CPU utilization of the application process and thread count.  The app will start off using about 10% CPU and 8-10 threads.  It gradually increases its load on the CPU and thread consumption over the course of about 60 mins after which time it is using 100% CPU and 60 threads.  I have to suspect that this is some how related to the multithreading but have no idea how to look at what part of the app is causing the CPU creep.  This is my first serious multithreaded app and i'm really at a loss.  I will award points for ideas about how to investigate the problem because it doesn't seem likely that anyone will be able to tell me what line of code is causing the problem... ;-)  Thanks!
0
Comment
Question by:stealth188
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +2
11 Comments
 
LVL 7

Expert Comment

by:sj_hicks
ID: 12099601
Process Explorer from http://www.sysinternals.com give lots of info about running processes such as threads, handles etc.  This might be helpful.
0
 
LVL 18

Accepted Solution

by:
armoghan earned 250 total points
ID: 12102018
0
 

Assisted Solution

by:samitt
samitt earned 50 total points
ID: 12105636
For starters.. you could go to Perfmon and add counter ".NET CLRLocksAndThreads" for your application instance. Keep an eye on total no. of Contentions, Contention rate per second..
0
Creating Instructional Tutorials  

For Any Use & On Any Platform

Contextual Guidance at the moment of need helps your employees/users adopt software o& achieve even the most complex tasks instantly. Boost knowledge retention, software adoption & employee engagement with easy solution.

 
LVL 1

Author Comment

by:stealth188
ID: 12105671
I was using spy++ and saw that there was contention happening, but I don't know how much is 'bad'.  How would I determine that such and such code is producing the contention?  Can you offer any advice?
0
 

Expert Comment

by:samitt
ID: 12106118
It's never very easy to debug... the way I would approach it is to break the app into smaller pieces.. write out log / trace messages at each thread start / stop  and probably with every other line of code..
In a well synchronized world any amount of thread contention should be avoided (but may not always be feasible).
0
 

Expert Comment

by:samitt
ID: 12106130
Are you user a 1 processor system? How is the GC implemented?
0
 
LVL 1

Author Comment

by:stealth188
ID: 12107186
I am using a 3.06 intel with HT.  Not sure how to answer GC question... If that gives you any indication ;)
0
 
LVL 1

Author Comment

by:stealth188
ID: 12107470
Took a look at the Contention Rate/sec.  It starts at about 1/sec and then after a while the couter increments with larger numbers.  It is at that point that the CPU starts to take off so it seems pretty reasonable to conclude that the two are related.  When you posted earlier you talked about writing trace messages when threads start/stop.  What information would be useful and should be included in the trace messages?  Contention is where multiple threads want to use a global variable correct?  there is only one situation where i use synclock in the app so I assume that has to be the source of the problem.  I tried to implement it using the smallest "footprint" possible.  Can you offer some advice on how to structure the synclocks?  Or possibly an alternative?  I am using Synclock to batch some SQL together and have included a code snipet below.  Thanks!

        SyncLock BatchSQL
            BatchSQL.Append(strSQL)
            BatchSQL.Append(";")
            BatchSQLCount += 1

            If BatchSQLCount >= 250 Then
                'If the SQL batch is big enough then copy the batch to a temp string variable and clear the global string variable
                SQLTemp = BatchSQL.ToString

                BatchSQL.Remove(0, BatchSQL.Length)
                BatchSQLCount = 0

                ExecuteBatch = True
            End If
        End SyncLock
0
 
LVL 37

Expert Comment

by:gregoryyoung
ID: 12113540
that is not a long held lock and should not cause too much of an issue.

(form previous questions) there are other variables used within your app that are shared the async io on the socket is a good example.
0
 
LVL 1

Author Comment

by:stealth188
ID: 12115688
I took a look at the .net memory profiler.  I am new to the multithreading scene so it is taking me a while to understand what I am looking at.  What I think I have discovered is that a class I am creating to pass data to a thread is not being freed after the thread is finished.  So the question I think that I want to ask is how do I make sure that I have properly "disposed" of a class that has been used to send data to a thread after the thread has completed its job?
0
 
LVL 37

Assisted Solution

by:gregoryyoung
gregoryyoung earned 200 total points
ID: 12115732
the object is a holder class and will be picked up during garbage collection. This is normal.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

The ECB site provides FX rates for major currencies since its inception in 1999 in the form of an XML feed. The files have the following format (reducted for brevity) (CODE) There are three files available HERE (http://www.ecb.europa.eu/stats/exch…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Michael from AdRem Software outlines event notifications and Automatic Corrective Actions in network monitoring. Automatic Corrective Actions are scripts, which can automatically run upon discovery of a certain undesirable condition in your network.…
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
Suggested Courses

628 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question