spark执行优化--禁止将依赖的Jar包传到HDFS(spark.yarn.jar和spark.yarn.archive的使用)

spark执行优化——依赖上传到HDFS(spark.yarn.jar和spark.yarn.archive的使用) 一、简述 使用yarn的方式提交spark应用时,在没有配置spark.yarn.archive或者spark.yarn.jars时, 看到输出的日志在输出Neither spark.yarn.jars nor spark.yarn.archive is set;一段指令后,会看到不停地上传本地jar到HDFS上,内容如下,这个过程会非常耗时。可以通过在spark-defaults.conf配置里添加spark.yarn.archive或spark.yarn.jars来缩小spark应用的启动时间。 Wi 阅读详情

使用yarn的方式提交spark应用时,如果没有配置spark.yarn.archive或者spark.yarn.jars时, 输出的日志在输出Neither spark.yarn.jars nor spark.yarn.archive is set后,会将SPARK_HOME/jars下的所有jar打包并上传到HDFS上,这个过程会非常耗时。可以通过如下2种方法避免此操作,缩小spark应用的启动时间

  1. spark-defaults.conf配置里添加spark.yarn.archive或spark.yarn.jars

  2. 在spark-submit启动参数中,增加:--conf "spark.yarn.archive=hdfs://hdp01:8020/spark-yarn/zip/spark_jars_2.4.0.zip"  或  --conf "spark.yarn.jars=hdfs://hdp01:8020/spark-yarn/jars/*.jar"

要使Spark runtime jars 可以从YARN端访问,可以指定spark.yarn.archive or spark.yarn.jars.

这两个参数的官方定义如下:详见:http://spark.apache.org/docs/2.4.7/running-on-yarn.html

 spark.yarn.jars:包含要分发到YARN容器的Spark代码的库列表。默认情况下,Spark on YARN将使用本地安装的Spark jar,但Spark jar也可以位于HDFS上。这允许YARN将其缓存到节点上,这样就不需要在每次应用程序运行时分发它。例如,要指向HDFS上的jar文件,可以将该配置设置为HDFS:///some/path。

spark.yarn.archive: 一个包含分发到YARN Cache所需的Spark jar的归档文件。如果设置了,这个配置将替换spark.yarn.jars,并且归档文件将在应用程序的所有容器中使用。归档文件的根目录中应该包含jar文件。与前面的选项一样,归档文件也可以托管在HDFS上,以加快文件分发。

注意:如果两个都设置,则spark.yarn.archive的优先级更高。

1. 未设置spark.yarn.archive或者spark.yarn.jars

如果在spark-defaults.conf、spark-submit中都没有设置spark.yarn.archive、spark.yarn.jars参数,则会在日志中提示Neither spark.yarn.jars nor spark.yarn.archive is set, falling back to uploading libraries under SPARK_HOME后,Spark将在$SPARK_HOME/jars下创建一个包含所有jar的zip文件,并将其上传到分布式缓存中。

每个Application都会上传一个这样的zip文件,影响HDFS的性能以及占用HDFS的空间,并且导致启动时间延长。

此zip包在spark 2.4.0版本中,大小约为225MB.


