有什么让hive在hadoop上运行更快的技巧吗?

wfsdck30  于 2021-06-01  发布在  Hadoop
关注(0)|答案(6)|浏览(337)

我对hive和hadoop还不熟悉。我已经为hadoop配置了伪分布式操作,其中一个数据节点和一个名称节点都在localhost上。
我有一个普通的employee表,其中包含4条记录。我可以在一个合理的时间内选择记录,但任何超过这需要很长时间。例如:

  1. 0: jdbc:hive2://localhost:10000> select * from emp;
  2. +------------+------------+-------------+-------------+------------+
  3. | emp.empno | emp.ename | emp.job | emp.deptno | emp.etype |
  4. +------------+------------+-------------+-------------+------------+
  5. | 7369 | SMITH | CLERK | 10 | PART_TIME |
  6. | 7400 | JONES | ENGINEER | 10 | FULL_TIME |
  7. | 7500 | BROWN | NIGHTGUARD | 20 | FULL_TIME |
  8. | 7510 | LEE | ENGINEER | 20 | FULL_TIME |
  9. +------------+------------+-------------+-------------+------------+
  10. 4 rows selected (0.643 seconds)
  11. 0: jdbc:hive2://localhost:10000> select * from emp order by empno;
  12. WARNING: Hive-on-MR is deprecated in Hive 2 and may not be available in the future versions. Consider using a different execution engine (i.e. spark, tez) or using Hive 1.X releases.
  13. +------------+------------+-------------+-------------+------------+
  14. | emp.empno | emp.ename | emp.job | emp.deptno | emp.etype |
  15. +------------+------------+-------------+-------------+------------+
  16. | 7369 | SMITH | CLERK | 10 | PART_TIME |
  17. | 7400 | JONES | ENGINEER | 10 | FULL_TIME |
  18. | 7500 | BROWN | NIGHTGUARD | 20 | FULL_TIME |
  19. | 7510 | LEE | ENGINEER | 20 | FULL_TIME |
  20. +------------+------------+-------------+-------------+------------+
  21. 4 rows selected (225.852 seconds)

花了这么长时间做什么?我可以缩短投票时间吗?我知道Hive不是为小任务而优化的,但这似乎很荒谬。
下面是各种文件:hive-site.xml

  1. <?xml version="1.0" encoding="UTF-8" standalone="no"?>
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  3. <configuration>
  4. <property>
  5. <name>hive.mapred.mode</name>
  6. <value>nostrict</value>
  7. </property>
  8. <property>
  9. <name>javax.jdo.option.ConnectionURL</name>
  10. <value>jdbc:derby:;databaseName=metastore_db;create=true</value>
  11. </property>
  12. <property>
  13. <name>javax.jdo.option.ConnectionDriverName</name>
  14. <value>org.apache.derby.jdbc.EmbeddedDriver</value>
  15. </property>
  16. <property>
  17. <name>hive.exec.local.scratchdir</name>
  18. <value>/home/hadoop/tmp</value>
  19. </property>
  20. <property>
  21. <name>hive.downloaded.resources.dir</name>
  22. <value>/home/hadoop/tmp/${hive.session.id}_resources</value>
  23. </property>
  24. <property>
  25. <name>hive.querylog.location</name>
  26. <value>/home/hadoop/tmp</value>
  27. </property>
  28. <property>
  29. <name>hive.server2.logging.operation.log.location</name>
  30. <value>/home/hadoop/tmp/operation_logs</value>
  31. </property>
  32. </configuration>

hdfs.xml文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  3. <configuration>
  4. <property>
  5. <name>dfs.replication</name>
  6. <value>1</value>
  7. </property>
  8. <property>
  9. <name>dfs.name.dir</name>
  10. <value>file:///home/hadoop/hadoopinfra/hdfs/namenode</value>
  11. </property>
  12. <property>
  13. <name>dfs.data.dir</name>
  14. <value>file:///home/hadoop/hadoopinfra/hdfs/datanode</value>
  15. </property>
  16. </configuration>

core-site.xml文件

  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  3. <configuration>
  4. <property>
  5. <name>fs.default.name</name>
  6. <value>hdfs://localhost:9000</value>
  7. </property>
  8. <property>
  9. <name>hadoop.proxyuser.hive.groups</name>
  10. <value>*</value>
  11. </property>
  12. <property>
  13. <name>hadoop.proxyuser.hive.hosts</name>
  14. <value>*</value>
  15. </property>
  16. <property>
  17. <name>hadoop.proxyuser.hadoop.hosts</name>
  18. <value>*</value>
  19. </property>
  20. <property>
  21. <name>hadoop.proxyuser.hadoop.groups</name>
  22. <value>*</value>
  23. </property>
  24. </configuration>

mapred-site.xml文件

  1. <?xml version="1.0"?>
  2. <?xml-stylesheet type="text/xsl" href="configuration.xsl"?>
  3. <configuration>
  4. <property>
  5. <name>mapreduce.framework.name</name>
  6. <value>yarn</value>
  7. </property>
  8. </configuration>

yarn-site.xml文件

  1. <?xml version="1.0"?>
  2. <configuration>
  3. <property>
  4. <name>yarn.nodemanager.aux-services</name>
  5. <value>mapreduce_shuffle</value>
  6. </property>
  7. </configuration>
cuxqih21

cuxqih211#

使用直线壳,不推荐使用Hive。

wf82jlnq

wf82jlnq2#

你的Hive正在使用 Map Reduce 用于处理hive2中不推荐使用的数据,并且响应速度慢,因此必须设置 Tez 或者 Spark 作为你的Hive执行引擎,给你更快的结果。
根据我的经验,我建议你用 Tez 作为最佳性能的执行引擎。用于设置 Hive-Tez 请把这份文件流转一下。https://docs.hortonworks.com/hdpdocuments/hdp2/hdp-2.6.2/bk_command-line-installation/content/ref-d677ca50-0a14-4d9e-9882-b764e689f6db.1.html

ou6hu8tu

ou6hu8tu3#

在查询中使用“order by”,order by强制所有结果的总顺序,因此必须有一个reducer来对最终输出进行排序。
尽管在这种情况下记录的数量较少,但由于两个阶段(map和reduce)和磁盘i/o,查询的处理需要时间。如果输出中的行数太大,则单个减速机可能需要很长时间才能完成。
建议您在tez或spark引擎上运行hive,除非确实需要,否则不要运行需要完整扫描表的查询。

g2ieeal7

g2ieeal74#

  1. Set hive.fetch.task.conversion=none;

设置此属性并再次运行

dgtucam1

dgtucam15#

在配置单元查询的开头使用以下命令:

  1. -- use cost-based query optimization
  2. set hive.cbo.enable=true;
  3. set hive.compute.query.using.stats=true;
  4. set hive.stats.fetch.column.stats=true;
  5. set hive.stats.fetch.partition.stats=true;
  6. -- use dynamic hive partition
  7. set hive.exec.dynamic.partition = true;
  8. set hive.exec.dynamic.partition.mode = nonstrict;

请添加评论,如果你喜欢我的答案!

hujrc8aj

hujrc8aj6#

您可以做两件事来更快地运行查询:1。使用distribute by和sort by的组合。distribute by将确保具有某个值的所有键最终都位于同一个数据节点上。sort by随后将对每个节点上的数据进行排序。2在执行查询之前,将执行引擎设置为tez。
设置hive.execution.engine=tez;
我想这一定会让你的查询运行得更快。

相关问题