Advertisement
Guest User

Devart UniDAC Connection pooling

a guest
Aug 14th, 2019
510
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 1.61 KB | None | 0 0
  1. uses Diagnostics, Threading, InterbaseUniProvider, System.TimeSpan;
  2.  
  3.  
  4. procedure SetupConnection(const AUniConn: TUniConnection);
  5. begin
  6.   AUniConn.ProviderName := 'InterBase';
  7.   AUniConn.Server :='localhost';
  8.   AUniConn.Database := 'employee';
  9.   AUniConn.Username := 'SYSDBA';
  10.   AUniConn.Password := 'masterkey';
  11.   AUniConn.LoginPrompt := False;
  12.   AUniConn.PoolingOptions.MaxPoolSize := 100;
  13.   AUniConn.PoolingOptions.MinPoolSize := 2;
  14.   AUniConn.PoolingOptions.ConnectionLifetime := 60000; // 60 seconds
  15.   AUniConn.PoolingOptions.Validate := True;
  16.   AUniConn.Pooling := True;
  17. end;
  18.  
  19. procedure TForm1.Button1Click(Sender: TObject);
  20. var
  21.   LIndex: Integer;
  22.   LStopWatch: TStopWatch;
  23.   LTasks: TArray<ITask>;
  24.  
  25. begin
  26.   LStopWatch := TStopWatch.StartNew;
  27.   LTasks := [];
  28.   for LIndex := 1 to 1000 do
  29.   begin
  30.  
  31.     LTasks := LTasks + [
  32.       TTask.Run(
  33.         procedure
  34.         var
  35.           LConnection: TUniConnection;
  36.           LQuery: TUniQuery;
  37.         begin
  38.           LConnection := TUniConnection.Create(nil);
  39.           try
  40.             SetupConnection(LConnection);
  41.  
  42.             LQuery := TUniQuery.Create(nil);
  43.             try
  44.               LQuery.Connection := LConnection;
  45.               LQuery.SQL.Text := 'select * from EMPLOYEE';
  46.  
  47.               LQuery.Open;
  48.               LQuery.Last;
  49.             finally
  50.               FreeAndNil(LQuery);
  51.             end;
  52.           finally
  53.             FreeAndNil(LConnection);
  54.           end;
  55.         end
  56.       )
  57.     ];
  58.  
  59.   end;
  60.  
  61.   TTask.WaitForAll(LTasks);
  62.   LStopWatch.Stop;
  63.   Button1.Caption := LStopWatch.ElapsedMilliseconds.ToString;
  64. end;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement