我已将一个表从oracle数据库导入到hbase。我试图通过phoenix控制台访问它,此操作已成功完成。但是当我尝试执行一些查询(也包含子查询和分组依据)时,它从phoenix控制台执行的速度要快得多(对于35k记录几乎不需要花费12-13秒的时间),但是从spark sql不能执行(花费8-10 mins)。这是我如何通过sql上下文获取数据的示例:
String tableNames[]=new String[]{"table1","table2"};
Dataset<Row> df = null;
SQLContext sqlContext = new SQLContext(this.getSparkContext());
for (int i = 0; i < tableNames.length; i++) {
df = sqlContext.read().format("jdbc").options(ImmutableMap.of("driver", "org.apache.phoenix.jdbc.PhoenixDriver", "url","jdbc:phoenix:"+zookeeperUrl, "dbtable", tableNames[i])).load();
df.createOrReplaceTempView(tableNames[i]);
}
Dataset<Row> res = sqlContext.sql(query);
res.show();//here it is taking a lot of time to execute
使用的配置:
Cluster with 3 nodes:1 master and 2 slaves
Master node:20gb
Slave nodes:12gb
Driver memory:4gb
尽管我的代码在相同的配置上运行,为什么我的代码要花几分钟的时间执行?
我还尝试使用spark.sql.shuffle.partitions在数据集上运行.show()时最小化它正在创建的分区数,以使其执行较少的混洗次数,但未发现性能改进。