Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

Terrible performance problem

Posted on 2006-03-22
14
Medium Priority
?
358 Views
Last Modified: 2012-06-27
Greetings,

I'm having a terrible performance problem where if my program is running, it's using 100% of the processor's available CPU.  I've written an object which tracks thhe time spent is most every function, summarizes the elapsed times by function, and writes them to disk.  But I can't fund what's taking so long.  The values I see are relatively small, 20-250 milliseconds per 15 second period.

Has anybody got a suggestion of how I could approach this problem from a different angle?  I would love ot be able to query Windows to find out what function or functions are using al the processor time.

Has anybody got any idea?  I'm in a serious pickle.


Thanks,
Bob
0
Comment
Question by:ba272
  • 5
  • 5
  • 2
  • +2
14 Comments
 
LVL 28

Assisted Solution

by:strickdd
strickdd earned 400 total points
ID: 16261867
You might want to look into disposing your unused objects. That should help a little bit.
0
 
LVL 10

Assisted Solution

by:dkloeck
dkloeck earned 400 total points
ID: 16262599
If you are using visual studio 2005 you can use the performance profiler

http://msdn.microsoft.com/vstudio/teamsystem/reference/technotes/profiling_windows_apps/perm_profiler.aspx

to start a new performance session go to:
Tools->Performance Tools-> new Performance session
then debug the progrma and after you close it will write a performance protokoll for you, so you can see what funktions are taking more resources and are runned offter,

you also could think about using timers if you wait for something to happen and task managers to run big calculations step by step
0
 
LVL 10

Expert Comment

by:dkloeck
ID: 16262645
maybe this process explorer could help you too:

http://www.sysinternals.com/Utilities/ProcessExplorer.html
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
LVL 21

Accepted Solution

by:
Yurich earned 1000 total points
ID: 16262653
you can start standard windows task manager, switch to the performance tab, then start debugging your program step-by-step and see what's exactly causing this performance problem.

good luck,
yurich
0
 

Author Comment

by:ba272
ID: 16262802
strickdd,

Could you please tell me more about disposing my objects?  As a C++ programmer I can certainly see the importane of this, but never got into that in C# because I thought the garbage collector did that for me.

Yurish, that's a relly cool idea I'll have to try.


Thanks,
Bob
0
 
LVL 21

Expert Comment

by:Yurich
ID: 16263251
the garbage collector takes care of it of course but it's a good practice to release high-resource consuming objects such as all graphics objects (graphics itself, pens, brushes, and etc), io objects, some other stuff - doesn't come to my mind now ;)

good luck,
yurich
0
 

Author Comment

by:ba272
ID: 16263456
I suspect that my problem involves, ata minimum, not closing a database connection.

When using the following objects, which ones need to be closed?  I know I must close the connection and will add the Close() function inside the finally block in the event an exception is thrown.  What else must I close?

Thanks,
Bob

if ( menuItemSqlDataAdapter == null )
{
   menuItemSqlDataAdapter = new SqlDataAdapter( sql, connectString );
   menuItemDataSet = new DataSet();
   menuItemSqlDataAdapter.Fill(menuItemDataSet, "Order_Lines");
}
else
{
   SqlConnection myConnection = new SqlConnection( connectString );
   myConnection.Open();
   SqlCommand sqlCommand = new SqlCommand( sql, myConnection );
   menuItemSqlDataAdapter.SelectCommand = sqlCommand;
   menuItemDataSet.Clear();
   menuItemSqlDataAdapter.Fill( menuItemDataSet, "Order_Lines" );
}
0
 
LVL 21

Expert Comment

by:Yurich
ID: 16263873
in fact, you don't need to call Open or Close for your connection if you're using data adapter - it will handle gracefully openning and closing connection as it needs it.

