Skip to content

Performance optimizations when bulk loading large amounts of timestamps#2194

Merged
lilgreenbird merged 4 commits intomicrosoft:mainfrom
hannes92:main
Nov 2, 2023
Merged

Performance optimizations when bulk loading large amounts of timestamps#2194
lilgreenbird merged 4 commits intomicrosoft:mainfrom
hannes92:main

Conversation

@hannes92
Copy link
Copy Markdown
Contributor

While writing software to sync a couple of hundred million rows from another rdbms to sql server via the BulkCopy API, I discovered a disproportioned amount of time was spent serializing Timestamp objects to then deserialize them into Timestamp objects once again.
My fix for this is to be able to accept Timestamp objects directly (which should cover the majority of objects passed) and only serialize them once when passing the date values to the TDSWriter.

I have attached an example to show the difference while importing about 600k rows with 16 columns with dates only.
image

@hannes92
Copy link
Copy Markdown
Contributor Author

hannes92 commented Aug 15, 2023 via email

@Jeffery-Wasty
Copy link
Copy Markdown
Contributor

Thank you for the PR @hannes92. We'll review it when we're able to and get back to you with our next steps.

@lilgreenbird
Copy link
Copy Markdown
Contributor

could you please add a test which covers the scenario

@hannes92
Copy link
Copy Markdown
Contributor Author

Added a test case, I lowered the mount of rows inserted to 10000 to not slow down the test suite

@Jeffery-Wasty
Copy link
Copy Markdown
Contributor

Hi @hannes92,

The PR passes our internal testing, we'll now be reviewing it.

Comment thread src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java Outdated
Comment thread src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTimestampTest.java Outdated
Comment thread src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTimestampTest.java Outdated
Comment thread src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyTimestampTest.java Outdated
public class BulkCopyTimestampTest extends AbstractTest {

public static final int COLUMN_COUNT = 16;
public static final int ROW_COUNT = 10000;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's not really necessary to do this that many times, just make sure this is run at last once cover the newly added code

Copy link
Copy Markdown
Contributor

@lilgreenbird lilgreenbird left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please make changes as per comments

@lilgreenbird lilgreenbird added this to the 12.5.0 milestone Sep 22, 2023
@lilgreenbird
Copy link
Copy Markdown
Contributor

@hannes92

Comment thread src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java Outdated
Comment thread src/test/java/com/microsoft/sqlserver/jdbc/bulkCopy/BulkCopyAllTypesTest.java Outdated
@tkyc
Copy link
Copy Markdown
Contributor

tkyc commented Oct 18, 2023

After making the newly requested changes, LGTM.

Comment thread src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java Outdated
Comment thread src/main/java/com/microsoft/sqlserver/jdbc/IOBuffer.java Outdated
Comment thread src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java Outdated
Comment thread src/main/java/com/microsoft/sqlserver/jdbc/SQLServerBulkCopy.java Outdated
@lilgreenbird lilgreenbird merged commit a762d7c into microsoft:main Nov 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Closed/Merged PRs

Development

Successfully merging this pull request may close these issues.

4 participants