SlideShare une entreprise Scribd logo
1  sur  28
Télécharger pour lire hors ligne
하이브 최적화 방안
최종욱 tchoi@hortonworks.com
발표에 앞서…

•

스팅어 소개를 간단히
스팅어는

“차세대 하이브 개발자들”
모든 하둡은

스팅어의 하이브를 기본 탑재

3

단계

2

단계

1

단계
모든 하둡 분석 도구들은

하이브를 기본 지원
파워 BI, 엑셀로 하이브 질의 자동 생성
SQL 질의를 하이브로 자동 변환
기존 다이어그램을 하이브로 자동 변환
탐색기, 대시보드 등에서 활용
하이브 버전별 최적화 요소
버전

분류

세부

관련 용어

~0.10

처리 성능

디렉토리 구조

파티션, 버킷

0.11

처리 성능

+ 대용량 조인

SMB 조인

0.12

저장 용량

+ 자료 압축

ORC, ZLIB

0.13

처리 성능

+ 실시간 질의

테즈, 벡터화
0.11: 다양한 조인 구현
•

고객 정보와 주문 정보를 합쳐서 각 고객이 어떤 주문을 했
는지 모아서 보고 싶을 때. 각 주문이 고객 번호를 가리키는
방식. Quick Refresher on Joins
customer&
first&

last&

order&
id&

cid&

price&

quan6ty&

Nick'

Toner'

11911'

4150'

10.50'

3'

Jessie'

Simonds'

11912'

11914'

12.25'

27'

Kasi'

Lamers'

11913'

3491'

5.99'

5'

Rodger'

Clayton'

11914'

2934'

39.99'

22'

Verona'

Hollen'

11915'

11914'

40.50'

10'

SELECT&*&FROM&customer&join&order&ON#customer.id#=#order.cid;&

Joins'match'values'from'one'table'against'values'in'another'table.'
하이브의 조인 전략들
방식

셔플 조인

맵/리듀스를 이용해서 키를
기준으로 재분배(셔플)하여
조인 측에서 조인을 수행.

장점
어떤 형태의 데이터 크기와
구성에서도 작동함.

작은 테이블이 모든 노드의 가장 큰 테이블에서 굉장히
메모리에 올라가고, 매퍼는 빠른 단일 스캔.
브로드캐스트 큰 테이블을 훑어보며 조인을
조인
함.
매퍼는 각 키가 인접한 특성
정렬-병합-버 을 이용해 효과적인 조인을
킷(SMB) 조 수행.
인

단점
가장 자원을 많이 사용하며
가장 느린 조인 방식.

작은 테이블이 메모리에 들어
갈 정도로 작아야 함.

어떤 크기의 테이블에서도 굉 사전에 자료가 정렬되고 버켓
장히 빠름.
화 되어있어야 함.
셔플 조인
Shuffle Joins in Map Reduce
customer&
first&

last&

order&
id&

cid&

price&

quan6ty&

Nick'

Toner'

11911'

4150'

10.50'

3'

Jessie'

Simonds'

11912'

11914'

12.25'

27'

Kasi'

Lamers'

11913'

3491'

5.99'

5'

Rodger'

Clayton'

11914'

2934'

39.99'

22'

Verona'

Hollen'

11915'

11914'

40.50'

10'

SELECT&*&FROM&customer&join&order&ON#customer.id#=#order.cid;&
{'id:'11911,'{'first:'Nick,'last:'Toner'}}'
{'id:'11914,'{'first:'Rodger,'last:'Clayton'}}'
…'
{'cid:'4150,'{'price:'10.50,'quan1ty:'3'}}'
{'cid:'11914,'{'price:'12.25,'quan1ty:'27'}}'
…'

M
M

R

{'id:'11911,'{'first:'Nick,'last:'Toner'}}'
{'cid:'4150,'{'price:'10.50,'quan1ty:'3'}}'
…'

R

{'id:'11914,'{'first:'Rodger,'last:'Clayton'}}'
{'cid:'11914,'{'price:'12.25,'quan1ty:'27'}}'

Iden1cal'keys'shuffled'to'the'same'reducer.'Join'done'reduceEside.'
Expensive'from'a'network'u1liza1on'standpoint.'
Deep Dive content by Hortonworks, Inc. is licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License.

Page 15
Broadcast Join
브로드캐스트

조인

•  Star schemas use dimension 작은 디멘전 테이블들을 사용 to fit in RAM.
• 스타 스키마는 메모리에 올라올 정도로 tables small enough
•  Small tables 작은 테이블들이 메모리에 올라감
• 모든 노드에서 held in memory by all nodes.
• 큰 테이블을 through the large table.
•  Single pass통한 단일 스캔
• 일반적인 DW에서 스타-스키마 방식의 조인에서 널리 쓰임
•  Used for star-schema type joins common in DW.
양 테이블이 메모리에

When both are too large for memory:
비해 너무 클 때:
customer&
first&

last&

order&
id&

cid&

price&

quan6ty&

Nick'

Toner'

11911'

4150'

10.50'

3'

Jessie'

Simonds'

11912'

11914'

12.25'

27'

Kasi'

Lamers'

11913'

11914'

40.50'

10'

Rodger'

Clayton'

11914'

12337'

39.99'

22'

Verona'

Hollen'

11915'

15912'

40.50'

10'

SELECT&*&FROM&customer&join&order&ON#customer.id#=#order.cid;&
Cluster&and&sort&by&the&most&common&join&key.&
CREATE&TABLE&order&(cid&int,&price&float,&quantity&int)&
CLUSTERED#BY(cid)#SORTED#BY(cid)#INTO#32#BUCKETS;#
CREATE&TABLE&customer&(id&int,&first&string,&last&string)&
CLUSTERED#BY(id)#SORTED#BY(id)#INTO#32#BUCKETS;#

