Spark SQL与Hive On MapReduce速度比较

我们都知道SparkHadoop的MR计算速度更快。到底快多少呢?我一直比较疑惑,会有官网说的那么夸张吗。

今天就拿基于Spark的Spark SQL和基于MR的Hive比较一下,因为Spark SQL也兼容了HiveQL,我们就可以通过运行相同的HiveQL语句,比较直观的看出到底快多少了。


Spark SQL只要在编译的时候引入hive支持,就可以支持Hive表访问,UDF,SerDe,以及HiveQL/HQL--引自《Spark快速大数据分析》

Hive一般在工作站上运行,它把SQL查询转化为一系列在hadoop集群上运行的MR作业--引自《Hadoop权威指南》



用的文件系统都是HDFS,比较的是第二条sql语句

1.运行spark-sql shell

[plain]  view plain  copy
  1. guo@drguo:/opt/spark-1.6.1-bin-hadoop2.6/bin$ spark-sql   
[plain]  view plain  copy
  1. spark-sql> create external table cn(x bigint, y bigint, z bigint, k bigint)   
  2.          > row format delimited fields terminated by ','   
  3.          > location '/cn';  
  4. OK  
  5. Time taken: 0.876 seconds  
  6. spark-sql> create table p as select y, z, sum(k) as t  
  7.          > from cn where x>=20141228 and x<=20150110 group by y, z;  
  8. Time taken: 20.658 seconds   
查看jobs,用了15s,为什么上面显示花了接近21s?我也不清楚,先放下不管。


再看一下它的DAG图

2.运行Hive


[plain]  view plain  copy
  1. guo@drguo:~$ hive  
[plain]  view plain  copy
  1. hive> create external table cn(x bigint, y bigint, z bigint, k bigint)   
  2.     > row format delimited fields terminated by ','   
  3.     > location '/cn';  
  4. OK  
  5. Time taken: 0.752 seconds  
  6. hive> create table p as select y, z, sum(k) as t  
  7.     > from cn where x>=20141228 and x<=20150110 group by y, z;  
  8. Query ID = guo_20160515161032_2e035fc2-6214-402a-90dd-7acda7d638bf  
  9. Total jobs = 1  
  10. Launching Job 1 out of 1  
  11. Number of reduce tasks not specified. Estimated from input data size: 1  
  12. In order to change the average load for a reducer (in bytes):  
  13.   set hive.exec.reducers.bytes.per.reducer=<number>  
  14. In order to limit the maximum number of reducers:  
  15.   set hive.exec.reducers.max=<number>  
  16. In order to set a constant number of reducers:  
  17.   set mapreduce.job.reduces=<number>  
  18. Starting Job = job_1463299536204_0001, Tracking URL = http://drguo:8088/proxy/application_1463299536204_0001/  
  19. Kill Command = /opt/Hadoop/hadoop-2.7.2/bin/hadoop job  -kill job_1463299536204_0001  
  20. Hadoop job information for Stage-1: number of mappers: 1; number of reducers: 1  
  21. 2016-05-15 16:10:52,353 Stage-1 map = 0%,  reduce = 0%  
  22. 2016-05-15 16:11:03,418 Stage-1 map = 100%,  reduce = 0%, Cumulative CPU 8.65 sec  
  23. 2016-05-15 16:11:13,257 Stage-1 map = 100%,  reduce = 100%, Cumulative CPU 13.99 sec  
  24. MapReduce Total cumulative CPU time: 13 seconds 990 msec  
  25. Ended Job = job_1463299536204_0001  
  26. Moving data to: hdfs://drguo:9000/user/hive/warehouse/predict  
  27. Table default.predict stats: [numFiles=1, numRows=1486, totalSize=15256, rawDataSize=13770]  
  28. MapReduce Jobs Launched:   
  29. Stage-Stage-1: Map: 1  Reduce: 1   Cumulative CPU: 13.99 sec   HDFS Read: 16551670 HDFS Write: 15332 SUCCESS  
  30. Total MapReduce CPU Time Spent: 13 seconds 990 msec  
  31. OK  
  32. Time taken: 42.887 seconds  
花了接近43s。再去RM看一下,花了36s

结果非常明显

如果按shell里显示花的时间算,21:43

按网页里显示花的时间算,15:36

差不多一倍,据说即将发布的Spark2.0速度更快。

那么问题来了,Spark什么时候会完全取代MR?

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值