Terrible performance problem

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
ba272Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

strickddCommented:
You might want to look into disposing your unused objects. That should help a little bit.
0
dkloeckCommented:
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
dkloeckCommented:
maybe this process explorer could help you too:

http://www.sysinternals.com/Utilities/ProcessExplorer.html
0
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

YurichCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ba272Author Commented:
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
YurichCommented:
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
ba272Author Commented:
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
YurichCommented:
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
ba272Author Commented:
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
YurichCommented:
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
KelmenCommented:
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
ba272Author Commented:
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
YurichCommented:
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
ba272Author Commented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.