SlideShare una empresa de Scribd logo
1 de 28
Descargar para leer sin conexión
하이브 최적화 방안
최종욱 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 기반의 성능 측정 도구를
오픈소스로 제공. 일반 텍스트와 압
축 및 최적화된 형태 두 가지를 생
성. 임팔라 등 다른 시스템과 비교에
도 사용 가능.

•

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

Más contenido relacionado

La actualidad más candente

Best Practices for Enabling Speculative Execution on Large Scale Platforms
Best Practices for Enabling Speculative Execution on Large Scale PlatformsBest Practices for Enabling Speculative Execution on Large Scale Platforms
Best Practices for Enabling Speculative Execution on Large Scale PlatformsDatabricks
 
Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...
Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...
Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...Daniel Hochman
 
The Apache Spark File Format Ecosystem
The Apache Spark File Format EcosystemThe Apache Spark File Format Ecosystem
The Apache Spark File Format EcosystemDatabricks
 
How to Automate Performance Tuning for Apache Spark
How to Automate Performance Tuning for Apache SparkHow to Automate Performance Tuning for Apache Spark
How to Automate Performance Tuning for Apache SparkDatabricks
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesDatabricks
 
Building a SIMD Supported Vectorized Native Engine for Spark SQL
Building a SIMD Supported Vectorized Native Engine for Spark SQLBuilding a SIMD Supported Vectorized Native Engine for Spark SQL
Building a SIMD Supported Vectorized Native Engine for Spark SQLDatabricks
 
How to understand and analyze Apache Hive query execution plan for performanc...
How to understand and analyze Apache Hive query execution plan for performanc...How to understand and analyze Apache Hive query execution plan for performanc...
How to understand and analyze Apache Hive query execution plan for performanc...DataWorks Summit/Hadoop Summit
 
How to Performance-Tune Apache Spark Applications in Large Clusters
How to Performance-Tune Apache Spark Applications in Large ClustersHow to Performance-Tune Apache Spark Applications in Large Clusters
How to Performance-Tune Apache Spark Applications in Large ClustersDatabricks
 
HBase in Practice
HBase in PracticeHBase in Practice
HBase in Practicelarsgeorge
 
Top 5 Mistakes to Avoid When Writing Apache Spark Applications
Top 5 Mistakes to Avoid When Writing Apache Spark ApplicationsTop 5 Mistakes to Avoid When Writing Apache Spark Applications
Top 5 Mistakes to Avoid When Writing Apache Spark ApplicationsCloudera, Inc.
 
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...Databricks
 
Dynamic Partition Pruning in Apache Spark
Dynamic Partition Pruning in Apache SparkDynamic Partition Pruning in Apache Spark
Dynamic Partition Pruning in Apache SparkDatabricks
 
Spark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in Spark
Spark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in SparkSpark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in Spark
Spark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in SparkBo Yang
 
Understanding Query Plans and Spark UIs
Understanding Query Plans and Spark UIsUnderstanding Query Plans and Spark UIs
Understanding Query Plans and Spark UIsDatabricks
 
Time-Series Apache HBase
Time-Series Apache HBaseTime-Series Apache HBase
Time-Series Apache HBaseHBaseCon
 
Real-Time Anomoly Detection with Spark MLib, Akka and Cassandra by Natalino Busa
Real-Time Anomoly Detection with Spark MLib, Akka and Cassandra by Natalino BusaReal-Time Anomoly Detection with Spark MLib, Akka and Cassandra by Natalino Busa
Real-Time Anomoly Detection with Spark MLib, Akka and Cassandra by Natalino BusaSpark Summit
 
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudAmazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudNoritaka Sekiyama
 

La actualidad más candente (20)

Best Practices for Enabling Speculative Execution on Large Scale Platforms
Best Practices for Enabling Speculative Execution on Large Scale PlatformsBest Practices for Enabling Speculative Execution on Large Scale Platforms
Best Practices for Enabling Speculative Execution on Large Scale Platforms
 
