Jump to content
Soji

FireDAC array DML performance issue

Recommended Posts

Hi,

I am trying to rewrite a piece of legacy code which inserts a number of records in a bulk to SQL server tables(Total number of lines is around 200000 across 15 tables). Currently it uses ADO query to insert multiple records one by one. If the number of records are too high then this process takes a lot of time.

 

I was trying to make it faster and came across FireDAC array DML and according to the documentation, inserting 100000 records can be done less than a second!

 

So I implemented it and in my development machine  (where application and database resides) it improved a lot. From 8 minutes to less than a minute.

But when I tested it on a test environment where application and database resides on different machines connected by a network, performance is worse. (It was taking 10 minutes with ADO and with array DML it takes 15 minutes)
I can't figure it out why array DML insert is taking more time than normal record by record insert. Any ideas?

 

Delphi version:  Delphi 10.4 

SQL Server: 2017

SQL Driver: ODBC DRIVER 17 FOR SQL SERVER

 

Kind regards,

Soji.

Share this post


Link to post

Would suggest using the Microsoft OLE DB Driver for SQL Server - OLE DB Driver for SQL Server | Microsoft Docs instead of ODBC.

 

Without seeing your code it is just guessing why it is slow. Certainly a large difference between local and over the network suggests your code isn't using ArrayDML with a large enough batch size or any batch size at all.  

 

 

 

  • Thanks 1

Share this post


Link to post

Hi Brain,

 

Thanks for your suggestion. But those OLEDB drivers are either not maintained or deprecated.

 

Also FireDAC forces you to use ODBC driver. FireDAC, New OLE DB Driver, and SQL Server

 

I figured out that if I use begin transaction and commit transaction, then the performance increases dramatically. 15 minutes to 1 minute!!!

So I am satisfied with this solution and testing now.

 

Kind regards,

Soji.

Share this post


Link to post

You could probably have used the MSSQL Server Profiler to determine what the server is doing when you run the query.

 

With regard to transactions, I always use explicit transactions.

BeginTransaction;
try
  DoStuff;

  CommitTransaction;
except
  RollbackTransaction;
  raise;
end;

 

Share this post


Link to post

Thanks @Anders Melander

I did exactly same. I saw that even though it executes in the batch, server side it was inserting slowly. 

So I used transactions, it inserted super fast. 

Share this post


Link to post

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×