?
Solved

Delphi 7 - Slow Application

Posted on 2009-04-21
26
Medium Priority
?
272 Views
Last Modified: 2013-11-05
Hi,
I created application (APP1) that uses a MySql database. Many customers have said that the program works very well and is very fast after a bit of time leave standby APP1 and do other things. When returning to use APP1 notice very slow in the insertion of data and go in Task Manager APP1 uses 80 % of the CPU.
Greetings.
0
Comment
Question by:danz67
  • 11
  • 7
  • 6
  • +1
26 Comments
 
LVL 8

Expert Comment

by:BdLm
ID: 24202155
you can try to download a profile for delphi and check to slow lines of code
0
 
LVL 8

Expert Comment

by:BdLm
ID: 24202169
0
 

Author Comment

by:danz67
ID: 24202331
Ok i try it, but the problem is when APP1 is in standby
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 19

Expert Comment

by:MerijnB
ID: 24202751
Do you have separate threads in your application?
0
 

Author Comment

by:danz67
ID: 24202835
I don't know
0
 
LVL 8

Expert Comment

by:BdLm
ID: 24202940
May be the MYSQL connection is in a separate thread, can you check the taskmanager in WIN, how many processes are created when running your app1.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 24203107
> I don't know.

What do you use to connect to the MySQL server?

0
 

Author Comment

by:danz67
ID: 24203507
MerijnB:
> What do you use to connect to the MySQL server?

CoreLab
0
 

Author Comment

by:danz67
ID: 24204552
BdLm:
>May be the MYSQL connection is in a separate thread, can you check the taskmanager in WIN, how many processes are created

Only one
0
 

Author Comment

by:danz67
ID: 24207610
Maybe the proble is here
list.bmp
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24209169
some connections close the active connection after a certain time being idle (firewall can do this too)

it's possible you make a new connection after closing ...
do you use connection pooling ?
if so, does switching it off help ?

It's in the TMyDac Connection object properties
0
 

Author Comment

by:danz67
ID: 24209445
Pooling is false in proprieties.
0
 
LVL 38

Accepted Solution

by:
Geert Gruwez earned 1500 total points
ID: 24211859
it seems like your app is running multiple times ...
do you need this, if not you can prevent this with a Semaphore  ...
just use this unit in your project
unit uAppInstances;
 
interface
 
const
  MultiApp = False;
 
implementation
 
uses Forms, SysUtils, Windows;
 
var 
  SemHandle: THandle;
 
function CheckSemaphore(sem: string; var SemaphoreHandle: THandle): boolean;
var
  SemName: string;
begin
  Result := MultiApp;
  if not Result then
  begin
    SemName := Sem + ExtractFileName(Application.ExeName);
    SemaphoreHandle := CreateSemaphore(nil, 0, 1, PCHAR(SemName));
    if (SemaphoreHandle <> 0) and (GetLastError() = ERROR_ALREADY_EXISTS) then
    begin
      CloseHandle(SemaphoreHandle);
      MessageBox(0, PChar('Application allready running!!!'), PChar('Warning'), SW_SHOWNORMAL);
    end else
      Result := True;
  end;
end;
 
procedure CloseSemaphore(SemaphoreHandle: THandle);
begin
  CloseHandle(SemaphoreHandle);
end;
 
initialization
  if not CheckSemaphore('SeMaPhORe', SemHandle) then
  begin
    Halt;
    Exit;
  end;
finalization
  CloseSemaphore(SemHandle);
end.

Open in new window

0
 

Author Comment

by:danz67
ID: 24212041
I tried this unit in the project and if I try to start for the second time app1 warns me that is already running. This is good, but are sure this is the problem? When app1 is running in task manager I see only one process. You say something else in your project use different DataModule and each has a connection that starts at startup app1, probably this is that create different connections to MySql.
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24212137
well, there is more than 1 possibility:
a: multiple connections with 1 app
b: multiple connections with multiple apps
c: 1 connection with multiple app

i guess you don't want any of these, unless option a if you are using threads.

so ... are you using threads in your app ?
0
 

Author Comment

by:danz67
ID: 24212412
I use APP1 with multiple connections to the server MySql, but believe that this can slow APP1 after a bit of time?
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24213870
what are you doing with the multiple connections ?
are you creating them on the fly (adding them as you need)
and not freeing them ?
0
 

Author Comment

by:danz67
ID: 24214207
connections are open to the start of app1 and are never closed
0
 
LVL 8

Expert Comment

by:BdLm
ID: 24217732
could try the profiler, which function is getting that slow?
0
 

Author Comment

by:danz67
ID: 24218059
Are unable to use it.
0
 
LVL 8

Expert Comment

by:BdLm
ID: 24222481
which profiler did you try to use?
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24222823
if you do not have separate threads in your app, it's no use of having more than 1 connection.
1 connection will just wait on an other in the same thread.

so you need to know if you are creating more than 1 thread

if you don't know how, try search / find in files to look for something like this  "class(TThread)"

type
  TMyThread = class(TThread)
  ...
  protected
    procedure Execute; override;
  ...
  end;


0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24222825
did you create this app yourself ?
0
 
LVL 8

Expert Comment

by:BdLm
ID: 24223094
@ Geert_Gruwez:

I have a simillar problem (unsolved) using INDY Client Server  (Win2K, D7, Indy 9)
 test#i :  INDY SERVER APPLICATION using 100 % CPU  -> good
 test #i+1 : INDY SERVER APPLICATION using 30 % CPU -> I get crazy
test #i+2 : INDY SERVER APPLICATION using 80 % CPU -> waiting ....

occurence Random, no idea how to fix that issue. no time for profiling that code.
used the profiler for other issues

0
 

Author Comment

by:danz67
ID: 24223103
Geert_Gruwez: did you create this app yourself ?

Yes
0
 
LVL 38

Expert Comment

by:Geert Gruwez
ID: 24913538
i'm having the same problem with some of my apps for oracle
after sleep, it seems to do some stuff for 5-10 minutes and then stops

maybe some of the db processes stop and then take a while to start again
0

Featured Post

Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

Question has a verified solution.

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

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
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…
Suggested Courses

578 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