- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我知道在 HDFS 中读取大量小文件的问题一直是一个问题并被广泛讨论,但请耐心等待。大多数处理此类问题的 stackoverflow 问题都与读取大量 txt 文件有关。我正在尝试读取大量小型 avro 文件
此外,这些阅读 txt 文件解决方案谈到使用作为 RDD 实现的 WholeTextFileInputFormat 或 CombineInputFormat ( https://stackoverflow.com/a/43898733/11013878 ),我使用的是 Spark 2.4 (HDFS 3.0.0) 并且通常不鼓励使用 RDD 实现,并且首选数据帧。我更喜欢使用数据帧,但也对 RDD 实现持开放态度。
我已经尝试按照 Murtaza 的建议合并数据帧,但是在大量文件中出现 OOM 错误( https://stackoverflow.com/a/32117661/11013878 )
我正在使用以下代码
val filePaths = avroConsolidator.getFilesInDateRangeWithExtension //pattern:filePaths: Array[String]
//I do need to create a list of file paths as I need to filter files based on file names. Need this logic for some upstream process
//example : Array("hdfs://server123:8020/source/Avro/weblog/2019/06/03/20190603_1530.avro","hdfs://server123:8020/source/Avro/weblog/2019/06/03/20190603_1531.avro","hdfs://server123:8020/source/Avro/weblog/2019/06/03/20190603_1532.avro")
val df_mid = sc.read.format("com.databricks.spark.avro").load(filePaths: _*)
val df = df_mid
.withColumn("dt", date_format(df_mid.col("timeStamp"), "yyyy-MM-dd"))
.filter("dt != 'null'")
df
.repartition(partitionColumns(inputs.logSubType).map(new org.apache.spark.sql.Column(_)):_*)
.write.partitionBy(partitionColumns(inputs.logSubType): _*)
.mode(SaveMode.Append)
.option("compression","snappy")
.parquet(avroConsolidator.parquetFilePath.toString)
最佳答案
由于读取大量小文件花费的时间太长,我退后一步,使用CombineFileInputFormat 创建了RDD。 This InputFormat 适用于小文件,因为它将许多文件打包成一个拆分,因此映射器较少,并且每个映射器都有更多的数据要处理。
这是我所做的:
def createDataFrame(filePaths: Array[Path], sc: SparkSession, inputs: AvroConsolidatorInputs): DataFrame = {
val job: Job = Job.getInstance(sc.sparkContext.hadoopConfiguration)
FileInputFormat.setInputPaths(job, filePaths: _*)
val sqlType = SchemaConverters.toSqlType(getSchema(inputs.logSubType))
val rddKV = sc.sparkContext.newAPIHadoopRDD(
job.getConfiguration,
classOf[CombinedAvroKeyInputFormat[GenericRecord]],
classOf[AvroKey[GenericRecord]],
classOf[NullWritable])
val rowRDD = rddKV.mapPartitions(
f = (iter: Iterator[(AvroKey[GenericRecord], NullWritable)]) =>
iter.map(_._1.datum()).map(genericRecordToRow(_, sqlType))
, preservesPartitioning = true)
val df = sc.sqlContext.createDataFrame(rowRDD ,
sqlType.dataType.asInstanceOf[StructType])
df
object CombinedAvroKeyInputFormat {
class CombinedAvroKeyRecordReader[T](var inputSplit: CombineFileSplit, context: TaskAttemptContext, idx: Integer)
extends AvroKeyRecordReader[T](AvroJob.getInputKeySchema(context.getConfiguration))
{
@throws[IOException]
@throws[InterruptedException]
override def initialize(inputSplit: InputSplit, context: TaskAttemptContext): Unit = {
this.inputSplit = inputSplit.asInstanceOf[CombineFileSplit]
val fileSplit = new FileSplit(this.inputSplit.getPath(idx),
this.inputSplit.getOffset(idx),
this.inputSplit.getLength(idx),
this.inputSplit.getLocations)
super.initialize(fileSplit, context)
}
}
}
/*
* The class CombineFileInputFormat is an abstract class with no implementation, so we must create a subclass to support it;
* We’ll name the subclass CombinedAvroKeyInputFormat. The subclass will initiate a delegate CombinedAvroKeyRecordReader that extends AvroKeyRecordReader
*/
class CombinedAvroKeyInputFormat[T] extends CombineFileInputFormat[AvroKey[T], NullWritable] {
val logger = Logger.getLogger(AvroConsolidator.getClass)
setMaxSplitSize(67108864)
def createRecordReader(split: InputSplit, context: TaskAttemptContext): RecordReader[AvroKey[T], NullWritable] = {
val c = classOf[CombinedAvroKeyInputFormat.CombinedAvroKeyRecordReader[_]]
val inputSplit = split.asInstanceOf[CombineFileSplit]
/*
* CombineFileRecordReader is a built in class that pass each split to our class CombinedAvroKeyRecordReader
* When the hadoop job starts, CombineFileRecordReader reads all the file sizes in HDFS that we want it to process,
* and decides how many splits base on the MaxSplitSize
*/
return new CombineFileRecordReader[AvroKey[T], NullWritable](
inputSplit,
context,
c.asInstanceOf[Class[_ <: RecordReader[AvroKey[T], NullWritable]]])
}
}
关于scala - Spark 集群 : Read Large number of small avro files is taking too long to list,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56962341/
由于 PostgreSQL 人员选择的术语不当,这会让一些人感到困惑,但请耐心等待... 我们需要能够支持多个 PostgreSQL (PG) 集群,并将它们集群在多个服务器上,例如使用repmgr.
Hadoop会跑很多jobs,从Hbase读取数据,写数据到数据库。假设我有 100 个节点,那么有两种方法可以构建我的 Hadoop/Hbase集群: 100节点hadoop&hbase集群(1个b
在kafka中,我们能创建多种类型的集群,一般如下: 单节点——单个broker集群 单节点——多broker集群 多结点——多broker集群 kafka集群中主要有五个组件: Topic:主题主要
我想在两台机器上运行我的 MPI 程序,一台是 ubuntu 18.04,另一台是 Windows 10。是否可以使用不同的操作系统组成一个集群? (我正在使用 MPICH) 如果可能,怎么做?我在网
简介: 更新负载平衡集群中的节点的最佳实践是什么? 我们在 ha 代理负载均衡器后面使用 RabbitMQ 集群来支持我们的客户端轻松集群,as suggested in the RabbitMQ d
我正在尝试创建一个图表,我明确指定了许多节点的等级并指定了集群。以下代码生成我想要的图形类型: digraph { rankdir=LR subgraph cluster0 {
我正在尝试在 RABBITMQ 上进行集群。我添加了 2 个节点,但无法添加第 3 个节点。我已经聚集了 rabbit@node1 和 rabbit@node2。现在我正在尝试将 rabbit@nod
我在 MS Azure 的生产环境中启用了一个双集群多区域 HA。 我被要求重用同一个集群来使用微服务管理几个新项目。 这里的最佳做法是什么?我应该为每个应用程序创建一个集群吗?将不同集群中的每个项目
我正在尝试 flex 搜索,并且很难在具有3个 flex 搜索实例的单台计算机上创建集群。我对实例进行了以下更改: 在所有实例上更改了群集名称{cluster.name:es-stack} 在所有实例
我想创建一个redis集群,仅将特定的redis主机作为主服务器和从服务器。另外,我想自己指定哪个主机应该是哪个主机的副本。 目前,cluster-create command当在任何一个 Redis
我计划在具有负载平衡的集群中设置 Magento,那么是否可以让两个 Magento 安装指向同一个数据库? 如果可能的话 - 我应该如何配置这些服务器的基本 URL?服务器应该具有相同的名称吗? 最
我目前正在计划一个 Web 应用程序,我想计划它最终在集群上运行。 集群将由一个 php web 集群和一个 mysql 集群以及一个独立的存储单元组成(也许是一个集群,我真的不知道它是如何工作的:s
我已经安装了 elasticsearch 2.2.3 并在 2 个节点的集群中配置 节点 1 (elasticsearch.yml) cluster.name: my-cluster node.nam
我正在寻找现有的中间件解决方案,以解决服务集群/分布方面的问题,以实现负载平衡和可用性。我正在考虑基于消息传递系统(更具体地说,JMS)为此构建自己的基础设施。但是,如果可能的话,我宁愿使用已经存在的
在 Hadoop 集群中,数据是自动跨数据节点复制还是必须编程? 如果必须编程,那我该怎么做呢? 最佳答案 dfs.replication 的默认值为 3。这存在于您的 hdfs.site.xml 中
我已经设置了一个具有 1 个主节点和 2 个从节点的 redis 集群,哨兵在所有 3 个节点上运行。 在此设置之前,我的应用程序指向运行 Redis 实例的单个节点。 集群搭建完成后,我的应用应该指
所以,我正在设计一个具有多个 redis 实例的分布式系统来分解大量的流式写入,但发现很难清楚地了解事情是如何工作的。 从我读到的内容来看,正确配置的集群似乎会自动对“错误实例”上的请求进行分片和重定
我有一个关于redis集群架构的问题。 我正在设置一个 Redis 集群,并遵循基本建议:3 硕士3个奴隶 有什么方法可以在 Amazon LB、HAProxy、Nginx 等负载均衡器后面配置此集群
那么集群背后的想法是什么? 您有多台机器具有相同的数据库副本,您在其中传播读/写?这是正确的吗? 这个想法如何运作?当我进行选择查询时,集群会分析哪个服务器的读/写较少并将我的查询指向该服务器? 当您
目录 一.系统环境 二.前言 三.Kubernetes 3.1 概述 3.2 Kube
我是一名优秀的程序员,十分优秀!