Deep Dive content by Hortonworks, Inc. is licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License.

Page 17
하이브의 클러스터링과 정렬
Hive’s Clustering and Sorting
customer&
first&

last&

order&
id&

cid&

price&

quan6ty&

Nick'

Toner'

11911'

4150'

10.50'

3'

Jessie'

Simonds'

11912'

11914'

12.25'

27'

Kasi'

Lamers'

11913'

11914'

40.50'

10'

Rodger'

Clayton'

11914'

12337'

39.99'

22'

Verona'

Hollen'

11915'

15912'

40.50'

10'

SELECT&*&FROM&customer&join&order&ON#customer.id#=#order.cid;&

Observa1on'1:'
Sor1ng'by'the'join'key'makes'joins'easy.'
All'possible'matches'reside'in'the'same'area'on'disk.'

Deep Dive content by Hortonworks, Inc. is licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License.

Page 18
하이브의 클러스터링과 정렬
Hive’s Clustering and Sorting
customer&
first&

last&

order&
id&

cid&

price&

quan6ty&

Nick'

Toner'

11911'

4150'

10.50'

3'

Jessie'

Simonds'

11912'

11914'

12.25'

27'

Kasi'

Lamers'

11913'

11914'

40.50'

10'

Rodger'

Clayton'

11914'

12337'

39.99'

22'

Verona'

Hollen'

11915'

15912'

40.50'

10'

SELECT&*&FROM&customer&join&order&ON#customer.id#=#order.cid;&

Observa1on'2:'
Hash'bucke1ng'a'join'key'ensures'all'matching'values'reside'on'the'same'node.'
EquiEjoins'can'then'run'with'no'shuffle.'

Deep Dive content by Hortonworks, Inc. is licensed under a
Creative Commons Attribution-ShareAlike 3.0 Unported License.

Page 19
데이터 지역성 통제
•

버켓팅 (Bucketing):
•
•

•

파티션 값을 해시하여 미리 설정된 버켓에 저장
일반적으로 정렬과 함께 사용

스큐 (Skew):
•
•

•

값을 분리된 파일들로 저장
특정한 값이 자주 등장할 때 사용

복제 계수 (Replication Factor):
•
•

•

복제 계수를 증가시켜 읽기 성능을 향상
HDFS 수준에서 설정

정렬 (Sorting):
•

주어진 컬럼을 기준으로 값을 정렬

•

ORC 파일 필터 다운과 사용했을 때 질의를 굉장히 가속
하이브 자료 설계 지침
테이블 크기
작음
모두
큼
큼
큼

데이터 특성

질의 패턴

추천 전략

자주 쓰임

모두

복제 계수를 증가

모두

특정한 필터

특정한 질의에서 가장 많이 쓰
이는 컬럼을 기준으로 정렬

모두

다른 큰 테이블에 조인됨

테이블을 조인 키에 따라 정렬
하고 버켓화

한 값이 25% 이 모두
상으로 자주 쓰임
모두

잦은 값을 별도의 스큐로 분리

질의가 날짜처럼 자연적으로 자료를 자연적인 경계에 맞추
경계들을 갖는 경향이 있음 어 파티션
자동 조인 구현체 선택
작업 예: 스테이징 테이블 생성
Example Workflow: Create a Stag
CREATE EXTERNAL TABLE pos_staging (!
!txnid STRING,!
!txntime STRING,!
!givenname STRING,!
!lastname STRING,!
!postalcode STRING,!
!storeid STRING,!
!ind1 STRING,!
!productid STRING,!
!purchaseamount FLOAT,!
!creditcard STRING!
)ROW FORMAT DELIMITED FIELDS TERMINATED BY '|'!
LOCATION '/user/hdfs/staging_data/pos_staging';!
작업 예: 파티션Choose a partition schem
스키마를 선택
Example Workflow:
hive> select distinct concat(year(txntime),month(txntime)) as part_dt !
from pos_staging;!
…!
OK!
20121!
201210!
201211!
201212!
20122!
20123!
20124!
20125!
20126!
20127!
20128!
20129!
Time taken: 21.823 seconds, Fetched: 12 row(s)!

Execute a query to determine if the partition choice returns a reasonable result. We will
use this projection to create partitions for our data set. You want to keep your partitions
작업 예: 최적화된 Define optimized ta
테이블 정의
Example Workflow:
CREATE TABLE fact_pos!
(!
!txnid STRING,!
!txntime STRING,!
!givenname STRING,!
!lastname STRING,!
!postalcode STRING,!
!storeid STRING,!
!ind1 STRING,!
!productid STRING,!
!purchaseamount FLOAT,!
!creditcard STRING!
) PARTITIONED BY (part_dt STRING)!
CLUSTERED BY (txnid)!
SORTED BY (txnid)!
INTO 24 BUCKETS!
STORED AS ORC tblproperties ("orc.compress"="SNAPPY");!

The part_dt field is defined in the partition by clause and cannot be the same name as any
fields. In this case, we will be performing a modification of txntime to generate a partition k
작업 예: 데이터를 최적화된

Example Workflow: Load Data Into Optimized
테이블에 탑재
set hive.enforce.sorting=true;!
set hive.enforce.bucketing=true;!
set hive.exec.dynamic.partition=true;!
set hive.exec.dynamic.partition.mode=nonstrict; !
set mapreduce.reduce.input.limit=-1;!
!
FROM pos_staging!
INSERT OVERWRITE TABLE fact_pos!
PARTITION (part_dt)!
SELECT!
!txnid,!
!txntime,!
!givenname,!
!lastname,!
!postalcode,!
!storeid,!
!ind1,!
!productid,!
!purchaseamount,!
!creditcard,!
!concat(year(txntime),month(txntime)) as part_dt!
SORT BY productid;!