in terms of database components, you can close only connection (which you don't have to close since you're using adapters) and data reader (which you don't use in your code), everything else (command, relation, parameter, adapter) are not closable.

regs,
yurich
0
 

Author Comment

by:ba272
ID: 16264171
Yurich,

How wouldyou change this:

SqlConnection myConnection = new SqlConnection( connectString );
myConnection.Open();
SqlCommand sqlCommand = new SqlCommand( sql, myConnection );
menuItemSqlDataAdapter.SelectCommand = sqlCommand;
menuItemDataSet.Clear();
menuItemSqlDataAdapter.Fill( menuItemDataSet, "Order_Lines" );

to get rid of the connection so that the SqlDataAdapter can manage the connection?  I tried this but got an exception: Connection property has not been initialized.

SqlCommand sqlCommand = new SqlCommand( sql, myConnection );
menuItemSqlDataAdapter.SelectCommand = sqlCommand;
menuItemDataSet.Clear();
menuItemSqlDataAdapter.Fill( menuItemDataSet, "Order_Lines" );

I'd like to let the SqlDataAdapter manage the connection for me.  Could you tell me how?


Thanks,
Bob
0
 
LVL 21

Expert Comment

by:Yurich
ID: 16264878
SqlDataAdapter can manage only opening and closing connection - it cannot create it, so try this:

SqlConnection myConnection = new SqlConnection( connectString );
SqlCommand sqlCommand = new SqlCommand( sql, myConnection );
menuItemSqlDataAdapter.SelectCommand = sqlCommand;
menuItemDataSet.Clear();
menuItemSqlDataAdapter.Fill( menuItemDataSet, "Order_Lines" );

in fact, you don't have to Clear your dataset every time you fill it as it will get resetted on its own when refilled, so it would be this one:

SqlConnection myConnection = new SqlConnection( connectString );
SqlCommand sqlCommand = new SqlCommand( sql, myConnection );
menuItemSqlDataAdapter.SelectCommand = sqlCommand;
menuItemSqlDataAdapter.Fill( menuItemDataSet, "Order_Lines" );

good luck,
yurich

0
 
LVL 5

Assisted Solution

by:Kelmen
Kelmen earned 200 total points
ID: 16264903
from my understanding of your question, you problem is because CPU is being utilized 100%, but no real performance issue in terms of how long the task get done, right?

As you mentioned you log all processing time lapsed, and all are within damn small timing.

Utilizing CPU 100% isn't really a performance concern IMO.
0
 

Author Comment

by:ba272
ID: 16264942
well there are performance problems, like the cursor flickers and the GUI really suffers when you need to close a program and open a window.  The whole system does bog down.

If the Task Manager shows ~100% utilization as soon as my main window opens, wouldn't that mean there is nothing left for any other process?  I'd like and try to get the utilization down to a level more like it used ot be.  In fact, given that my program runs on a "heartbeat" of 15 seconds, and that most of the work takes a second o two at the most, traditionally I've seen the utilization climb quickly, and sometomes reach 100%, but just as quickly fall again.  But lately it's flatlines at 100%.

Any suggestions to get it down?  (I haven't yet followed the links above.)
0
 
LVL 21

Expert Comment

by:Yurich
ID: 16265186
try debugging with monitoring your performance - the one i advised before.

a continuous resource consumption can be happen if you have a timer for example and very cycle your intialize some resources (graphics, external dll access), in which case it doesn't matter whether you release them or not (i mean if you don't release you'd probably crash your system) but even if you do, you intialize 'em again...

when an application runs it can easily push the cpu usage to 100% but only for a very short time... hmm - have i mentioned debugging with monitoring already?

good luck,
yurich
0
 

Author Comment

by:ba272
ID: 16265504
Thanks for the help all.  Turns out I found the problem by doing a destructive test on my source code.  I deleted various controls from the window in question, then commented out major parts of the code, all to no avail.  Finally when the processor was still maxing at 100%, I used the "break" option under debugging, and I saw the problem.  Many moons ago I had written a parser that determined how many exceptions I had logged to my exceptions text file, so I could display the count on my window.  Well, I had a few bugs which had caused a huge number of exceptions, and that file needed to be parsed every heartbeat.   Dumb!

So thanks,

Bob
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…

564 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