#title Hive Tuning [[TableOfContents]] ==== SQL Server에서 ODBC연결하여 Hive에서 데이터 가져올때 ==== sql1방식보다 sql2 방식으로 가져오는게 4~10배 빠르다. (경험적으로..) sql1 {{{ drop table if exists #temp1 select * into #temp1 from openquery(hive, ' select col1, col2, col3 from gamelog where 1=1 and a.date_key between 20190619 and 20190821 ' ) }}} sql2 {{{ exec('drop table if exists etl_fcc1d2fd1da44550bbde0661f25b631a;') at hive exec(' create table etl_fcc1d2fd1da44550bbde0661f25b631a as select col1, col2, col3 from gamelog where 1=1 and a.date_key between 20190619 and 20190821 ') at hive go drop table if exists #1 select * into #1 from openquery(hive, ' select col1, col2, col3 from etl_fcc1d2fd1da44550bbde0661f25b631a') --4:30 }}} ==== 파티션 컬럼 읽을 때 ==== '''현상:''' gamelog 테이블은 date_key, log_no로 파티션된 테이블이다. 아래와 같이 파티션 키만 읽는 쿼리를 날렸다. 그런데 1시간이 걸리는 것이다. {{{ hive> set hive.execution.engine=mr; hive> select log_no > from gamelog > where 1=1 > and date_key=20181228 > group by log_no; }}} '''해결:''' 영문을 모르겠으나 메시지를 잘 살펴보니 알겠더라. 이유는 hive가 input data size를 졸라 작제 추정한 것에 있다. attachment:HiveTuning/hive.png 그냥 쓸때없이 파티션 키가 아닌 다른 데이터도 조회하도록 해준다. {{{ hive> select log_no, count(get_json_object(log_string, '$.1') cnt > from gamelog > where 1=1 > and date_key=20181228 > group by log_no; }}} ==== 자원 쓰기 ==== 투기적 실행 {{{ set hive.mapred.reduce.tasks.speculative.execution =true; }}} map수 늘리기(숫자를 작게 할 수록 map숫자가 늘어남) {{{ set mapreduce.input.fileinputformat.split.maxsize=1048576; }}}