21/04/26 15:34:25 INFO SparkUI: Bound SparkUI to 0.0.0.0, and started at http://172.25.21.134:4040
21/04/26 15:34:25 INFO RMProxy: Connecting to ResourceManager at hdp01/172.25.21.104:8050
21/04/26 15:34:25 INFO Client: Requesting a new application from cluster with 3 NodeManagers
21/04/26 15:34:25 INFO Client: Verifying our application has not requested more than the maximum memory capability of the cluster (76800 MB per container)
21/04/26 15:34:25 INFO Client: Will allocate AM container, with 896 MB memory including 384 MB overhead
21/04/26 15:34:25 INFO Client: Setting up container launch context for our AM
21/04/26 15:34:25 INFO Client: Setting up the launch environment for our AM container
21/04/26 15:34:25 INFO Client: Preparing resources for our AM container
21/04/26 15:34:25 WARN Client: Neither spark.yarn.jars nor spark.yarn.archive is set, falling back to uploading libraries under SPARK_HOME.
21/04/26 15:34:27 INFO Client: Uploading resource file:/tmp/spark-d2d0ee3b-b814-4533-8bff-eb14a306d141/__spark_libs__6295765865935354270.zip -> hdfs://hdp01:8020/user/root/.sparkStaging/application_1619146133746_0029/__spark_libs__6295765865935354270.zip
21/04/26 15:34:31 INFO Client: Uploading resource file:/tmp/spark-d2d0ee3b-b814-4533-8bff-eb14a306d141/__spark_conf__6280792259904379056.zip -> hdfs://hdp01:8020/user/root/.sparkStaging/application_1619146133746_0029/__spark_conf__.zip
21/04/26 15:34:31 INFO SecurityManager: Changing view acls to: root
21/04/26 15:34:31 INFO SecurityManager: Changing modify acls to: root
21/04/26 15:34:31 INFO SecurityManager: Changing view acls groups to:
21/04/26 15:34:31 INFO SecurityManager: Changing modify acls groups to:
21/04/26 15:34:31 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users  with view permissions: Set(root); groups with view permissions: Set(); users  with modify permissions: Set(root); groups with modify permissions: Set()
21/04/26 15:34:32 INFO Client: Submitting application application_1619146133746_0029 to ResourceManager
21/04/26 15:34:32 INFO YarnClientImpl: Submitted application application_1619146133746_0029

    

   

2. 设置spark.yarn.jars

