executor

【转载】spark累加器(详细)

社会主义新天地 提交于 2019-12-21 04:00:46
一、生产常用Spark累加器剖析之一 由于最近在项目中需要用到Spark的累加器,同时需要自己去自定义实现Spark的累加器,从而满足生产上的需求。对此,对Spark的累加器实现机制进行了追踪学习。 本系列文章,将从以下几个方面入手,对Spark累加器进行剖析: Spark累加器的基本概念 累加器的重点类构成 累加器的源码解析 累加器的执行过程 累加器使用中的坑 自定义累加器的实现 Spark累加器基本概念 Spark提供的Accumulator,主要用于多个节点对一个变量进行共享性的操作。Accumulator只提供了累加的功能,只能累加,不能减少累加器只能在Driver端构建,并只能从Driver端读取结果,在Task端只能进行累加。 至于这里为什么只能在Task累加呢?下面的内容将会进行详细的介绍,先简单介绍下: 在Task节点,准确的就是说在executor上; 每个Task都会有一个累加器的变量,被序列化传输到executor端运行之后再返回过来都是独立运行的; 如果在Task端去获取值的话,只能获取到当前Task的,Task与Task之间不会有影响 累加器不会改变Spark lazy计算的特点,只会在Job触发的时候进行相关的累加操作 累加器的重点类介绍 class Accumulator extends Accumulable 源码

Java scheduled executor accuracy

纵然是瞬间 提交于 2019-12-21 03:59:12
问题 There is a peculiarity that I encountered while using Java scheduled executors and was wondering if what I experienced is normal. I need to schedule tasks that execute at a predefined rate of 5 seconds. It is expected that these tasks will take longer than 5 seconds to execute from time to time, but when the time to run them goes below 5 seconds, the backed up list of tasks should run in quick succession to catch up. When running the tasks, it is important to know what the original scheduled

Java8 CompletableFuture 编程

半腔热情 提交于 2019-12-20 12:57:59
一、简介  所谓异步调用其实就是实现一个无需等待被调用函数的返回值而让操作继续运行的方法。在 Java 语言中,简单的讲就是另启一个线程来完成调用中的部分计算,使调用继续运行或返回,而不需要等待计算结果。但调用者仍需要取线程的计算结果。  JDK5新增了 Future 接口,用于描述一个异步计算的结果。虽然 Future 以及相关使用方法提供了异步执行任务的能力,但是对于结果的获取却是很不方便,只能通过阻塞或者轮询的方式得到任务的结果。阻塞的方式显然和我们的异步编程的初衷相违背,轮询的方式又会耗费无谓的 CPU 资源,而且也不能及时地得到计算结果。 private static final ExecutorService POOL = Executors.newFixedThreadPool(TASK_THRESHOLD, new ThreadFactory() { AtomicInteger atomicInteger = new AtomicInteger(0); @Override public Thread newThread(Runnable r) { return new Thread(r, "demo15-" + atomicInteger.incrementAndGet()); } }); public static void main(String[] args)

Spark on YARN两种运行模式介绍

痞子三分冷 提交于 2019-12-20 09:11:30
本文出自:Spark on YARN两种运行模式介绍 http://www.aboutyun.com/thread-12294-1-1.html (出处: about云开发) 问题导读 1.Spark在YARN中有几种模式? 2.Yarn Cluster模式,Driver程序在YARN中运行,应用的运行结果在什么地方可以查看? 3.由client向ResourceManager提交请求,并上传jar到HDFS上包含哪些步骤? 4.传递给app的参数应该通过什么来指定? 5.什么模式下最后将结果输出到terminal中? Spark在YARN中有yarn-cluster和yarn-client两种运行模式: 1.Yarn Cluster Spark Driver首选作为一个ApplicationMaster在Yarn集群中启动,客户端提交给ResourceManager的每一个job都会在集群的worker节点上分配一个唯一的ApplicationMaster, 由该ApplicationMaster管理全生命周期的应用。因为Driver程序在YARN中运行,所以事先不用启动Spark Master/Client,应用的运行结果不能再客户端显示(可以在history server中查看) ,所以最好将结果保存在HDFS而非stdout输出

A good way to bulk download images over http with Java

孤街醉人 提交于 2019-12-19 03:23:07
问题 We have a web application that needs to import 10-20 images from a partner site via http. If I have a list of strings that represent the urls I want to download does anybody have a suggestion for how to download them as fast as possible? I could just put them in a for loop but if there is a simple way to parallelize this it would be probably be good for the end user. I would like to avoid using straight Java threads, although the executor framework might be a good idea. Any ideas? 回答1: The