!

We use this commend to load data from our staging table into
작업 예: 복제 계수를 증가
Example Workflow: Increase replication factor

hadoop fs -setrep -R –w 5 /apps/hive/warehouse/fact_pos!

Increase the replication factor for the high performance table.
This increases the chance for data locality. In this case, the
increase in replication factor is not for additional resiliency.
This is a trade-off of storage for performance.
작업 예: 숏서킷 읽기를 활성화
Example Workflow: Enabling Short Circuit Read

In hdfs-site.xml (or your custom Ambari settings for HDFS,
restart service after):!
!
dfs.block.local-path-access.user=hdfs!
dfs.client.read.shortcircuit=true!
dfs.client.read.shortcircuit.skip.checksum=false!

Short Circuit reads allow the mappers
to bypass the overhead of opening a
port to the datanode if the data is
local. The permissions for the local
block files need to permit hdfs to read
them (should be by default already)
See HDFS-2246 for more details.

Deep Dive content by Hortonworks, Inc. is licensed under a

Page 47
작업 예: 질의 수행

Example Workflow: Execute your query
set hive.mapred.reduce.tasks.speculative.execution=false;!
set io.sort.mb=300;!
set mapreduce.reduce.input.limit=-1;!
!
select productid, ROUND(SUM(purchaseamount),2) as total !
from fact_pos !
where part_dt between ‘201210’ and ‘201212’!
group by productid !
order by total desc !
limit 100;!
!
…!
OK!
20535
!3026.87!
39079
!2959.69!
28970
!2869.87!
45594
!2821.15!
…!
15649
!2242.05!
47704
!2241.22!
8140 !2238.61!
Time taken: 40.087 seconds, Fetched: 100 row(s)!

In the case above, we have a simple query executed to test out our table. We
작업 예: 앰버리에서

Example Workflow: Check Execution Path in Ambari
실행 경로 체크

You can check the execution path in Ambari’s Job viewer. This gives a high level overview of
the stages and particular number of map and reduce tasks. With Tez, it also shows task
하이브 고속 질의 체크 목록
•

데이터를 자연스런 질의 경계에 의해 파티션함 (예: 날짜).

•

가장 자주 조인되는 데이터를 인접시켜 데이터 셔플을 최소화.

•

잦은 값은 스큐를 이용하여 분산

•

숏서킷 읽기 활성화.

•

ORC 파일 사용.

•

자주 타겟되는 질의에서 로우 스킵을 사용하기 위해 컬럼 재정렬.

•

쿼리 계획을 확인하여 가장 큰 테이블을 기준으로 단일 스캔하는지 확인.

•

쿼리 계획을 확인하여 파티션 건너뛰기가 일어나는지 확인.

•

매 조인마다 최소한 하나의 ON 절 사용.
0.12: 자료 압축
•

“CREATE TABLE” 명령문 끝에 “STORED AS ORC” 구
문만 추가하면 압축 적용.

•

평균 1/4으로 용량이 줄어들어 4배 더 많은 데이터를 보관
가능.
0.13: 실시간 질의
•

테즈 사용
•

테즈 프로세스 상주: 프로세스를
새로 만드느라 낭비되는 시간을
없앰. 워밍업과 재사용 등 다양한
기법 도입.

•

맵리듀스 재구성: 예전 맵리듀스
는 맵과 리듀스가 한 쌍으로 묶
여, 다음 맵으로 전하기 위해서는
디스크에 써야했다. 이 제약을 풀
어 불필요한 디스크 입출력을 없
앴다.
성능 측정
•

https://github.com/
cartershanklin/hivetestbench

•

TPC DS 기반의 성능 측정 도구를
오픈소스로 제공. 일반 텍스트와 압
축 및 최적화된 형태 두 가지를 생
성. 임팔라 등 다른 시스템과 비교에
도 사용 가능.

•

국내 대기업 고객사 시험 환경에서
적용하자, 호튼웍스 홈페이지에서
밝힌 결과와 초단위로 일치.

Contenu connexe

Tendances

Hadoop World 2011: Advanced HBase Schema Design - Lars George, Cloudera
Hadoop World 2011: Advanced HBase Schema Design - Lars George, ClouderaHadoop World 2011: Advanced HBase Schema Design - Lars George, Cloudera
Hadoop World 2011: Advanced HBase Schema Design - Lars George, ClouderaCloudera, Inc.
 
OHDSI CDM Presentation
OHDSI CDM PresentationOHDSI CDM Presentation
OHDSI CDM PresentationAmritansh .
 
Tips and Tricks for SAP Sybase IQ
Tips and Tricks for SAP  Sybase IQTips and Tricks for SAP  Sybase IQ
Tips and Tricks for SAP Sybase IQDon Brizendine
 
Jose portillo dev con presentation 1138
Jose portillo   dev con presentation 1138Jose portillo   dev con presentation 1138
Jose portillo dev con presentation 1138Jose Portillo
 
Local Secondary Indexes in Apache Phoenix
Local Secondary Indexes in Apache PhoenixLocal Secondary Indexes in Apache Phoenix
Local Secondary Indexes in Apache PhoenixRajeshbabu Chintaguntla
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsZohar Elkayam
 
HBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon 2015: HBase Performance Tuning @ SalesforceHBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon 2015: HBase Performance Tuning @ SalesforceHBaseCon
 
Getting the Scylla Shard-Aware Drivers Faster
Getting the Scylla Shard-Aware Drivers FasterGetting the Scylla Shard-Aware Drivers Faster
Getting the Scylla Shard-Aware Drivers FasterScyllaDB
 
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015PostgreSQL-Consulting
 
