Performance & low memory - Opinion
Posted: Mon 29 Jul 2013 09:07
Hello,
To optimize database queries to get a good balance of speed and low memory usage, this is what I have come up with going through your help and demos. Of all the request, I would say that 90% of them are quick and return small amounts of data, while 10% return large amounts of data.
I have one central routine to get database connections. It hopefully is setup to implement pooling :
function TfdCore.GetDatabaseConnection(const sDatabaseName: RawByteString): TMyConnection;
begin
Result:= TMyConnection.Create(self);
Result.Database:= fdUTF8ToString(sDatabaseName);
Result.Password:= 'password';
Result.Pooling:= true;
Result.PoolingOptions.MaxPoolSize:= 16;
Result.PoolingOptions.MinPoolSize:= 4;
Result.Port:= 12345;
Result.Server:= '127.0.0.1';
Result.Username:= 'username';
end;
I mostly use TMyQuery. This is the way I use them :
daSQLQuery:= TMyQuery.Create(self);
try
daSQLQuery.Connection:= GetDatabaseConnection(databaseName);
daSQLQuery:= TMyQuery.Create(self);
daSQLQuery.FetchAll:= false;
daSQLQuery.FetchRows:= 16;
daSQLQuery.Options.FlatBuffers:= true;
daSQLQuery.Options.StrictUpdate:= false;
daSQLQuery.ReadOnly:= true;
daSQLQuery.UniDirectional:= true;
daSQLQuery.Connection:= GetDatabaseConnection(zRemoteCommand.getDatabaseName);
daSQLQuery.SQL.Text:= fdUTF8ToString(sSQL);
daSQLQuery.Execute;
daSQLQuery.First;
if (not(daSQLQuery.Eof)) then
...
finally
daSQLQuery.Close;
daSQLQuery.Connection.Close;
daSQLQuery.Connection.Disconnect;
FreeAndNil(daSQLQuery);
end;
Is this the good way to use pooling? Is this the best way to get very fast/low memory queries?
Any addition, modification or opinion would be very much appreciated.
Thank you.
Pierre
To optimize database queries to get a good balance of speed and low memory usage, this is what I have come up with going through your help and demos. Of all the request, I would say that 90% of them are quick and return small amounts of data, while 10% return large amounts of data.
I have one central routine to get database connections. It hopefully is setup to implement pooling :
function TfdCore.GetDatabaseConnection(const sDatabaseName: RawByteString): TMyConnection;
begin
Result:= TMyConnection.Create(self);
Result.Database:= fdUTF8ToString(sDatabaseName);
Result.Password:= 'password';
Result.Pooling:= true;
Result.PoolingOptions.MaxPoolSize:= 16;
Result.PoolingOptions.MinPoolSize:= 4;
Result.Port:= 12345;
Result.Server:= '127.0.0.1';
Result.Username:= 'username';
end;
I mostly use TMyQuery. This is the way I use them :
daSQLQuery:= TMyQuery.Create(self);
try
daSQLQuery.Connection:= GetDatabaseConnection(databaseName);
daSQLQuery:= TMyQuery.Create(self);
daSQLQuery.FetchAll:= false;
daSQLQuery.FetchRows:= 16;
daSQLQuery.Options.FlatBuffers:= true;
daSQLQuery.Options.StrictUpdate:= false;
daSQLQuery.ReadOnly:= true;
daSQLQuery.UniDirectional:= true;
daSQLQuery.Connection:= GetDatabaseConnection(zRemoteCommand.getDatabaseName);
daSQLQuery.SQL.Text:= fdUTF8ToString(sSQL);
daSQLQuery.Execute;
daSQLQuery.First;
if (not(daSQLQuery.Eof)) then
...
finally
daSQLQuery.Close;
daSQLQuery.Connection.Close;
daSQLQuery.Connection.Disconnect;
FreeAndNil(daSQLQuery);
end;
Is this the good way to use pooling? Is this the best way to get very fast/low memory queries?
Any addition, modification or opinion would be very much appreciated.
Thank you.
Pierre