검색결과 리스트
글
[java] DB에 다량건 데이터 INSERT 시 excuteBatch() 사용
Q. 약 15만 라인의 데이터를 txt 파일을 읽어와서
DB에 INSERT 몇개 단위로 배치를 돌릴경우 가장 효율적인가?
Query를 excute 할 때, excuteUpdate()와 excuteBatch()의 성능을 테스트한다.
※ 소스코드
long start = System.nanoTime(); while( ( s = reader.readLine() ) != null ) { totCnt++; String no = s.substring( 0, 6 ); int index1 = s.indexOf( '|', 11 ); int index2 = s.indexOf( '|', index1 + 1 ); String address = s.substring( index1 + 1, index2 ); stmt.setInt( 1, totCnt ); stmt.setString( 2, no ); stmt.setString( 3, address ); // case 1 stmt.executeUpdate(); // case 2 stmt.addBatch(); cnt++; if( cnt == 100 ) { cnt = 0; stmt.executeBatch(); } }
1. 매번 excuteUpdate() 실행
- 4분 이상의 작업에 인내심이 바닥남.... 중지함.
2. addbatch(), excuteBatch() 를 이용 100건당 실행
- 39459776065(ns) => 3.9초
3. addbatch(), excuteBatch() 를 이용 500건당 실행
- 11512822395(ns) => 1.1초
4. addbatch(), excuteBatch() 를 이용 1000건당 실행
- 6683119024(ns) => 0.66초
5. addbatch(), excuteBatch() 를 이용 10000건당 실행 (BEST 乃)
- 1442062299(ns) => 0.144초
- 1423391208(ns) => 0.142초
- 1475451583(ns) => 0.147초
6. addbatch(), excuteBatch() 를 이용 20000건당 실행 (Rank 3)
- 1690612350(ns) => 0.16초
- 1597981482(ns) => 0.15초
7. addbatch(), excuteBatch() 를 이용 30000건당 실행 (Rank 4)
- 1608968179(ns) => 0.16초
- 1619791589(ns) => 0.16초
8. addbatch(), excuteBatch() 를 이용 50000건당 실행 (Rank 2)
- 1488951363(ns) => 0.148초
- 1466872514(ns) => 0.146초
※ 결론.
1. 다량건 처리는 excuteUpdate 보다 excuteBatch 를 이용해야함!
2. batch 처리시 많은량을 batch로 넣는다해서 (무조건) 빨리 되는건 아님.
3. batch 처리할때에도 적당한 양 만큼 batch 로 처리하는것이 올바름.
4. 테스트 횟수와 각 장비들의 상태가 같지 않았기 때문에, 정확한 결론은 아님(참고할순 있지 않나..?)
'program > java' 카테고리의 다른 글
[java] for 문에서 객체의 size 선언법 (0) | 2012.10.05 |
---|---|
[java] 문자열(String) 나누기, Split VS SubString (0) | 2012.10.05 |
[java] ? 연산, Question Mark 연산 (0) | 2012.10.05 |
[gwt] 한글 깨짐 현상, css 목록 안불러와질때 (0) | 2012.10.05 |
[java] 자바 환경변수 설정, java 환경변수 설정 (0) | 2012.10.05 |