Ceph on Windows
Ceph on WindowsCeph on Windows
Ceph on Windows
 
Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...
Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...
Geospatial Indexing at Scale: The 15 Million QPS Redis Architecture Powering ...
 
The Apache Spark File Format Ecosystem
The Apache Spark File Format EcosystemThe Apache Spark File Format Ecosystem
The Apache Spark File Format Ecosystem
 
How to Automate Performance Tuning for Apache Spark
How to Automate Performance Tuning for Apache SparkHow to Automate Performance Tuning for Apache Spark
How to Automate Performance Tuning for Apache Spark
 
The Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization OpportunitiesThe Parquet Format and Performance Optimization Opportunities
The Parquet Format and Performance Optimization Opportunities
 
Building a SIMD Supported Vectorized Native Engine for Spark SQL
Building a SIMD Supported Vectorized Native Engine for Spark SQLBuilding a SIMD Supported Vectorized Native Engine for Spark SQL
Building a SIMD Supported Vectorized Native Engine for Spark SQL
 
How to understand and analyze Apache Hive query execution plan for performanc...
How to understand and analyze Apache Hive query execution plan for performanc...How to understand and analyze Apache Hive query execution plan for performanc...
How to understand and analyze Apache Hive query execution plan for performanc...
 
How to Performance-Tune Apache Spark Applications in Large Clusters
How to Performance-Tune Apache Spark Applications in Large ClustersHow to Performance-Tune Apache Spark Applications in Large Clusters
How to Performance-Tune Apache Spark Applications in Large Clusters
 
HBase in Practice
HBase in PracticeHBase in Practice
HBase in Practice
 
Spark on YARN
Spark on YARNSpark on YARN
Spark on YARN
 
Top 5 Mistakes to Avoid When Writing Apache Spark Applications
Top 5 Mistakes to Avoid When Writing Apache Spark ApplicationsTop 5 Mistakes to Avoid When Writing Apache Spark Applications
Top 5 Mistakes to Avoid When Writing Apache Spark Applications
 
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
Deep Dive into Spark SQL with Advanced Performance Tuning with Xiao Li & Wenc...
 
Dynamic Partition Pruning in Apache Spark
Dynamic Partition Pruning in Apache SparkDynamic Partition Pruning in Apache Spark
Dynamic Partition Pruning in Apache Spark
 
Node Labels in YARN
Node Labels in YARNNode Labels in YARN
Node Labels in YARN
 
Spark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in Spark
Spark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in SparkSpark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in Spark
Spark Shuffle Deep Dive (Explained In Depth) - How Shuffle Works in Spark
 
Understanding Query Plans and Spark UIs
Understanding Query Plans and Spark UIsUnderstanding Query Plans and Spark UIs
Understanding Query Plans and Spark UIs
 
Time-Series Apache HBase
Time-Series Apache HBaseTime-Series Apache HBase
Time-Series Apache HBase
 
Real-Time Anomoly Detection with Spark MLib, Akka and Cassandra by Natalino Busa
Real-Time Anomoly Detection with Spark MLib, Akka and Cassandra by Natalino BusaReal-Time Anomoly Detection with Spark MLib, Akka and Cassandra by Natalino Busa
Real-Time Anomoly Detection with Spark MLib, Akka and Cassandra by Natalino Busa
 
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the CloudAmazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
Amazon S3 Best Practice and Tuning for Hadoop/Spark in the Cloud
 

Similar a 하이브 최적화 방안

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
 

Similar a 하이브 최적화 방안 (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 기반의 성능 측정 도구를 오픈소스로 제공. 일반 텍스트와 압 축 및 최적화된 형태 두 가지를 생 성. 임팔라 등 다른 시스템과 비교에 도 사용 가능. • 국내 대기업 고객사 시험 환경에서 적용하자, 호튼웍스 홈페이지에서 밝힌 결과와 초단위로 일치.