<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Speed Up JDBC Write from Databricks Notebook to MS SQL Server in Data Engineering</title>
    <link>https://community.databricks.com/t5/data-engineering/speed-up-jdbc-write-from-databricks-notebook-to-ms-sql-server/m-p/45114#M27794</link>
    <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;I have a use case where I need to write a delta table from DataBricks to a SQL Server Table using Pyspark/ python/ spark SQL .&lt;/P&gt;&lt;P&gt;The delta table I am writing contains around 3 million records and the SQL Server Table is neither partitioned nor indexed. It is taking around 8-10 min to write into the SQL Server Table no matter what compute I use (using default JDBC driver).&lt;/P&gt;&lt;P&gt;The code being used:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;df.write.mode("overwrite").option("truncate", True ).jdbc(Url, "dbtable" , properties = properties )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have executed this code on DataBricks runtime 11.3LTS using the compute&amp;nbsp;&lt;SPAN&gt;&lt;SPAN class=""&gt;E4ds v4 and&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;E16ds v4 but in both the cases it took 8-10 min.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Can anyone please suggest a way to reduce this time ?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;P.S. I have tried to increase the batch size but even that was not helping. If it was more than 20000 the process became even slower&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Also, I cannot install anything on the cluster according to the client's requirement. But if this is absolutely necessary please let me know what to install and how to install.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;I have tried using the driver "&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;com.microsoft.sqlserver.jdbc.spark&lt;/SPAN&gt;&lt;SPAN&gt;", however, it gave me an error&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;java.lang.ClassNotFoundException: Failed to find data source: com.microsoft.sqlserver.jdbc.spark.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thank You&lt;/P&gt;</description>
    <pubDate>Sat, 16 Sep 2023 15:02:48 GMT</pubDate>
    <dc:creator>berserkersap</dc:creator>
    <dc:date>2023-09-16T15:02:48Z</dc:date>
    <item>
      <title>Speed Up JDBC Write from Databricks Notebook to MS SQL Server</title>
      <link>https://community.databricks.com/t5/data-engineering/speed-up-jdbc-write-from-databricks-notebook-to-ms-sql-server/m-p/45114#M27794</link>
      <description>&lt;P&gt;Hello Everyone,&lt;/P&gt;&lt;P&gt;I have a use case where I need to write a delta table from DataBricks to a SQL Server Table using Pyspark/ python/ spark SQL .&lt;/P&gt;&lt;P&gt;The delta table I am writing contains around 3 million records and the SQL Server Table is neither partitioned nor indexed. It is taking around 8-10 min to write into the SQL Server Table no matter what compute I use (using default JDBC driver).&lt;/P&gt;&lt;P&gt;The code being used:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;df.write.mode("overwrite").option("truncate", True ).jdbc(Url, "dbtable" , properties = properties )&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have executed this code on DataBricks runtime 11.3LTS using the compute&amp;nbsp;&lt;SPAN&gt;&lt;SPAN class=""&gt;E4ds v4 and&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;E16ds v4 but in both the cases it took 8-10 min.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Can anyone please suggest a way to reduce this time ?&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;P.S. I have tried to increase the batch size but even that was not helping. If it was more than 20000 the process became even slower&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;Also, I cannot install anything on the cluster according to the client's requirement. But if this is absolutely necessary please let me know what to install and how to install.&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&lt;SPAN class=""&gt;I have tried using the driver "&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;com.microsoft.sqlserver.jdbc.spark&lt;/SPAN&gt;&lt;SPAN&gt;", however, it gave me an error&amp;nbsp;&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;java.lang.ClassNotFoundException: Failed to find data source: com.microsoft.sqlserver.jdbc.spark.&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;Thank You&lt;/P&gt;</description>
      <pubDate>Sat, 16 Sep 2023 15:02:48 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/speed-up-jdbc-write-from-databricks-notebook-to-ms-sql-server/m-p/45114#M27794</guid>
      <dc:creator>berserkersap</dc:creator>
      <dc:date>2023-09-16T15:02:48Z</dc:date>
    </item>
    <item>
      <title>Re: Speed Up JDBC Write from Databricks Notebook to MS SQL Server</title>
      <link>https://community.databricks.com/t5/data-engineering/speed-up-jdbc-write-from-databricks-notebook-to-ms-sql-server/m-p/103840#M41571</link>
      <description>&lt;P class="_1t7bu9h1 paragraph"&gt;&lt;SPAN&gt;You can partition the DataFrame in PySpark before writing it to SQL Server. For example:&lt;/SPAN&gt;&lt;/P&gt;
&lt;DIV class="gb5fhw2"&gt;
&lt;PRE&gt;&lt;CODE class="markdown-code-python _1t7bu9hb hljs language-python gb5fhw3"&gt;df.repartition(&lt;SPAN class="hljs-number"&gt;10&lt;/SPAN&gt;).write.mode(&lt;SPAN class="hljs-string"&gt;"overwrite"&lt;/SPAN&gt;).option(&lt;SPAN class="hljs-string"&gt;"truncate"&lt;/SPAN&gt;, &lt;SPAN class="hljs-literal"&gt;True&lt;/SPAN&gt;).jdbc(Url, &lt;SPAN class="hljs-string"&gt;"dbtable"&lt;/SPAN&gt;, properties=properties)&lt;/CODE&gt;&lt;/PRE&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 01 Jan 2025 19:30:20 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/speed-up-jdbc-write-from-databricks-notebook-to-ms-sql-server/m-p/103840#M41571</guid>
      <dc:creator>NandiniN</dc:creator>
      <dc:date>2025-01-01T19:30:20Z</dc:date>
    </item>
    <item>
      <title>Re: Speed Up JDBC Write from Databricks Notebook to MS SQL Server</title>
      <link>https://community.databricks.com/t5/data-engineering/speed-up-jdbc-write-from-databricks-notebook-to-ms-sql-server/m-p/103841#M41572</link>
      <description>&lt;P&gt;&lt;A href="https://docs.databricks.com/en/connect/external-systems/jdbc.html#control-parallelism-for-jdbc-queries" target="_blank"&gt;https://docs.databricks.com/en/connect/external-systems/jdbc.html#control-parallelism-for-jdbc-queries&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;When writing to databases using JDBC, Apache Spark uses the number of partitions in memory to control parallelism. You can repartition data before writing to control parallelism. Avoid high number of partitions on large clusters to avoid overwhelming your remote database. The following example demonstrates repartitioning to eight partitions before writing:&lt;/P&gt;
