(1)创建表的时候
设置表的数据压缩
//设置数据压缩
family.setCompressionType(Compression.Algorithm.SNAPPY)
创建预分区
admin.createTable(desc,Array(
Bytes.toBytes("145057118"),Bytes.toBytes("145057138"),
Bytes.toBytes("145057158"),Bytes.toBytes("145057188")
))
设置读取表中的数据不缓存
cache block
2)spark程序的优化
.filter(tuple =>eventTypeList.contains(EventEnum.valueOfAlias(tuple._1)))
eventTypeList是Driver里面,filter是在Executor里面task运行
如果RDD有中3个分区,分别在不同的executor中,那么eventTypeList需要存储3份
在实际的开发中,一天处理的数据量几十个GB,分区有可能很多,一个数据库对应一个分区,一个分区对应一个Task,如果有1000个分区,
如果eventTypeList1M的话,将消耗1GB
可以考虑一个executor存储一份,如果有10个executor存储10M就好了
Spark supports two types of shared variables
spark提供2种方式变量共享
broadcast variables:广播变量
which can be used to cache a value in memory on all nodes,
使用广播变量将集合类别 广播出去:将数据发送到每一个executor里面
//将集合List变量广播出去
val eventTypeBroadcast = sc.broadcast(eventTypeList)
val eventPutRDD = parseEventLogRDD
//针对时间类型进行过滤eventType
.filter(tuple =>eventTypeBroadcast.value.contains(EventEnum.valueOfAlias(tuple._1)))
.map{
case (eventAlias,logInfo)=>{
//。。。
)
accumulators:累加器
which are variables that are only “added” to, such as counters and sums.
(3)使用HFileOuputFile
向HBASE表中存储数据的时候,
put方式
putData ->WAL->MemStore ->StoreFile(HFile)
Hfile方式
Date –>Hfile ->load table
刷新缓存:flush 'ns1:t1'
强制让memStore的数据到StoreFile(Hfile )中