Java Executor Best Practices for Tasks that Should Run Forever

♀尐吖头ヾ 提交于 2019-12-18 10:04:46
问题 I'm working on a Java project where I need to have multiple tasks running asynchronously. I'm led to believe Executor is the best way for me to do this, so I'm familiarizing myself with it. (Yay getting paid to learn!) However, it's not clear to me what the best way is to accomplish what I'm trying to do. For the sake of argument, let's say I have two tasks running. Neither is expected to terminate, and both should run for the duration of the application's life. I'm trying to write a main

How to stop next thread from running in a ScheduledThreadPoolExecutor

家住魔仙堡 提交于 2019-12-18 09:41:00
问题 I have a ScheduledThreadPoolExecutor which has one thread and runs for every 30 seconds. Now, if the current executing thread throws some exception, then I need to make sure that the next thread do not run and the the ScheduledThreadPoolExecutor is down. How do I achieve this? 回答1: As a clean way, you can simply use a static accessed class to set/check the execution availability. import java.util.concurrent.atomic.AtomicBoolean; class ThreadManager { private static AtomicBoolean shouldStop =

【搞定面试官】谈谈你对JDK中Executor的理解?

旧巷老猫 提交于 2019-12-18 04:37:47
前言 随着当今处理器计算能力愈发强大,可用的核心数量越来越多,各个应用对其实现更高吞吐量的需求的不断增长,多线程 API 变得非常流行。在此背景下,Java自JDK1.5 提供了自己的多线程框架,称为 Executor 框架 . 1. Executor 框架是什么? 1.1 简介 Java Doc中是这么描述的 An object that executes submitted Runnable tasks. This interface provides a way of decoupling task submission from the mechanics of how each task will be run, including details of thread use, scheduling, etc. An Executor is normally used instead of explicitly creating threads. 执行提交的Runnable任务的对象。这个接口提供了一种将任务提交与如何运行每个任务的机制,包括线程的详细信息使用、调度等。通常使用Executor而不是显式地创建线程。 我们可以这么理解:Executor就是一个线程池框架, 在开发中如果需要创建线程可优先考虑使用Executor,无论你需要多线程还是单线程

Spark On YARN内存分配

风格不统一 提交于 2019-12-18 04:26:42
本文转自:http://blog.javachen.com/2015/06/09/memory-in-spark-on-yarn.html?utm_source=tuicool 此文解决了Spark yarn-cluster模式运行时,内存不足的问题。 Spark yarn-cluster模式运行时,注意yarn.app.mapreduce.am.resource.mb的设置。默认为1G Spark On YARN内存分配 本文主要了解Spark On YARN部署模式下的内存分配情况,因为没有深入研究Spark的源代码,所以只能根据日志去看相关的源代码,从而了解“为什么会这样,为什么会那样”。 说明 按照Spark应用程序中的driver分布方式不同,Spark on YARN有两种模式: yarn-client 模式、 yarn-cluster 模式。 当在YARN上运行Spark作业,每个Spark executor作为一个YARN容器运行。Spark可以使得多个Tasks在同一个容器里面运行。 下图是yarn-cluster模式的作业执行图,图片来源于网络: 关于Spark On YARN相关的配置参数,请参考 Spark配置参数 。本文主要讨论内存分配情况,所以只需要关注以下几个内心相关的参数: spark.driver.memory :默认值512m spark

spark架构原理

a 夏天 提交于 2019-12-18 00:53:31
一、spark基础架构 spark和Hadoop的基础架构类似,采用了分布式计算中的Master-Slave模型。 Master是对应集群中的含有Master进程的节点,Slave是集群中含有Worker进程的节点。 1、物理节点逻辑 Master:作为整个集群的控制器,负责整个集群的正常运行,负责接收Client提交的作业,管理Worker,并命令Worker启动Driver和Executor; Worker:相当于是计算节点,负责管理本节点的资源,定期向Master汇报心跳,接收Master的命令,启动Driver和Executor。 Client:作为用户的客户端负责提交应用。 2、管理程序逻辑 Driver: 一个Spark作业运行时包括一个Driver进程,也是作业的主进程,负责作业的解析、生成Stage并调度Task到Executor上。包括DAGScheduler,TaskScheduler。运行在worker,或客户端。并不是运行在master。 Executor:即真正执行作业的地方,一个集群一般包含多个Executor,每个Executor接收Driver的命令Launch Task,一个Executor可以执行一到多个Task。 clusterManager:指的是在集群上获取资源的外部服务。目前有三种类型:1、Standalon,spark原生的资源管理