Short Description:

Hive configuration settings to optimize your HiveQL when querying ORC formatted tables.

Article

SYNOPSIS

The Optimized Row Columnar (ORC) file is a columnar storage format for Hive. Specific Hive configuration settings for ORC formatted tables can improve query performance resulting in faster execution and reduced usage of computing resources. Some of these settings may already be turned on by default, whereas others require some educated guesswork.

The table below compares Tez job statistics for the same Hive query that was submitted without and with certain configuration settings. Notice the performance gains with optimization. This article will explain how the performance improvements were achieved.

QUERY EXECUTION

Source Data:

  • 102,602,110 Clickstream page view records across 5 days of data for multiple countries
  • Table is partitioned by date in the format YYYY-MM-DD.
  • There are no indexes and table is not bucketed.

The HiveQL is ranking each page per user by how many times the user viewed that page for a specific date and within the United States. Breakdown of the query:

  1. Scan all the page views for each user.
  2. Filter for page views on 1 date partition and only include traffic in the United States.
  3. For each user, rank each page in terms of how many times it was viewed by that user.
  4. For example, I view Page A 3 times and Page B once. Page A would rank 1 and Page B would rank 2.

Without optimization

With optimization

Notice the change in reducers

  • The final output size of all the reducers is 920 MB.
  • For the first run, 73 reducers completed resulting in 73 output files. This is excessive. 920 MB into 73 reducers is around 12.5 MB per reducer output. This is unnecessary overhead resulting in too many small files. More parallelism does not always equate to better performance.
  • The second run launched 10 reducers resulting in 10 reduce files. 920 MB into 10 reducers is about 92 MB per reducer output. Much less overhead and we don’t run into the small files problem. The maximum number of files in HDFS depends on the amount of memory available in the NameNode. Each block, file, and directory in HDFS is represented as an object in the NameNode’s memory each of which occupies about 150 Bytes.

OPTIMIZATION

  1. Always collect statistics on those tables for which data changes frequently. Schedule an automated ETL job to run at certain times:

    ANALYZE TABLE page_views_orc COMPUTE STATISTICS FOR COLUMNS;

  2. Run the Hive query with the following settings:

    SET hive.optimize.ppd=true;

    SET hive.optimize.ppd.storage=true;

    SET hive.vectorized.execution.enabled=true;

    SET hive.vectorized.execution.reduce.enabled = true;

    SET hive.cbo.enable=true;

    SET hive.compute.query.using.stats=true;

    SET hive.stats.fetch.column.stats=true;

    SET hive.stats.fetch.partition.stats=true;

    SET hive.tez.auto.reducer.parallelism=true;

    SET hive.tez.max.partition.factor=20;

    SET hive.exec.reducers.bytes.per.reducer=128000000;

  3. Partition your tables by date if you are storing a high volume of data per day. Table management becomes easier. You can easily drop partitions that are no longer needed or for which data has to be reprocessed.

SUMMARY

Let’s look at each of the Hive settings.

  1. Enable predicate pushdown (PPD) to filter at the storage layer:

    SET hive.optimize.ppd=true;

    SET hive.optimize.ppd.storage=true

  2. Vectorized query execution processes data in batches of 1024 rows instead of one by one:

    SET hive.vectorized.execution.enabled=true;

    SET hive.vectorized.execution.reduce.enabled=true;

  3. Enable the Cost Based Optimizer (COB) for efficient query execution based on cost and fetch table statistics:

    SET hive.cbo.enable=true;

    SET hive.compute.query.using.stats=true;

    SET hive.stats.fetch.column.stats=true;

    SET hive.stats.fetch.partition.stats=true;

    Partition and column statistics from fetched from the metastsore. Use this with caution. If you have too many partitions and/or columns, this could degrade performance.

  4. Control reducer output:

    SET hive.tez.auto.reducer.parallelism=true;

    SET hive.tez.max.partition.factor=20;

    SET hive.exec.reducers.bytes.per.reducer=128000000;

This last set is important. The first run produced 73 output files with each file being around 12.5 MB in size. This is inefficient as I explained earlier. With the above settings, we are basically telling Hive an approximate maximum number of reducers to run with the caveat that the size for each reduce output should be restricted to 128 MB. Let's examine this:

  • The parameter hive.tez.max.partition.factor is telling Hive to launch up to 20 reducers. This is just a guess on my part and Hive will not necessarily enforce this. My job completed with only 10 reducers - 10 output files.
  • Since I set a value of 128 MB for hive.exec.reducers.bytes.per.reducer, Hive will try to fit the reducer output into files that are come close to 128 MB each and not just run 20 reducers.
  • If I did not set hive.exec.reducers.bytes.per.reducer, then Hive would have launched 20 reducers, because my query output would have allowed for this. I tested this and 20 reducers ran.
  • 128 MB is an approximation for each reducer output when setting hive.exec.reducers.bytes.per.reducer. In this example the total size of the output files is 920 MB. Hive launched 10 reducers which is about 92 MB per reducer file. When I set this to 64 MB, then Hive launched the 20 reducers with each file being around 46 MB.
  • If hive.exec.reducers.bytes.per.reducer is set to a very high value then you will have fewer reducers than if set to a lower value. Higher values result in fewer reducers being launched which can also degrade performance. You need just the right level of parallelism.