将spark根目录下jars里的所有jar包上传到HDFS

 hdfs dfs -mkdir -p  /spark-yarn/jars
 hdfs dfs -put /opt/spark/jars/* /spark-yarn/jars/

修改spark-defaults.conf (注意:要修改所有节点的),增加此配置:spark.yarn.jars hdfs://hadoop122:9000/spark-yarn/jars/*.jar

或

在spark-submit指定spark.yarn.jars参数: spark-sql --master yarn --conf "spark.yarn.jars=hdfs://hdp01:8020/spark-yarn/jars/*.jar"

可以看到,因为Source and destination file systems are the same,不再上传spark jars,减少了应用启动时间,只上传了应用所需要的配置,不足300kb

21/04/26 15:48:39 INFO SparkUI: Bound SparkUI to 0.0.0.0, and started at http://172.25.21.134:4040
21/04/26 15:48:39 INFO RMProxy: Connecting to ResourceManager at hdp01/172.25.21.104:8050
21/04/26 15:48:39 INFO Client: Requesting a new application from cluster with 3 NodeManagers
21/04/26 15:48:39 INFO Client: Verifying our application has not requested more than the maximum memory capability of the cluster (76800 MB per container)
21/04/26 15:48:39 INFO Client: Will allocate AM container, with 896 MB memory including 384 MB overhead
21/04/26 15:48:39 INFO Client: Setting up container launch context for our AM
21/04/26 15:48:39 INFO Client: Setting up the launch environment for our AM container
21/04/26 15:48:39 INFO Client: Preparing resources for our AM container
21/04/26 15:48:39 INFO Client: Source and destination file systems are the same. Not copying hdfs://hdp01:8020/spark-yarn/jars/JavaEWAH-0.3.2.jar
21/04/26 15:48:39 INFO Client: Source and destination file systems are the same. Not copying hdfs://hdp01:8020/spark-yarn/jars/RoaringBitmap-0.5.11.jar
......
21/04/26 15:48:39 INFO Client: Source and destination file systems are the same. Not copying hdfs://hdp01:8020/spark-yarn/jars/zookeeper-3.4.6.jar
21/04/26 15:48:39 INFO Client: Source and destination file systems are the same. Not copying hdfs://hdp01:8020/spark-yarn/jars/zstd-jni-1.3.2-2.jar
21/04/26 15:48:39 INFO Client: Uploading resource file:/tmp/spark-7435eb56-7303-44e9-882a-4733c406351c/__spark_conf__1185932954890838093.zip -> hdfs://hdp01:8020/user/root/.sparkStaging/application_1619146133746_0032/__spark_conf__.zip
21/04/26 15:48:39 INFO SecurityManager: Changing view acls to: root
21/04/26 15:48:39 INFO SecurityManager: Changing modify acls to: root
21/04/26 15:48:39 INFO SecurityManager: Changing view acls groups to:
21/04/26 15:48:39 INFO SecurityManager: Changing modify acls groups to:
21/04/26 15:48:39 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users  with view permissions: Set(root); groups with view permissions: Set(); users  with modify permissions: Set(root); groups with modify permissions: Set()
21/04/26 15:48:40 INFO Client: Submitting application application_1619146133746_0032 to ResourceManager

   

3. 设置spark.yarn.archive

将spark根目录下jars里的所有jar包上传到HDFS

打包要注意所有的jar都在zip包的根目录中(如果提示没有zip命令,则需要先安装:yum install zip)

cd /opt/spark/jars/
zip -q -r spark_jars_2.4.0.zip *
hdfs dfs -mkdir /spark-yarn/zip
hdfs dfs -put spark_jars_2.4.0.zip /spark-yarn/zip/

修改spark-defaults.conf (注意:要修改所有节点的),增加此配置:spark.yarn.archive hdfs://hdp01:8020/spark-yarn/zip/spark_jars_2.4.0.zip

或

在spark-submit指定spark.yarn.jars参数: spark-sql --master yarn --conf "spark.yarn.archive=hdfs://hdp01:8020/spark-yarn/zip/spark_jars_2.4.0.zip"

可以看到,因为Source and destination file systems are the same. Not copying hdfs://hdp01:8020/spark-yarn/zip/spark_jars_2.4.0.zip,

不再上传spark jars,减少了应用启动时间,只上传了应用所需要的配置,不足300kb

21/04/26 15:57:33 INFO SparkUI: Bound SparkUI to 0.0.0.0, and started at http://172.25.21.134:4040
21/04/26 15:57:33 INFO RMProxy: Connecting to ResourceManager at hdp01/172.25.21.104:8050
21/04/26 15:57:33 INFO Client: Requesting a new application from cluster with 3 NodeManagers
21/04/26 15:57:33 INFO Client: Verifying our application has not requested more than the maximum memory capability of the cluster (76800 MB per container)
21/04/26 15:57:33 INFO Client: Will allocate AM container, with 896 MB memory including 384 MB overhead
21/04/26 15:57:33 INFO Client: Setting up container launch context for our AM
21/04/26 15:57:33 INFO Client: Setting up the launch environment for our AM container
21/04/26 15:57:33 INFO Client: Preparing resources for our AM container
21/04/26 15:57:33 INFO Client: Source and destination file systems are the same. Not copying hdfs://hdp01:8020/spark-yarn/zip/spark_jars_2.4.0.zip
21/04/26 15:57:33 INFO Client: Uploading resource file:/tmp/spark-7ca10ef0-2e82-47f8-86b8-c29db05b6bbe/__spark_conf__6479054559100777354.zip -> hdfs://hdp01:8020/user/root/.sparkStaging/application_1619146133746_0033/__spark_conf__.zip
21/04/26 15:57:34 INFO SecurityManager: Changing view acls to: root
21/04/26 15:57:34 INFO SecurityManager: Changing modify acls to: root
21/04/26 15:57:34 INFO SecurityManager: Changing view acls groups to:
21/04/26 15:57:34 INFO SecurityManager: Changing modify acls groups to:
21/04/26 15:57:34 INFO SecurityManager: SecurityManager: authentication disabled; ui acls disabled; users  with view permissions: Set(root); groups with view permissions: Set(); users  with modify permissions: Set(root); groups with modify permissions: Set()
21/04/26 15:57:35 INFO Client: Submitting application application_1619146133746_0033 to ResourceManager

spark.yarn.archive spark.yarn.jars 的设置 为什么要设置呢?摘自Spark-2.3.0官方文档 http://spark.apache.org/docs/latest/running-on-yarn.html#preparations(个人理解:spark运行所需的jar包,不设置的话每次运行就需要上传到yarn管理的各个节点的缓存,很麻烦很影响性能。如果设置了,比如说放在HDFS上,就不需要每次都上传而是从HDFS上读取,能快那么一点点…... 阅读详情

相关推荐

Spark依赖管理二选一:spark.yarn.archive和spark.yarn.jars到底怎么选?

本文深入探讨Spark依赖管理中spark.yarn.archive与spark.yarn.jars的架构选择,从核心机制、性能测试到决策矩阵,提供全面的优化建议。针对HDFS集群规模、作业特征和成本因素,分析两种方案的优劣,帮助开发者在生产环境中做出最优决策,提升执行效率。

weixin_26789847的博客 361

IDEA版大型Spark2.4架构师系列教程第四季

本课程讲解大规模数据处理的统一分析引擎——Spark2.4。在本课程中基于大量案例实战,深度剖析和讲解Spark2.4原理和新特性,且会包含完全从企业真实业务需求中抽取出的案例实战。除Spark2.4全体系外还包含机器学习、算法、推荐系统等。本套大型Spark2.4架构师系列教程共计13季,本套为第四季。配套资料-答疑专属答疑群购买课程后加入qq群 831186576 (备注订单号后四位)

Amazon EMR生产实战:从踩坑到自愈的深度指南

Amazon EMR是构建云原生数据湖的核心引擎,其本质是基于YARN调度的Spark/Hadoop托管服务,依赖S3作为默认存储层、IAM实现细粒度权限控制,并通过Bootstrap脚本与配置分类(Configurations)完成深度定制。理解其底层资源模型(如vCPU/内存带宽对广播性能的影响)、S3路径前缀与List效率的关系、AQE自适应优化器的启用代价,是避免OOM、卡顿和预算超支的关键。技术价值体现在TB级日志分析分钟级响应、混合Spot/On-Demand成本优化、以及Lambda+Clou

anjichan4261的博客 436

spark.yarn.archive spark.yarn.jars

参考自:http://spark.apache.org/docs/latest/running-on-yarn.html#preparations 在spark on yarn模式下,/usr/local/spark-current2.3/conf下的spark-defaults.conf配置文件有一个spark.yarn.archive配置项 1.如果没有配置 #spark.yarn.a...

我的祖传代码 1557

解决Spark on YARN时大量jar乱飞的情况

问题重现 运行以下这个作业 spark-submit \ --class org.apache.spark.examples.SparkPi \ --master yarn \ --deploy-mode client \ /opt/app/spark-2.4.5-bin-2.6.0-cdh5.16.2/examples/jars/spark-examples_2.12-2.4.5.jar ...

mcdull213的博客 613

别再死磕MuJoCo了!用PyBullet+Stable-Baselines3搞定机械臂强化学习(保姆级环境配置)

本文详细介绍了如何使用PyBullet和Stable-Baselines3构建机械臂强化学习系统,绕过昂贵的MuJoCo许可壁垒。通过实战指南,包括环境配置、机械臂Gym环境构建、训练策略与调优技巧,帮助开发者快速掌握机器人强化学习技术,提升智能控制效率。

weixin_42667269的博客 265

对象存储存大数据的真相:不是不能用,而是必须懂这3个高效场景

对象存储(如S3、OSS、COS)是一种面向海量非结构化数据的分布式存储服务,其核心设计基于HTTP RESTful API与最终一致性模型,天然支持高扩展性与低成本持久化。但因其不支持追加写、原子重命名和低延迟随机读,无法直接替代HDFS等面向计算优化的文件系统。其技术价值在于归档层、输出层与跨云交换枢纽三大不可替代场景,尤其适配只追加(append-only)、大块顺序读、低频更新的数据流。结合Parquet列式格式、合理分区策略(宽而浅)、COSN/S3A连接器调优及Alluxio缓存,可在电商日志、

weixin_30432579的博客 370

window下安装并使用nvm(含卸载node、卸载nvm、全局安装npm)

文章目录一、卸载node二、安装nvm三、配置路径和下载源四、使用nvm安装node五、nvm常用命令六、卸载nvm七、遇到的问题 nvm 全名 node.js version management,顾名思义是一个nodejs的版本管理工具。通过它可以安装和切换不同版本的nodejs。 一、卸载node 如果你已经安装了node,那么你需要先卸载node,如果你没有安装那直接跳过这一步到下一步。 打开控制面板 -> 打开程序和功能 -> 右上角搜索输入node -> 右键卸载 为了确保彻底

HuangsTing的博客 41万+

国赛级Flume配置实战:数据采集链路稳定性设计

Flume作为Hadoop生态原生数据采集工具,其核心价值在于构建高可靠、低延迟、可容灾的数据管道。它通过Source-Channel-Sink三层架构实现数据解耦,依托File Channel保障断电/崩溃场景下的零丢失,结合Interceptor完成结构化解析与元数据增强,再经HDFS Sink直连写入实现毫秒级吞吐。在资源受限的国赛环境(4核8G)中,配置本质是系统工程——需协同JVM内存、磁盘IO、网络带宽与Hadoop Kerberos认证等多维约束。本文聚焦Flume安装配置中的spooldir

weixin_30617797的博客 368

别再死记公式了!用TL072运放设计带通滤波器,调出干净正弦波的实战心得与误区盘点

本文分享了使用TL072运放设计带通滤波器的实战经验,重点解决波形失真问题,提供单电源供电优化、动态调谐技巧及仿真与现实的参数修正方法,帮助工程师调出纯净正弦波。内容涵盖模拟电路设计中的常见误区与解决方案,适合电子工程师和爱好者参考。

weixin_29172963的博客 404

LMX2820即时校准实战:从失锁到稳定锁频的完整指南

本文详细解析了LMX2820锁相芯片在高频段(11.3-22.6GHz)易出现随机失锁问题的根源,并提供了即时校准(InstCal)的完整实战指南。通过寄存器编程、Index例程和校准配置的关键步骤,确保从失锁到稳定锁频的高可靠性,大幅提升射频合成器在通信与测试测量应用中的性能。

bert9linguist的博客 960

数据工程师实战指南:从管道思维到水电系统架构

数据工程不是简单的ETL流水线,而是构建高可靠、可扩展、可治理的数据基础设施。其核心在于理解数据流动的全链路原理——从多源接入、实时/批处理协同、Schema演化控制,到质量防御、血缘追踪与成本精算。技术价值体现在保障数据可信、降低业务使用门槛、支撑实时决策与AI工程化落地。典型应用场景覆盖电商用户行为分析、金融实时风控、SaaS产品AB测试等对一致性、延迟和合规性要求严苛的领域。本文聚焦真实生产环境中的Flink选型、Delta Lake事务实践、数据契约共建与混沌工程治理,揭示数据基建如何成为业务增长的

weixin_30265103的博客 314

37、半导体硅材料中的缺陷与吸杂技术解析

本文系统解析了半导体硅材料中的缺陷形成机制及其对电子器件性能的影响,重点探讨了生长和工艺诱导缺陷、表面与内部微缺陷的起源与特征。文章详细阐述了吸杂技术的原理、过程及在集成电路和太阳能电池制造中的应用,强调通过氧行为调控和热处理优化实现缺陷控制。同时介绍了吸杂效果的评估方法,并展望了未来新型吸杂技术的发展趋势,为提升半导体器件性能和制造良率提供理论支持和技术路径。

mongodb5scout的博客 164

spark.yarn.archive 的正确设置方法

spark.yarn.archive 的设置方法有很多,下面三种 ①spark.yarn.jars hdfs://Desktop:9000/spark/jars/* ②spark.yarn.jars hdfs://Desktop:9000/spark/jars/*.jar ③spark.yarn.jars hdfs://Desktop:9000/spark/jars/ 上述配置真的正确...

微电子学与固体电子学-俞驰 3613

《Python基础教程》内容总览篇(持续更新中)

大家好,我是爱编程的喵喵。双985硕士毕业,现担任全栈工程师一职,热衷于将数据思维应用到工作与生活中。从事机器学习以及相关的前后端开发工作。曾在阿里云、科大讯飞、CCF等比赛获得多次Top名次。现为优快云博客专家、人工智能领域优质创作者。喜欢通过博客创作的方式对所学的知识进行总结与归纳,不仅形成深入且独到的理解,而且能够帮助新手快速入门。个人精心开设的《Python基础课程》专栏订阅量接近900,帮助不少同学解决了Bug。

weixin_43178406的博客 35万+

Linux C/C++ or 嵌入式面试之《C/C++笔面试系列》(10) C++ 前置后置增减运算符重载形式与比较

C语言的++、–运算符在此不讨论。 文章目录1、前置后置增减运算符重载的形式2、前置和后置运算符的性能比较 1、前置后置增减运算符重载的形式 自增运算符“++”和自减运算符“–”分别包含两个版本。即运算符前置形式(如 ++x)和运算符后置形式(如 x++),这两者进行的操作是不一样的。因此,当我们在对这两个运算符进行重载时,就必须区分前置和后置形式。C++根据参数的个数来区分前置和后置形式。如果按照通常的方法来重载 ++ 运算符(即作为成员函数重载时不带参数,或者作为非成员函数重载时带有一个参数),那么重载

二进制君 5831

Spark On Yarn --jars/spark.yarn.jars 踩坑 与 提升spark submit速度

一.引言 Spark submit 可以选择 --jars 传入本地的jar也可以 --jars 传入HDFS的jar包,经过半下午的实验,终于搞清了两者的关系以及 spark.yarn.jars 和它们的区别 二.--jars的使用 1.--jars 传入本地jar包 --jars a.jar,b.jar,c.jar 传入本地jar包时,只需要输入通道机的jar包地址即可,随后spark-submit脚本会执行Uploading resource的操作将本地的jar包拷贝到spar..

BITDDD小栈 6989

低功耗设计-Power Switch

power gating与power switch cell

m0_61544122的博客 1万+

Spark 在YARN上运行

在YARN上运行Spark 安全 在YARN上启动Spark 添加其他JAR 准备工作 组态 调试您的应用程序 Spark特性 重要笔记 的Kerberos YARN特定的Kerberos配置 Kerberos故障排除 配置外部随机播放服务 使用Apache Oozie启动您的应用程序 使用Spark History Server替换Spark Web U...

大强博客 5720

SIMATIC S7-1200, S7-1500 PID 控制[手册]

SIMATIC S7-1200, S7-1500 PID 控制[手册]

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

spark2.2.1中 spark.yarn.jars | spark.yarn.archive的正确配置

【ERROR】 错误: 找不到或无法加载主类 org.apache.spark.deploy.yarn.ExecutorLauncher End Could not find or load main class org.apache.spark.deploy.yarn.ExecutorLauncher Application failed 2 times due to AM Containe...

Gamedev 5084

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

spark.yarn.jars的配置

1.原因: 官方文档 http://spark.apache.org/docs/latest/running-on-yarn.html#preparations To make Spark runtime jars accessible from YARN side, you can specify spark.yarn.archive or spark.yarn.jars. For deta...

xinji 3209

Spark on yarn模式的参数设置即调优

1 启动方式 执行命令./spark-shell --master yarn默认运行的是client模式。 执行./spark-shell --master yarn-client或者./spark-shell --master yarn --deploy-mode client运行的也是client。 执行./spark-shell --master yarn-cluster或者./spar...

6632

Spark Submit --files 添加文件

一.引言 当一个分布式任务中一个文件需要在全局使用时,最常见的方法就是使用广播的形式,在dirver端读取随后分发到excutor,这里需要的时间是 1) dirver端读取文件时间 2) 广播分发到各excutor的时间 当文件大小逐渐增加到一个阈值,或者内存资源有瓶颈时,广播的时间就会变长,这时候就需要和下面这种方式进行比较,看哪种方式时间最快 1) --files 添加文件 2) 直接在excutor读取文件,各个task使用 二.Spark Submit 脚本 --filse 添.

BITDDD小栈 8729

解决sparn yarn-cluster第三方依赖包的加载

1、最简单粗暴的方式, 打一个fatjar. 2、禁止应用程序将依赖的Jar包传到HDFS,将spark-assembly.jar放在该保重。 spark.yarn.jar spark.yarn.jars hdfs://chb0-179004/spark_libs/*.jar spark.yarn.archive 设置后,将不会在上传了 Source and destina...

chbxw 2274

Spark -6:运行Spark on YARN

翻译:http://spark.apache.org/docs/latest/running-on-yarn.html 支持在YARN上运行(Hadoop NextGen)在Spark0.6.0版本,并在以后的版本中得到改进。 在YARN上启动Spark 确保HADOOP_CONF_DIR或YARN_CONF_DIR指向包含Hadoop集群的(客户端)配置文件的目录。

sun 3871

spark-yarn模式的配置

将spark,和修改过的yarn-site.xml,还有创建的软链接分发一下。配置好了hadoop集群,均有python环境。python环境的配置和spark软件的下载。启动hadoop集群。

weixin_52642840的博客 569
上一篇: 如何添加多个jar到spark-submit的classpath?
下一篇: Spark如何正确的写hive分区表
enjoy编程
enjoy编程 领域专家: 大数据技术领域 领域专家: 大数据技术领域
博客等级 码龄20年 4万+粉丝 578原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

enjoy编程

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值