slow performance?

  • Thread starter Thread starter =?ISO-8859-1?Q?Hern=E1n_Freschi?=
  • Start date Start date
?

=?ISO-8859-1?Q?Hern=E1n_Freschi?=

Hi all, I'm a completely newbie here. I'm having a problem. I've
programmed before in VB6 and such, and all the programs I've made run
fast. But .NET programs run very slowly. I use C# (for no particular
reason).

It's not the algorithms (that is, what the program * does *, that works
fine), but the UI responsiveness. This programs "hides" in the traybar
and sits there until the phone rings (It's a Caller ID program).

Everything works OK. The number gets identified correctly, the database
is looked up correctly, but the pop up window takes a LONG while to
appear (20 seconds sometimes!). While it's loading, the hard disk works
a lot.

The machine is an Athlon 2200 with 512MB ram and Windows XP Pro, so I
don't think it's a hardware problem. Windows task manager reports that
it's consuming about 18MB of RAM. Seems like too much, because it only
uses a couple of forms. The program is compiled "RELEASE" (not "debug")
in VS 2003. The .exe is 900k.

So, any ideas?

Hernán Freschi
 
Only thing I could see making a form (and your form sounds simple) take a
long time to popup is the database round trip. Comment out the database
lookup and see how long your form takes to pop up. Do you have a large
dataset the query goes through? Are you transferring too much data back to
the client?

Chris
 
Chris said:
Only thing I could see making a form (and your form sounds simple) take a
long time to popup is the database round trip. Comment out the database
lookup and see how long your form takes to pop up. Do you have a large
dataset the query goes through? Are you transferring too much data back to
the client?

Chris
no, actually the database lookup starts after the form loads. that is:

1. phone rings
--->here's where the delay is
2. form loads. actually the form was already loaded but hidden, I show
it with this.Show();

3. mouse cursor to sandclock (by code)
message "Looking up database..." (SHOULD be shown but it doesn't, but
i'll deal with that later)

4. the database is looked up
(no delays here)
5. the number is finally displayed
6. mouse cursor to arrow

the database holds manually-entered numbers and it has less than 30, and
it's indexed and all (it's an access 2002 file).
i *think* the problem is that the program is too large for memory (18
megs) and windows swaps it (that would explain the disk activity).
so is there a way to reduce memory footprint?

hjf
 
How much memory is on the systems? When you call .Show, what triggers doing
the database lookup? Do you call Form.Show, then Form.LookupNumber? It you
rem out the code that does the actual lookup, does the form respond quickly
after the phone ring?

The message "Looking up database..." issue, just do a textbox.update or a
application.doevents to refresh the display.

Chris
 
Chris said:
How much memory is on the systems?
512MB in one and 448 in another one.
When you call .Show, what triggers doing
the database lookup? Do you call Form.Show, then Form.LookupNumber?
Exactly, that's why I don't think it's a database issue. The form should
be shown regardless of the delay of the database, and show the "looking
up data... etc" message.
It you
rem out the code that does the actual lookup, does the form respond quickly
after the phone ring?
No, once the form has been loaded once, it works OK if I don't mess with
the machine (that is, if I don't do nothing, as in leaving it overnight).

It keeps running in the background, waiting for a RING from the modem.

So I work as usual with word/mozilla/messenger/etc. After a while it
seems like if windows unloads it from physical RAM because the program
is idle. Again, the program uses 18MB according to the Task Manager. Are
..NET programs supposed to eat up that much RAM? Even a simple "hello
world" program is *huge* for what I've tested.

After 2 or 3 hours of regular work on the PC, if the phone rings, that's
when the program gets slow. After that it works ok, but after a while
the same happens again.
The message "Looking up database..." issue, just do a textbox.update or a
application.doevents to refresh the display.
I'll try that, thanks

hjf
 
Hernán Freschi said:
512MB in one and 448 in another one.

Exactly, that's why I don't think it's a database issue. The form should
be shown regardless of the delay of the database, and show the "looking up
data... etc" message.
Not true. If you go straight into heavy processing after a Form.Show, you
are not going to see the form. Do an Application.Doevents() after the
Form.Show before doing any processing this will solve that problem, but the
form will be unresponsive until the processing is done. Threading is the
way to solve both issues.

No, once the form has been loaded once, it works OK if I don't mess with
the machine (that is, if I don't do nothing, as in leaving it overnight).
I'm still not 100% sure this isn't a data issue. The form being loaded once
actually sounds like a data cacheing issue, which I have seen effect
performance just like you state. I know I suggested it once, but did you
try bypassing the actual call to the database?
It keeps running in the background, waiting for a RING from the modem.

So I work as usual with word/mozilla/messenger/etc. After a while it seems
like if windows unloads it from physical RAM because the program is idle.
Again, the program uses 18MB according to the Task Manager. Are .NET
programs supposed to eat up that much RAM? Even a simple "hello world"
program is *huge* for what I've tested.
The memory displayed in Task Manager is not an accurate representation of
the memory used by .Net. I don't have any acticles to point you to off
hand, but google will help you find information about this.
After 2 or 3 hours of regular work on the PC, if the phone rings, that's
when the program gets slow. After that it works ok, but after a while the
same happens again.

I'll try that, thanks

hjf

Chris
 
Chris said:
Not true. If you go straight into heavy processing after a Form.Show, you
are not going to see the form. Do an Application.Doevents() after the
Form.Show before doing any processing this will solve that problem, but the
form will be unresponsive until the processing is done. Threading is the
way to solve both issues.

The Application.DoEvents() solved the form not showing "looking up
data...", thanks. I'll see if it also solves the slow loading issue.

I'm still not 100% sure this isn't a data issue. The form being loaded once
actually sounds like a data cacheing issue, which I have seen effect
performance just like you state. I know I suggested it once, but did you
try bypassing the actual call to the database?

Erm.. no :) I need some major modifications in the code to do that (YES
I know the whole point of objects is to avoid that kind of things ;)
I'll do better next time)
The memory displayed in Task Manager is not an accurate representation of
the memory used by .Net. I don't have any acticles to point you to off
hand, but google will help you find information about this.
Yes, I suppose the CLR and stuff eats up some memory, and that my actual
program is just a tiny fraction of that, right?

hjf
 
Hernán Freschi said:
After 2 or 3 hours of regular work on the PC, if the phone rings, that's
when the program gets slow. After that it works ok, but after a while
the same happens again.

I have seen this kind of behavior with some other applications that I use
(none of which are written in C#) . I suspect that Windows may be
swapping out parts of the application, and for some reason, it seems
to be extremely slow when swapping them back in (I haven't clocked
it but it feels like it would be faster to restart the application than wait
for the existing application window to update).

Here's an article I found that might shed some light. I doubt this is
authoritative but I haven't been able to find anything else on this
issue: http://suif.stanford.edu/pub/keepresident/

Hope this helps...

-- jeff
 
I think you are calling methods on the form from another thread. That
does slow down the application a lot (and results in exceptions in
Framework v2.0). Try using BeginInvoke(), that will also help you avoid
using DoEvents().

Regards
Senthil
 
Can you explain this a little bit anyway?

I have tried doing some things in a second program (NOT a .NET program) and
have seen some absurd delays when my .NET program is already loaded. I
wonder if I have triggered a GC pass when I tell the other program to go get
256 MB out of my 1 GB of RAM. One time, this operation takes 2 seconds,
another time it takes one minute. Program 2 REALLY likes physical memory,
and will ALWAYS do this operation in 2 seconds if nothing else is loaded.

With 1 GB of RAM, everything is always fast when my allocated memory (in
Task Manager) is well under 1 GB, but it is sometimes (not always) slow when
I pass this point. Having a clue what to expect of .NET memory handling
might help me.

Thanks!

Tad
 
You need to do long calls separate from the UI so that it doesn't bog
down the thread that draws the screen. No matter what it is you think
it is to do w/ the Data source, trying using an IAsync call, or using
backgroundworker, and separate your UI code from the code that does the
work... you should see improvements in responsiveness.

~m.
 
Back
Top