데브시스터즈 데이터 레이크 구축 이야기 : Data Lake architecture case study (박주홍 데이터 분석 및 인프라 팀...
데브시스터즈 데이터 레이크 구축 이야기 : Data Lake architecture case study (박주홍 데이터 분석 및 인프라 팀...데브시스터즈 데이터 레이크 구축 이야기 : Data Lake architecture case study (박주홍 데이터 분석 및 인프라 팀...
데브시스터즈 데이터 레이크 구축 이야기 : Data Lake architecture case study (박주홍 데이터 분석 및 인프라 팀...Amazon Web Services Korea
 
Apache Phoenix Query Server
Apache Phoenix Query ServerApache Phoenix Query Server
Apache Phoenix Query ServerJosh Elser
 
Apache Arrow Flight Overview
Apache Arrow Flight OverviewApache Arrow Flight Overview
Apache Arrow Flight OverviewJacques Nadeau
 
Top 5 Mistakes When Writing Spark Applications
Top 5 Mistakes When Writing Spark ApplicationsTop 5 Mistakes When Writing Spark Applications
Top 5 Mistakes When Writing Spark ApplicationsSpark Summit
 
Cassandra & puppet, scaling data at $15 per month
Cassandra & puppet, scaling data at $15 per monthCassandra & puppet, scaling data at $15 per month
Cassandra & puppet, scaling data at $15 per monthdaveconnors
 
Mongodb - Scaling write performance
Mongodb - Scaling write performanceMongodb - Scaling write performance
Mongodb - Scaling write performanceDaum DNA
 
Oracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionOracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionMarkus Michalewicz
 
Ozone and HDFS’s evolution
Ozone and HDFS’s evolutionOzone and HDFS’s evolution
Ozone and HDFS’s evolutionDataWorks Summit
 
Postgresql Database Administration Basic - Day1
Postgresql  Database Administration Basic  - Day1Postgresql  Database Administration Basic  - Day1
Postgresql Database Administration Basic - Day1PoguttuezhiniVP
 
Managing your Hadoop Clusters with Apache Ambari
Managing your Hadoop Clusters with Apache AmbariManaging your Hadoop Clusters with Apache Ambari
Managing your Hadoop Clusters with Apache AmbariDataWorks Summit
 

Tendances (20)

Hadoop World 2011: Advanced HBase Schema Design - Lars George, Cloudera
Hadoop World 2011: Advanced HBase Schema Design - Lars George, ClouderaHadoop World 2011: Advanced HBase Schema Design - Lars George, Cloudera
Hadoop World 2011: Advanced HBase Schema Design - Lars George, Cloudera
 
OHDSI CDM Presentation
OHDSI CDM PresentationOHDSI CDM Presentation
OHDSI CDM Presentation
 
Tips and Tricks for SAP Sybase IQ
Tips and Tricks for SAP  Sybase IQTips and Tricks for SAP  Sybase IQ
Tips and Tricks for SAP Sybase IQ
 
Jose portillo dev con presentation 1138
Jose portillo   dev con presentation 1138Jose portillo   dev con presentation 1138
Jose portillo dev con presentation 1138
 
Local Secondary Indexes in Apache Phoenix
Local Secondary Indexes in Apache PhoenixLocal Secondary Indexes in Apache Phoenix
Local Secondary Indexes in Apache Phoenix
 
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAsOracle Database Performance Tuning Advanced Features and Best Practices for DBAs
Oracle Database Performance Tuning Advanced Features and Best Practices for DBAs
 
HBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon 2015: HBase Performance Tuning @ SalesforceHBaseCon 2015: HBase Performance Tuning @ Salesforce
HBaseCon 2015: HBase Performance Tuning @ Salesforce
 
Getting the Scylla Shard-Aware Drivers Faster
Getting the Scylla Shard-Aware Drivers FasterGetting the Scylla Shard-Aware Drivers Faster
Getting the Scylla Shard-Aware Drivers Faster
 
Alfresco tuning part2
Alfresco tuning part2Alfresco tuning part2
Alfresco tuning part2
 
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
How does PostgreSQL work with disks: a DBA's checklist in detail. PGConf.US 2015
 
데브시스터즈 데이터 레이크 구축 이야기 : Data Lake architecture case study (박주홍 데이터 분석 및 인프라 팀...
데브시스터즈 데이터 레이크 구축 이야기 : Data Lake architecture case study (박주홍 데이터 분석 및 인프라 팀...데브시스터즈 데이터 레이크 구축 이야기 : Data Lake architecture case study (박주홍 데이터 분석 및 인프라 팀...
데브시스터즈 데이터 레이크 구축 이야기 : Data Lake architecture case study (박주홍 데이터 분석 및 인프라 팀...
 
Apache Phoenix Query Server
Apache Phoenix Query ServerApache Phoenix Query Server
Apache Phoenix Query Server
 
Apache Arrow Flight Overview
Apache Arrow Flight OverviewApache Arrow Flight Overview
Apache Arrow Flight Overview
 
Top 5 Mistakes When Writing Spark Applications
Top 5 Mistakes When Writing Spark ApplicationsTop 5 Mistakes When Writing Spark Applications
Top 5 Mistakes When Writing Spark Applications
 
Cassandra & puppet, scaling data at $15 per month
Cassandra & puppet, scaling data at $15 per monthCassandra & puppet, scaling data at $15 per month
Cassandra & puppet, scaling data at $15 per month
 
Mongodb - Scaling write performance
Mongodb - Scaling write performanceMongodb - Scaling write performance
Mongodb - Scaling write performance
 
Oracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion EditionOracle RAC Internals - The Cache Fusion Edition
Oracle RAC Internals - The Cache Fusion Edition
 
Ozone and HDFS’s evolution
Ozone and HDFS’s evolutionOzone and HDFS’s evolution
Ozone and HDFS’s evolution
 
Postgresql Database Administration Basic - Day1
Postgresql  Database Administration Basic  - Day1Postgresql  Database Administration Basic  - Day1
Postgresql Database Administration Basic - Day1
 
Managing your Hadoop Clusters with Apache Ambari
Managing your Hadoop Clusters with Apache AmbariManaging your Hadoop Clusters with Apache Ambari
Managing your Hadoop Clusters with Apache Ambari
 

Similaire à 하이브 최적화 방안

DynamoDB를 게임에서 사용하기 – 김성수, 박경표, AWS솔루션즈 아키텍트:: AWS Summit Online Korea 2020
DynamoDB를 게임에서 사용하기 – 김성수, 박경표, AWS솔루션즈 아키텍트::  AWS Summit Online Korea 2020DynamoDB를 게임에서 사용하기 – 김성수, 박경표, AWS솔루션즈 아키텍트::  AWS Summit Online Korea 2020
DynamoDB를 게임에서 사용하기 – 김성수, 박경표, AWS솔루션즈 아키텍트:: AWS Summit Online Korea 2020Amazon Web Services Korea
 
ecdevday8 웹개발자의 약한고리 SQL 뛰어넘기
ecdevday8 웹개발자의 약한고리 SQL 뛰어넘기ecdevday8 웹개발자의 약한고리 SQL 뛰어넘기
ecdevday8 웹개발자의 약한고리 SQL 뛰어넘기Kenu, GwangNam Heo
 
sqlserver7.0 데이타베이스
sqlserver7.0 데이타베이스sqlserver7.0 데이타베이스
sqlserver7.0 데이타베이스영빈 송
 
효율적인Sql작성방법 3주차
효율적인Sql작성방법 3주차효율적인Sql작성방법 3주차
효율적인Sql작성방법 3주차희동 강
 
효율적인 SQL 작성방법 1주차
효율적인 SQL 작성방법 1주차효율적인 SQL 작성방법 1주차
효율적인 SQL 작성방법 1주차희동 강
 
데이타베이스 기본튜닝
데이타베이스 기본튜닝 데이타베이스 기본튜닝
데이타베이스 기본튜닝 Jinuk Bhak
 
Mongo db 시작하기
Mongo db 시작하기Mongo db 시작하기
Mongo db 시작하기OnGameServer
 
하이퍼레저 패브릭 데이터 구조
하이퍼레저 패브릭 데이터 구조하이퍼레저 패브릭 데이터 구조
하이퍼레저 패브릭 데이터 구조Logpresso
 
처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4성일 한
 
Ndc2011 성능 향상을_위한_데이터베이스_아키텍쳐_구축_및_개발_가이드
Ndc2011 성능 향상을_위한_데이터베이스_아키텍쳐_구축_및_개발_가이드Ndc2011 성능 향상을_위한_데이터베이스_아키텍쳐_구축_및_개발_가이드
Ndc2011 성능 향상을_위한_데이터베이스_아키텍쳐_구축_및_개발_가이드cranbe95
 
효율적인Sql작성방법 2주차
효율적인Sql작성방법 2주차효율적인Sql작성방법 2주차
효율적인Sql작성방법 2주차희동 강
 
[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)
[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)
[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)Sang Don Kim
 
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL TuningPgDay.Seoul
 
//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작
//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작
//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작Taeyoung Kim
 
효율적인Sql작성방법 4주차
효율적인Sql작성방법 4주차효율적인Sql작성방법 4주차
효율적인Sql작성방법 4주차희동 강
 
DataWorks Summit 2017
DataWorks Summit 2017DataWorks Summit 2017
DataWorks Summit 2017Daesung Park
 
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3Seok-joon Yun
 
[NDC08] 최적화와 프로파일링 - 송창규
[NDC08] 최적화와 프로파일링 - 송창규[NDC08] 최적화와 프로파일링 - 송창규
[NDC08] 최적화와 프로파일링 - 송창규ChangKyu Song
 

Similaire à 하이브 최적화 방안 (20)

Mongo db 최범균
Mongo db 최범균Mongo db 최범균
Mongo db 최범균
 
DynamoDB를 게임에서 사용하기 – 김성수, 박경표, AWS솔루션즈 아키텍트:: AWS Summit Online Korea 2020
DynamoDB를 게임에서 사용하기 – 김성수, 박경표, AWS솔루션즈 아키텍트::  AWS Summit Online Korea 2020DynamoDB를 게임에서 사용하기 – 김성수, 박경표, AWS솔루션즈 아키텍트::  AWS Summit Online Korea 2020
DynamoDB를 게임에서 사용하기 – 김성수, 박경표, AWS솔루션즈 아키텍트:: AWS Summit Online Korea 2020
 
ecdevday8 웹개발자의 약한고리 SQL 뛰어넘기
ecdevday8 웹개발자의 약한고리 SQL 뛰어넘기ecdevday8 웹개발자의 약한고리 SQL 뛰어넘기
ecdevday8 웹개발자의 약한고리 SQL 뛰어넘기
 
sqlserver7.0 데이타베이스
sqlserver7.0 데이타베이스sqlserver7.0 데이타베이스
sqlserver7.0 데이타베이스
 
효율적인Sql작성방법 3주차
효율적인Sql작성방법 3주차효율적인Sql작성방법 3주차
효율적인Sql작성방법 3주차
 
효율적인 SQL 작성방법 1주차
효율적인 SQL 작성방법 1주차효율적인 SQL 작성방법 1주차
효율적인 SQL 작성방법 1주차
 
데이타베이스 기본튜닝
데이타베이스 기본튜닝 데이타베이스 기본튜닝
데이타베이스 기본튜닝
 
Mongo db 시작하기
Mongo db 시작하기Mongo db 시작하기
Mongo db 시작하기
 
하이퍼레저 패브릭 데이터 구조
하이퍼레저 패브릭 데이터 구조하이퍼레저 패브릭 데이터 구조
하이퍼레저 패브릭 데이터 구조
 
처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4처음배우는 자바스크립트, 제이쿼리 #4
처음배우는 자바스크립트, 제이쿼리 #4
 
Ndc2011 성능 향상을_위한_데이터베이스_아키텍쳐_구축_및_개발_가이드
Ndc2011 성능 향상을_위한_데이터베이스_아키텍쳐_구축_및_개발_가이드Ndc2011 성능 향상을_위한_데이터베이스_아키텍쳐_구축_및_개발_가이드
Ndc2011 성능 향상을_위한_데이터베이스_아키텍쳐_구축_및_개발_가이드
 
효율적인Sql작성방법 2주차
효율적인Sql작성방법 2주차효율적인Sql작성방법 2주차
효율적인Sql작성방법 2주차
 
[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)
[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)
[Td 2015]치즈케이크 팩토리는 알겠는데, 데이터 팩토리는 뭔가요(한기환)
 
[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning[Pgday.Seoul 2020] SQL Tuning
[Pgday.Seoul 2020] SQL Tuning
 
//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작
//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작
//BUILD/ Seoul - .NET의 현재와 미래. 그 새로운 시작
 
효율적인Sql작성방법 4주차
효율적인Sql작성방법 4주차효율적인Sql작성방법 4주차
효율적인Sql작성방법 4주차
 
Meteor IoT
Meteor IoTMeteor IoT
Meteor IoT
 
DataWorks Summit 2017
DataWorks Summit 2017DataWorks Summit 2017
DataWorks Summit 2017
 
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
[2015-06-26] Oracle 성능 최적화 및 품질 고도화 3
 
[NDC08] 최적화와 프로파일링 - 송창규
[NDC08] 최적화와 프로파일링 - 송창규[NDC08] 최적화와 프로파일링 - 송창규
[NDC08] 최적화와 프로파일링 - 송창규
 

하이브 최적화 방안

  • 1. 하이브 최적화 방안 최종욱 tchoi@hortonworks.com
  • 4. 모든 하둡은
 스팅어의 하이브를 기본 탑재 3 단계 2 단계 1 단계
  • 5. 모든 하둡 분석 도구들은
 하이브를 기본 지원 파워 BI, 엑셀로 하이브 질의 자동 생성 SQL 질의를 하이브로 자동 변환 기존 다이어그램을 하이브로 자동 변환 탐색기, 대시보드 등에서 활용
  • 6. 하이브 버전별 최적화 요소 버전 분류 세부 관련 용어 ~0.10 처리 성능 디렉토리 구조 파티션, 버킷 0.11 처리 성능 + 대용량 조인 SMB 조인 0.12 저장 용량 + 자료 압축 ORC, ZLIB 0.13 처리 성능 + 실시간 질의 테즈, 벡터화
  • 7. 0.11: 다양한 조인 구현 • 고객 정보와 주문 정보를 합쳐서 각 고객이 어떤 주문을 했 는지 모아서 보고 싶을 때. 각 주문이 고객 번호를 가리키는 방식. Quick Refresher on Joins customer& first& last& order& id& cid& price& quan6ty& Nick' Toner' 11911' 4150' 10.50' 3' Jessie' Simonds' 11912' 11914' 12.25' 27' Kasi' Lamers' 11913' 3491' 5.99' 5' Rodger' Clayton' 11914' 2934' 39.99' 22' Verona' Hollen' 11915' 11914' 40.50' 10' SELECT&*&FROM&customer&join&order&ON#customer.id#=#order.cid;& Joins'match'values'from'one'table'against'values'in'another'table.'
  • 8. 하이브의 조인 전략들 방식 셔플 조인 맵/리듀스를 이용해서 키를 기준으로 재분배(셔플)하여 조인 측에서 조인을 수행. 장점 어떤 형태의 데이터 크기와 구성에서도 작동함. 작은 테이블이 모든 노드의 가장 큰 테이블에서 굉장히 메모리에 올라가고, 매퍼는 빠른 단일 스캔. 브로드캐스트 큰 테이블을 훑어보며 조인을 조인 함. 매퍼는 각 키가 인접한 특성 정렬-병합-버 을 이용해 효과적인 조인을 킷(SMB) 조 수행. 인 단점 가장 자원을 많이 사용하며 가장 느린 조인 방식. 작은 테이블이 메모리에 들어 갈 정도로 작아야 함. 어떤 크기의 테이블에서도 굉 사전에 자료가 정렬되고 버켓 장히 빠름. 화 되어있어야 함.
  • 9. 셔플 조인 Shuffle Joins in Map Reduce customer& first& last& order& id& cid& price& quan6ty& Nick' Toner' 11911' 4150' 10.50' 3' Jessie' Simonds' 11912' 11914' 12.25' 27' Kasi' Lamers' 11913' 3491' 5.99' 5' Rodger' Clayton' 11914' 2934' 39.99' 22' Verona' Hollen' 11915' 11914' 40.50' 10' SELECT&*&FROM&customer&join&order&ON#customer.id#=#order.cid;& {'id:'11911,'{'first:'Nick,'last:'Toner'}}' {'id:'11914,'{'first:'Rodger,'last:'Clayton'}}' …' {'cid:'4150,'{'price:'10.50,'quan1ty:'3'}}' {'cid:'11914,'{'price:'12.25,'quan1ty:'27'}}' …' M M R {'id:'11911,'{'first:'Nick,'last:'Toner'}}' {'cid:'4150,'{'price:'10.50,'quan1ty:'3'}}' …' R {'id:'11914,'{'first:'Rodger,'last:'Clayton'}}' {'cid:'11914,'{'price:'12.25,'quan1ty:'27'}}' Iden1cal'keys'shuffled'to'the'same'reducer.'Join'done'reduceEside.' Expensive'from'a'network'u1liza1on'standpoint.' Deep Dive content by Hortonworks, Inc. is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Page 15
  • 10. Broadcast Join 브로드캐스트 조인 •  Star schemas use dimension 작은 디멘전 테이블들을 사용 to fit in RAM. • 스타 스키마는 메모리에 올라올 정도로 tables small enough •  Small tables 작은 테이블들이 메모리에 올라감 • 모든 노드에서 held in memory by all nodes. • 큰 테이블을 through the large table. •  Single pass통한 단일 스캔 • 일반적인 DW에서 스타-스키마 방식의 조인에서 널리 쓰임 •  Used for star-schema type joins common in DW.
  • 11. 양 테이블이 메모리에
 When both are too large for memory: 비해 너무 클 때: customer& first& last& order& id& cid& price& quan6ty& Nick' Toner' 11911' 4150' 10.50' 3' Jessie' Simonds' 11912' 11914' 12.25' 27' Kasi' Lamers' 11913' 11914' 40.50' 10' Rodger' Clayton' 11914' 12337' 39.99' 22' Verona' Hollen' 11915' 15912' 40.50' 10' SELECT&*&FROM&customer&join&order&ON#customer.id#=#order.cid;& Cluster&and&sort&by&the&most&common&join&key.& CREATE&TABLE&order&(cid&int,&price&float,&quantity&int)& CLUSTERED#BY(cid)#SORTED#BY(cid)#INTO#32#BUCKETS;# CREATE&TABLE&customer&(id&int,&first&string,&last&string)& CLUSTERED#BY(id)#SORTED#BY(id)#INTO#32#BUCKETS;# Deep Dive content by Hortonworks, Inc. is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Page 17
  • 12. 하이브의 클러스터링과 정렬 Hive’s Clustering and Sorting customer& first& last& order& id& cid& price& quan6ty& Nick' Toner' 11911' 4150' 10.50' 3' Jessie' Simonds' 11912' 11914' 12.25' 27' Kasi' Lamers' 11913' 11914' 40.50' 10' Rodger' Clayton' 11914' 12337' 39.99' 22' Verona' Hollen' 11915' 15912' 40.50' 10' SELECT&*&FROM&customer&join&order&ON#customer.id#=#order.cid;& Observa1on'1:' Sor1ng'by'the'join'key'makes'joins'easy.' All'possible'matches'reside'in'the'same'area'on'disk.' Deep Dive content by Hortonworks, Inc. is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Page 18
  • 13. 하이브의 클러스터링과 정렬 Hive’s Clustering and Sorting customer& first& last& order& id& cid& price& quan6ty& Nick' Toner' 11911' 4150' 10.50' 3' Jessie' Simonds' 11912' 11914' 12.25' 27' Kasi' Lamers' 11913' 11914' 40.50' 10' Rodger' Clayton' 11914' 12337' 39.99' 22' Verona' Hollen' 11915' 15912' 40.50' 10' SELECT&*&FROM&customer&join&order&ON#customer.id#=#order.cid;& Observa1on'2:' Hash'bucke1ng'a'join'key'ensures'all'matching'values'reside'on'the'same'node.' EquiEjoins'can'then'run'with'no'shuffle.' Deep Dive content by Hortonworks, Inc. is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License. Page 19
  • 14. 데이터 지역성 통제 • 버켓팅 (Bucketing): • • • 파티션 값을 해시하여 미리 설정된 버켓에 저장 일반적으로 정렬과 함께 사용 스큐 (Skew): • • • 값을 분리된 파일들로 저장 특정한 값이 자주 등장할 때 사용 복제 계수 (Replication Factor): • • • 복제 계수를 증가시켜 읽기 성능을 향상 HDFS 수준에서 설정 정렬 (Sorting): • 주어진 컬럼을 기준으로 값을 정렬 • ORC 파일 필터 다운과 사용했을 때 질의를 굉장히 가속
  • 15. 하이브 자료 설계 지침 테이블 크기 작음 모두 큼 큼 큼 데이터 특성 질의 패턴 추천 전략 자주 쓰임 모두 복제 계수를 증가 모두 특정한 필터 특정한 질의에서 가장 많이 쓰 이는 컬럼을 기준으로 정렬 모두 다른 큰 테이블에 조인됨 테이블을 조인 키에 따라 정렬 하고 버켓화 한 값이 25% 이 모두 상으로 자주 쓰임 모두 잦은 값을 별도의 스큐로 분리 질의가 날짜처럼 자연적으로 자료를 자연적인 경계에 맞추 경계들을 갖는 경향이 있음 어 파티션
  • 17. 작업 예: 스테이징 테이블 생성 Example Workflow: Create a Stag CREATE EXTERNAL TABLE pos_staging (! !txnid STRING,! !txntime STRING,! !givenname STRING,! !lastname STRING,! !postalcode STRING,! !storeid STRING,! !ind1 STRING,! !productid STRING,! !purchaseamount FLOAT,! !creditcard STRING! )ROW FORMAT DELIMITED FIELDS TERMINATED BY '|'! LOCATION '/user/hdfs/staging_data/pos_staging';!
  • 18. 작업 예: 파티션Choose a partition schem 스키마를 선택 Example Workflow: hive> select distinct concat(year(txntime),month(txntime)) as part_dt ! from pos_staging;! …! OK! 20121! 201210! 201211! 201212! 20122! 20123! 20124! 20125! 20126! 20127! 20128! 20129! Time taken: 21.823 seconds, Fetched: 12 row(s)! Execute a query to determine if the partition choice returns a reasonable result. We will use this projection to create partitions for our data set. You want to keep your partitions
  • 19. 작업 예: 최적화된 Define optimized ta 테이블 정의 Example Workflow: CREATE TABLE fact_pos! (! !txnid STRING,! !txntime STRING,! !givenname STRING,! !lastname STRING,! !postalcode STRING,! !storeid STRING,! !ind1 STRING,! !productid STRING,! !purchaseamount FLOAT,! !creditcard STRING! ) PARTITIONED BY (part_dt STRING)! CLUSTERED BY (txnid)! SORTED BY (txnid)! INTO 24 BUCKETS! STORED AS ORC tblproperties ("orc.compress"="SNAPPY");! The part_dt field is defined in the partition by clause and cannot be the same name as any fields. In this case, we will be performing a modification of txntime to generate a partition k
  • 20. 작업 예: 데이터를 최적화된
 Example Workflow: Load Data Into Optimized 테이블에 탑재 set hive.enforce.sorting=true;! set hive.enforce.bucketing=true;! set hive.exec.dynamic.partition=true;! set hive.exec.dynamic.partition.mode=nonstrict; ! set mapreduce.reduce.input.limit=-1;! ! FROM pos_staging! INSERT OVERWRITE TABLE fact_pos! PARTITION (part_dt)! SELECT! !txnid,! !txntime,! !givenname,! !lastname,! !postalcode,! !storeid,! !ind1,! !productid,! !purchaseamount,! !creditcard,! !concat(year(txntime),month(txntime)) as part_dt! SORT BY productid;! ! We use this commend to load data from our staging table into
  • 21. 작업 예: 복제 계수를 증가 Example Workflow: Increase replication factor hadoop fs -setrep -R –w 5 /apps/hive/warehouse/fact_pos! Increase the replication factor for the high performance table. This increases the chance for data locality. In this case, the increase in replication factor is not for additional resiliency. This is a trade-off of storage for performance.
  • 22. 작업 예: 숏서킷 읽기를 활성화 Example Workflow: Enabling Short Circuit Read In hdfs-site.xml (or your custom Ambari settings for HDFS, restart service after):! ! dfs.block.local-path-access.user=hdfs! dfs.client.read.shortcircuit=true! dfs.client.read.shortcircuit.skip.checksum=false! Short Circuit reads allow the mappers to bypass the overhead of opening a port to the datanode if the data is local. The permissions for the local block files need to permit hdfs to read them (should be by default already) See HDFS-2246 for more details. Deep Dive content by Hortonworks, Inc. is licensed under a Page 47
  • 23. 작업 예: 질의 수행 Example Workflow: Execute your query set hive.mapred.reduce.tasks.speculative.execution=false;! set io.sort.mb=300;! set mapreduce.reduce.input.limit=-1;! ! select productid, ROUND(SUM(purchaseamount),2) as total ! from fact_pos ! where part_dt between ‘201210’ and ‘201212’! group by productid ! order by total desc ! limit 100;! ! …! OK! 20535 !3026.87! 39079 !2959.69! 28970 !2869.87! 45594 !2821.15! …! 15649 !2242.05! 47704 !2241.22! 8140 !2238.61! Time taken: 40.087 seconds, Fetched: 100 row(s)! In the case above, we have a simple query executed to test out our table. We
  • 24. 작업 예: 앰버리에서
 Example Workflow: Check Execution Path in Ambari 실행 경로 체크 You can check the execution path in Ambari’s Job viewer. This gives a high level overview of the stages and particular number of map and reduce tasks. With Tez, it also shows task
  • 25. 하이브 고속 질의 체크 목록 • 데이터를 자연스런 질의 경계에 의해 파티션함 (예: 날짜). • 가장 자주 조인되는 데이터를 인접시켜 데이터 셔플을 최소화. • 잦은 값은 스큐를 이용하여 분산 • 숏서킷 읽기 활성화. • ORC 파일 사용. • 자주 타겟되는 질의에서 로우 스킵을 사용하기 위해 컬럼 재정렬. • 쿼리 계획을 확인하여 가장 큰 테이블을 기준으로 단일 스캔하는지 확인. • 쿼리 계획을 확인하여 파티션 건너뛰기가 일어나는지 확인. • 매 조인마다 최소한 하나의 ON 절 사용.
  • 26. 0.12: 자료 압축 • “CREATE TABLE” 명령문 끝에 “STORED AS ORC” 구 문만 추가하면 압축 적용. • 평균 1/4으로 용량이 줄어들어 4배 더 많은 데이터를 보관 가능.
  • 27. 0.13: 실시간 질의 • 테즈 사용 • 테즈 프로세스 상주: 프로세스를 새로 만드느라 낭비되는 시간을 없앰. 워밍업과 재사용 등 다양한 기법 도입. • 맵리듀스 재구성: 예전 맵리듀스 는 맵과 리듀스가 한 쌍으로 묶 여, 다음 맵으로 전하기 위해서는 디스크에 써야했다. 이 제약을 풀 어 불필요한 디스크 입출력을 없 앴다.
  • 28. 성능 측정 • https://github.com/ cartershanklin/hivetestbench • TPC DS 기반의 성능 측정 도구를 오픈소스로 제공. 일반 텍스트와 압 축 및 최적화된 형태 두 가지를 생 성. 임팔라 등 다른 시스템과 비교에 도 사용 가능. • 국내 대기업 고객사 시험 환경에서 적용하자, 호튼웍스 홈페이지에서 밝힌 결과와 초단위로 일치.