【问题标题】:Kill a spark action running in a Thread when it is stuck当线程卡住时杀死在线程中运行的火花动作
【发布时间】:2020-12-23 23:50:01
【问题描述】:

我有一个 java 程序,它使用单独线程上的 spark 将配置单元表缓存到内存中。此线程定期触发。 但有时,在缓存后(实际缓存发生时)运行操作(计数)时,作业会卡住。

如果卡住了,我想取消/杀死/停止这个动作。

我想弄清楚如何做以下两件事之一:

  1. 如果耗时超过 10 分钟,则终止此操作。
  2. 或在下次再次触发线程时将其杀死(因为线程会定期触发)。

下面是我的代码:

public class MyThread extends Thread {

    public void run(SparkSession spark) {

        Dataset<Row> dataset = spark.sql("select * from db.table");
        dataset.cache();

        // This is where job gets stuck sometimes. I want to kill/cancel this
        long count = dataset.count();

        System.out.println("Count = " + count);

    }
}

【问题讨论】:

  • 修复卡顿......

标签: java multithreading dataframe apache-spark caching


【解决方案1】:

你的线程因为内存卡住了,你正在使用cache()方法将数据保存到内存中(MEMORY_ONLY

1:尝试使用persist(StorageLevel)可以根据level指定的缓存策略缓存在内存、磁盘或堆外内存中,

2:如果您正在使用 spark-submit 运行作业,请在提交作业时增加以下参数

--num-executors 
--executor-cores  
--executor-memory 
--driver-memory 

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-05
    • 2017-01-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-09
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多