我们使用 Spark 集群作为 yarn-client
计算几个业务,但有时我们有一个任务运行时间太长:
我们没有设置超时,但我认为默认超时时间不会太长,比如这里( 1.7h )。
有人给我一个解决这个问题的理想吗???
最佳答案
如果时间过长,spark 就无法终止它的任务。
但是我想出了一种使用 speculation 来处理这个问题的方法,
This means if one or more tasks are running slowly in a stage, they will be re-launched.
spark.speculation true
spark.speculation.multiplier 2
spark.speculation.quantile 0
注:
spark.speculation.quantile
意味着“推测”将从您的第一个任务开始。所以请谨慎使用。我使用它是因为随着时间的推移,由于 GC,一些作业会变慢。所以我认为你应该知道什么时候使用它——它不是 Elixir 。一些相关链接:http://apache-spark-user-list.1001560.n3.nabble.com/Does-Spark-always-wait-for-stragglers-to-finish-running-td14298.html和 http://mail-archives.us.apache.org/mod_mbox/spark-user/201506.mbox/%3CCAPmMX=rOVQf7JtDu0uwnp1xNYNyz4xPgXYayKex42AZ_9Pvjug@mail.gmail.com%3E
更新
我找到了解决我的问题的方法(可能不适用于所有人)。每个任务我都有一堆模拟运行,所以我在运行周围添加了超时。如果模拟需要更长的时间(由于该特定运行的数据偏差),它将超时。
ExecutorService executor = Executors.newCachedThreadPool();
Callable<SimResult> task = () -> simulator.run();
Future<SimResult> future = executor.submit(task);
try {
result = future.get(1, TimeUnit.MINUTES);
} catch (TimeoutException ex) {
future.cancel(true);
SPARKLOG.info("Task timed out");
}
确保您在
simulator
内处理中断的主循环如:if(Thread.currentThread().isInterrupted()){
throw new InterruptedException();
}
关于apache-spark - 如何处理 yarn 客户端中运行时间过长的任务(与其他工作相比)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31799755/