<?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 Re: Fix Hanging Task in Databricks in Machine Learning</title>
    <link>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3247#M100</link>
    <description>&lt;P&gt;Thank you Suteja. I had watched the resources and had never reached capacity for any. The data was evenly distributed across partitions and groups as well. I did end up taking your advice in (1). I set a timer and killed the process if the group took too long and just used default values in stead. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;</description>
    <pubDate>Thu, 15 Jun 2023 15:49:13 GMT</pubDate>
    <dc:creator>rgbuckley</dc:creator>
    <dc:date>2023-06-15T15:49:13Z</dc:date>
    <item>
      <title>Fix Hanging Task in Databricks</title>
      <link>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3242#M95</link>
      <description>&lt;P&gt;I am applying a pandas UDF to a grouped dataframe in databricks. When I do this, a couple tasks hang forever, while the rest complete quickly.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;I start by repartitioning my dataset so that each group is in one partition:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;group_factors = ['a','b','c'] #masked for anonymity
&amp;nbsp;
model_df = (
    df
    .repartition(
        num_cores, #partition into max number of cores on this compute
        group_factors #partition by group so a group is always in same partition
        )
    )&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;I then group my dataset and apply the udf:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;PRE&gt;&lt;CODE&gt;results = (
model_df #use repartitioned data
    .groupBy(group_factors) #build groups
    .applyInPandas(udf_tune, schema=result_schema) #apply in parallel
    )
&amp;nbsp;
#write results table to store parameters
results.write.mode('overwrite').saveAsTable(table_name)&lt;/CODE&gt;&lt;/PRE&gt;&lt;P&gt;Spark then splits this into tasks equal to the number of partitions. It runs successfully for all but two tasks. Those two tasks do not throw errors, but instead hang until the timeout threshold on the job.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="Spark UI for compute cluster"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/93iB584354657383C31/image-size/large?v=v2&amp;amp;px=999" role="button" title="Spark UI for compute cluster" alt="Spark UI for compute cluster" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;What is strange is that these groups/tasks do not appear to have any irregularities. The record size is similar to the other 58 completed tasks. The code does not throw any errors, so we don't have incorrectly typed or formatted data. Further, this command actually completes successfully about 20% of the time. But most days, we get caught on one or two hanging tasks that cause the job to fail.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The stderr simply notes that the task is hanging:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="stderr for hanging task"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/89i81F3A37E084A9A9E/image-size/large?v=v2&amp;amp;px=999" role="button" title="stderr for hanging task" alt="stderr for hanging task" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The stdout notes an allocation error (although all completed tasks contain the same allocation failure in their stdout files):&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper" image-alt="stdout for hanging task"&gt;&lt;img src="https://community.databricks.com/t5/image/serverpage/image-id/84i8AF905AAD3A6C423/image-size/large?v=v2&amp;amp;px=999" role="button" title="stdout for hanging task" alt="stdout for hanging task" /&gt;&lt;/span&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any suggestions for how to avoid the hanging task issue?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;P.S. When I reduce my data size (for example, splitting model_df into 4 smaller subsets, grouping and applying on each subset, and appending results) I do not run into this issue. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Mon, 12 Jun 2023 18:44:30 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3242#M95</guid>
      <dc:creator>rgbuckley</dc:creator>
      <dc:date>2023-06-12T18:44:30Z</dc:date>
    </item>
    <item>
      <title>Re: Fix Hanging Task in Databricks</title>
      <link>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3243#M96</link>
      <description>&lt;P&gt;Is the stdout log from one of the executors where the task was running or from the driver?&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 11:56:04 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3243#M96</guid>
      <dc:creator>Lakshay</dc:creator>
      <dc:date>2023-06-13T11:56:04Z</dc:date>
    </item>
    <item>
      <title>Re: Fix Hanging Task in Databricks</title>
      <link>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3244#M97</link>
      <description>&lt;P&gt;Both the stdout and stderr are from the executor running the task&lt;/P&gt;</description>
      <pubDate>Tue, 13 Jun 2023 15:41:41 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3244#M97</guid>
      <dc:creator>rgbuckley</dc:creator>
      <dc:date>2023-06-13T15:41:41Z</dc:date>
    </item>
    <item>
      <title>Re: Fix Hanging Task in Databricks</title>
      <link>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3245#M98</link>
      <description>&lt;P&gt;@Gary Buckley​&amp;nbsp;:&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;The hanging tasks issue you're experiencing with the pandas UDF in Databricks can be caused by various factors. Here are a few suggestions to help you troubleshoot and potentially resolve the problem:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;Increase the timeout: The hanging tasks might be related to longer processing times for specific groups. You can try increasing the timeout threshold for your job to give these tasks more time to complete before being considered as failed. You can set the timeout using the spark.databricks.sql.execution.pythonUDFTimeout configuration parameter.&lt;/LI&gt;&lt;LI&gt;Check for resource constraints: The hanging tasks could be a result of resource limitations on your compute cluster. Monitor the resource usage during the job execution, including CPU, memory, and disk utilization. If the hanging tasks consistently occur on specific nodes, it could indicate a resource constraint on those nodes. Consider adjusting the cluster configuration to allocate more resources to alleviate any bottlenecks.&lt;/LI&gt;&lt;LI&gt;Investigate data characteristics: Examine the data characteristics of the groups that experience hanging tasks. Look for any patterns or anomalies in the data that might cause performance issues. For example, if certain groups have significantly larger or more complex data, it could impact the execution time. Analyzing the data distribution and structure can help identify potential causes.&lt;/LI&gt;&lt;LI&gt;Check for data skew: Data skew occurs when a few groups have significantly more data than others, leading to imbalanced processing. Skewed data distribution can result in some tasks taking much longer to complete than others. Use Databricks' built-in data skew optimization techniques, such as the skew() function, to mitigate the impact of data skewness.&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Wed, 14 Jun 2023 07:42:44 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3245#M98</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-06-14T07:42:44Z</dc:date>
    </item>
    <item>
      <title>Re: Fix Hanging Task in Databricks</title>
      <link>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3246#M99</link>
      <description>&lt;P&gt;Hi @Gary Buckley​&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thank you for posting your question in our community! We are happy to assist you.&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;To help us provide you with the most accurate information, could you please take a moment to review the responses and select the one that best answers your question?&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;This will also help other community members who may have similar questions in the future. Thank you for your participation and let us know if you need any further assistance!&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 06:44:51 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3246#M99</guid>
      <dc:creator>Anonymous</dc:creator>
      <dc:date>2023-06-15T06:44:51Z</dc:date>
    </item>
    <item>
      <title>Re: Fix Hanging Task in Databricks</title>
      <link>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3247#M100</link>
      <description>&lt;P&gt;Thank you Suteja. I had watched the resources and had never reached capacity for any. The data was evenly distributed across partitions and groups as well. I did end up taking your advice in (1). I set a timer and killed the process if the group took too long and just used default values in stead. &lt;/P&gt;&lt;P&gt;&lt;/P&gt;&lt;P&gt;Thanks for the help.&lt;/P&gt;</description>
      <pubDate>Thu, 15 Jun 2023 15:49:13 GMT</pubDate>
      <guid>https://community.databricks.com/t5/machine-learning/fix-hanging-task-in-databricks/m-p/3247#M100</guid>
      <dc:creator>rgbuckley</dc:creator>
      <dc:date>2023-06-15T15:49:13Z</dc:date>
    </item>
  </channel>
</rss>