&lt;DIV class="clt-tabs clt-tabs--literal"&gt;
&lt;DIV class="clt-tabs__content"&gt;
&lt;DIV id="8-language-python" class="compound-first highlight-python notranslate clt-tabs-content clt-tabs-content--selected" role="tabpanel" data-lang="language-python" aria-controlled-by="8-anchor-language-python" aria-hidden="false"&gt;
&lt;DIV class="highlight"&gt;
&lt;PRE&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="n"&gt;employees_table&lt;/SPAN&gt;&lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;repartition&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="mi"&gt;8&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
  &lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;write&lt;/SPAN&gt;
  &lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;format&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;"jdbc"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
  &lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;option&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;"url"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;"&amp;lt;jdbc-url&amp;gt;"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
  &lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;option&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;"dbtable"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;"&amp;lt;new-table-name&amp;gt;"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
  &lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;option&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;"user"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;"&amp;lt;username&amp;gt;"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
  &lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;option&lt;/SPAN&gt;&lt;SPAN class="p"&gt;(&lt;/SPAN&gt;&lt;SPAN class="s2"&gt;"password"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;,&lt;/SPAN&gt; &lt;SPAN class="s2"&gt;"&amp;lt;password&amp;gt;"&lt;/SPAN&gt;&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;
  &lt;SPAN class="o"&gt;.&lt;/SPAN&gt;&lt;SPAN class="n"&gt;save&lt;/SPAN&gt;&lt;SPAN class="p"&gt;()&lt;/SPAN&gt;
&lt;SPAN class="p"&gt;)&lt;/SPAN&gt;&lt;/PRE&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;
&lt;/DIV&gt;</description>
      <pubDate>Wed, 01 Jan 2025 19:32:14 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/speed-up-jdbc-write-from-databricks-notebook-to-ms-sql-server/m-p/103841#M41572</guid>
      <dc:creator>NandiniN</dc:creator>
      <dc:date>2025-01-01T19:32:14Z</dc:date>
    </item>
    <item>
      <title>Re: Speed Up JDBC Write from Databricks Notebook to MS SQL Server</title>
      <link>https://community.databricks.com/t5/data-engineering/speed-up-jdbc-write-from-databricks-notebook-to-ms-sql-server/m-p/103842#M41573</link>
      <description>&lt;P&gt;&lt;A href="https://spark.apache.org/docs/latest/sql-data-sources-jdbc.html" target="_blank"&gt;https://spark.apache.org/docs/latest/sql-data-sources-jdbc.html&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;TABLE&gt;
&lt;TBODY&gt;
&lt;TR&gt;
&lt;TD&gt;&lt;CODE&gt;numPartitions&lt;/CODE&gt;&lt;/TD&gt;
&lt;TD&gt;(none)&lt;/TD&gt;
&lt;TD&gt;The maximum number of partitions that can be used for parallelism in table reading and writing. This also determines the maximum number of concurrent JDBC connections. If the number of partitions to write exceeds this limit, we decrease it to this limit by calling&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;CODE&gt;coalesce(numPartitions)&lt;/CODE&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;before writing.&lt;/TD&gt;
&lt;TD&gt;
&lt;P&gt;read/write&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;/TD&gt;
&lt;/TR&gt;
&lt;/TBODY&gt;
&lt;/TABLE&gt;</description>
      <pubDate>Wed, 01 Jan 2025 19:33:55 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/speed-up-jdbc-write-from-databricks-notebook-to-ms-sql-server/m-p/103842#M41573</guid>
      <dc:creator>NandiniN</dc:creator>
      <dc:date>2025-01-01T19:33:55Z</dc:date>
    </item>
    <item>
      <title>Re: Speed Up JDBC Write from Databricks Notebook to MS SQL Server</title>
      <link>https://community.databricks.com/t5/data-engineering/speed-up-jdbc-write-from-databricks-notebook-to-ms-sql-server/m-p/104054#M41652</link>
      <description>&lt;P&gt;&lt;a href="https://community.databricks.com/t5/user/viewprofilepage/user-id/44166"&gt;@berserkersap&lt;/a&gt;&amp;nbsp;have you had time to identify where's the bottleneck? e.g.: sequential writes, network latency/throughput, or maybe you have a connection pool in the target much lower than the number of connection threads in the source?&lt;/P&gt;</description>
      <pubDate>Fri, 03 Jan 2025 10:51:28 GMT</pubDate>
      <guid>https://community.databricks.com/t5/data-engineering/speed-up-jdbc-write-from-databricks-notebook-to-ms-sql-server/m-p/104054#M41652</guid>
      <dc:creator>VZLA</dc:creator>
      <dc:date>2025-01-03T10:51:28Z</dc:date>
    </item>
  </channel>
</rss>