Optimizing Hive queries for ORC formatted tables的更多相关文章

  1. 5 Ways to Make Your Hive Queries Run Faster

    5 Ways to Make Your Hive Queries Run Faster Technique #1: Use Tez  Hive can use the Apache Tez execu ...

  2. hive orc压缩数据异常java.lang.ClassCastException: org.apache.hadoop.io.Text cannot be cast to org.apache.hadoop.hive.ql.io.orc.OrcSerde$OrcSerdeRow

    hive表在创建时候指定存储格式 STORED AS ORC tblproperties ('orc.compress'='SNAPPY'); 当insert数据到表时抛出异常 Caused by: ...

  3. Hive Bug修复:ORC表中array数据类型长度超过1024报异常

    目前HVIE里查询如下语句报错: select * from dw.ticket_user_mtime limit 10; 错误如下: 17/07/06 16:45:38 [main]: DEBUG ...

  4. Oracle:ORA-01219:database not open:queries allowed on fixed tables/views only

    Oracle:ORA-01219:database not open:queries allowed on fixed tables/views only 问: 解决 ORA-01219:databa ...

  5. 关于tez-ui的"All DAGs"和"Hive Queries"页面信息为空的问题解决过程

    近段时间发现公司的HDP大数据平台的tez-ui页面不能用了,页面显示为空,导致通过hive提交的sql不能方便地查找到Yarn上对应的applicationId,只能通过beeline的屏幕输出信息 ...

  6. Hive存储格式之ORC File详解,什么是ORC File

    目录 概述 文件存储结构 Stripe Index Data Row Data Stripe Footer 两个补充名词 Row Group Stream File Footer 条纹信息 列统计 元 ...

  7. Hive Streaming 追加 ORC 文件

    1.概述 在存储业务数据的时候,随着业务的增长,Hive 表存储在 HDFS 的上的数据会随时间的增加而增加,而以 Text 文本格式存储在 HDFS 上,所消耗的容量资源巨大.那么,我们需要有一种方 ...

  8. Sqoop将MySQL表结构同步到hive(text、orc)

    Sqoop将MySQL表结构同步到hive sqoop create-hive-table --connect jdbc:mysql://localhost:3306/sqooptest --user ...

  9. Hive Hadoop 解析 orc 文件

    解析 orc 格式 为 json 格式: ./hive --orcfiledump -d <hdfs-location-of-orc-file> 把解析的 json 写入 到文件 ./hi ...

随机推荐

  1. T-SQL基础(六)之可编程对象

    变量 -- 声明变量 DECLARE @variable_name [AS] variable_type; -- 变量赋值 SET @variable_name = variable_value; 示 ...

  2. docker相关操作文章整理

    docker整理: 菜鸟教程的nginx操作链接(docker安装完毕安装nginx启动错误,可以看下面的文章) CSDN基于 Docker 安装 Nginx docker 部署springboot

  3. 为链表数据结构实现iterator接口

    iterator作用 为所有的数据结构提供统一的访问方式. 接口对象 接口对象一共有3个方法,next()方法.return()方法.throw()方法. next() 必填 用于for..of迭代. ...

  4. call,apply,bind的用法与区别

    1.call/apply/bind方法的来源 首先,在使用call,apply,bind方法时,我们有必要知道这三个方法究竟是来自哪里?为什么可以使用的到这三个方法? call,apply,bind这 ...

  5. angular $index获取ng-repeat的上一条数据

    <div ng-repeat="item in dataList" ng-click="func($index,$index-1)"></di ...

  6. CF607B Zuma(区间dp)

    题意 题目链接 Sol 裸的区间dp,转移的时候判一下两个字符是否相等即可 #include<bits/stdc++.h> #define Pair pair<int, int> ...

  7. 关于处理注册表权限无法修改的问题(无法打开主键或注册表项unknown)

    CMD下(管理员) secedit /configure /cfg %windir%\inf\defltbase.inf /db defltbase.sdb /verbose 此命令可以生成报告, 任 ...

  8. Javascript 对象 - 数学对象

    数学对象 JavaScript中提供了math对象,math对象包含一些常用的属相和方法.Math对象与Array对象.String对象.Data对象不同,没有构造函数,因此不能创建Math对象.可直 ...

  9. Tomcat_记一次tomcatwar包应用简单部署过程

    记一次tomcat war包应用简单部署过程 by:授客 QQ:1033553122 1.  实践环境 Linux apache-tomcat-7.0.73 2.  实践步骤 # 解压tomcat压缩 ...

  10. Kotlin入门(27)文件读写操作

    Java的文件处理用到了io库java.io,该库虽然功能强大,但是与文件内容的交互还得通过输入输出流中转,致使文件读写操作颇为繁琐.因此,开发者通常得自己重新封装一个文件存取的工具类,以便在日常开发 ...