SSISO Community

시소당

Sqlldr (sqlload) Parallel Execution | Oracle-ETL

 

[서론]
1. 오라클 데이터 로딩 퍼포먼스를 극대화 한다.
2. MySQL 데이터 로딩 퍼포먼스를 극대화 한다.

[본론]
Oracle 로딩
sqlldr를 실행할 서버의 CPU 개수와 데이터 파일개수를 일치시켜주자.
나누어 로딩할 파일개수는 조절이 가능하므로
리소스를 고려하여 파일을 쪼개어 실행한다.

0. 데이터를 넣을 대상 empty table 준비
데이터를 넣을 테이블을 하나 생성한다.
퍼포먼스를 향상 시키려면 direct 모드로 loading을 해야하고,
direct mode로 loading을 하려면,
테이블은 인덱스를 생성하지 않아야 하며, 인덱스가 기생성되어 있는 테이블에
로딩을 하는 것이라면 index를 drop 하거나 아래와 같이 disable 시켜준다.

 SQL> drop index index명; --또는 PK로 설정되어 있을 경우,
 SQL> alter table table명 drop constraint primary key; -- 하면된다.

1. Datafile 준비
DB에 넣을 파일을 4등분하여 4개의 파일로 저장한다.
shell> wc -l file.txt
20000
shell> split -l 5000 -d file.txt file. # 5000라인씩 끊는다고 가정하자.

각각의 파일이름은 /data/file.01, /data/file.02, /data/file.03, /data/file.04 라고 가정하자.

shell> head /data/file.01
홍길동 1024050
김갑순 2384867
이정화 3847293
박경모 3842983


2. Controlfile 준비
[file1.ctl]
load data infile '/data/file1.txt'
truncate into table temp_4parallel -- 실패를 대비해 truncate 구문으로 준비한다.
fieleds terminated by '\t' optionally enclosed by '"'
trailing nullcols
(
col1 char,
col2 char
)

[file2.ctl]
load data infile '/data/file2.txt'
truncate into table temp_4parallel -- 실패를 대비해 truncate 구문으로 준비한다.
fieleds terminated by '\t' optionally enclosed by '"'
trailing nullcols
(
col1 char,
col2 char
)

.. 동일한 방법으로 file3.ctl과 file4.ctl도 생성해준다.

3. 실행파일 준비(필자는 csh로 작성했다)
[fileload.csh]
#!/bin/csh
SQLLDR user/passwd CONTROL=file1.ctl DIRECT=TRUE PARALLEL=TRUE
SQLLDR user/passwd CONTROL=file2.ctl DIRECT=TRUE PARALLEL=TRUE
SQLLDR user/passwd CONTROL=file3.ctl DIRECT=TRUE PARALLEL=TRUE
SQLLDR user/passwd CONTROL=file4.ctl DIRECT=TRUE PARALLEL=TRUE

주의사항 : 반드시 parallel loading은 direct 모드로 실행해야 한다.
(앞서 언급한대로, direct 모드로 실행시에는 index를 disable 또는 drop해야하니 주의하자)

4. 실행
shell> fileload.csh

CPU개수가 4개라고 가정했을 때, 서버로드가 높지 않다면, 4배의 속도향상을
체험할 수 있을 것이다.

MySQL 로딩
1. 퍼포먼스
MySQL의 로딩 퍼포먼스는 Row의 사이즈 및
Row 의 Count, 즉, 파일의 사이즈에 따라 민감하게 영향을 받는데,
이로 인해 한번에 로딩하는 량을 줄이는 방법으로 퍼포먼스를 극대화 할수 있다.

/data01/mysql/bin/mysqlimport -h [server IP] -udbm -pdbmpw --local -d
user_group /data/file1.txt & # -d 옵션은 오라클의 control 파일에서의 truncate into... 구문과 같다.

/data01/mysql/bin/mysqlimport -h [server IP] -udbm -pdbmpw --local
user_group /data/file2.txt & # -d 옵션이 생략되면 오라클 control 파일에서 append into.. 구문과 같다.

/data01/mysql/bin/mysqlimport -h [server IP] -udbm -pdbmpw --local
user_group /data/file3.txt &

/data01/mysql/bin/mysqlimport -h [server IP] -udbm -pdbmpw --local
user_group /data/file4.txt &


 이와 같은 방법으로 여러개의 프로세스를 동시에 실행하여 퍼포먼스를 N배만큼 빠르게 할 수 있다.

 

출처 : http://niflheim.tistory.com/category/Oracle-ETL

1719 view

4.0 stars