SQLPLUS> create table test
2 ( id number,
3 code varchar2(20),
4 descr varchar2(20),
5 insert_user varchar2(30),
6 insert_date date
7 )
8 /
Table created.
import java.sql.*;
public class perftest {
public static void main (String arr[]) throws Exception
{
DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
Connection con = DriverManager.getConnection
("jdbc:oracle:thin:@localhost:1521:ora11gr2","scott","tiger");
Integer iters = new Integer(arr[0] ); -- insert 할 전체 row 수
Integer commitCnt = new Integer(arr[1]); -- 몇 개의 row 단위로 커밋할지
con.setAutoCommit (false) ;
dolnserts( con, 1, 1 );
Statement stmt = con.createStatement ();
stmt.execute( "begin dbms_monitor.session_trace_enable(waits=>true); end ;" );
dolnserts( con, iters.intValue() , commitCnt.intValue() );
con.close();
}
static void dolnserts(Connection con, int count, int commitCount )
throws Exception
{
PreparedStatement ps = con.prepareStatement
("insert into test " + "(id, code, descr,insert_user,insert_date)" + " values (?,?,?, user, sysdate)" );
int rowcnt = 0; int committed =0;
for (int i =0; i < count; i++ {
ps.setlnt(1 ,i);
ps.setString(2,"PS . code"+i);
ps.setString(3,"PS . desc"+i);
ps.executeUpdate();
rowcnt++;
if ( rowcnt == commitCount )
{
con.commit() ;
rowcnt =0;
committed++;
}
}
con.commit () ;
System.out.println
("pstatement rows/commitcnt = " + count + " I " + committed);
}
}
SQLPLUS >grant select on v_$statname to hong ;
Grant succeeded.
SQLPLUS >grant select on v_$mystat to hong ;
Grant succeeded.
SQLPLUS> create or replace function get_stat_val( p_name in varchar2 ) return number
as
l_val number;
begin
select b.value
into l_val
from v$statname a, v$mystat b
where a.statistic# = b.statistic#
and a.name = p_name;
return l_val ;
end ;
/
Function created.
SQLPLUS >create table t as select * from all_objects ;
Table created.
SQLPLUS >create table big_table as select * from all_objects ;
Table created.
SQLPLUS> set serveroutput on
SQLPLUS> declare
l_redo number;
l_cpu number;
l_ela number;
begin
dbms_output.put_line
( '-' || ' Rows' || ' Redo' ||
' CPU' || ' Elapsed') ;
for i in 1 .. 6
loop
l_redo := get_stat_val ('redo size');
insert into t select * from big_table where rownum <= power(10,i) ;
l_cpu := dbms_utility.get_cpu_time;
l_ela := dbms_utility.get_time;
commit work write wait ;
dbms_output.put_line
( '-' ||
to_char( power(10, i), '9,999,999') ||
to_char( (get_stat_val('redo size')-l_redo), '999,999,999') ||
to_char( (dbms_utility.get_cpu_time-l_cpu), '999,999') ||
to_char( (dbms_utility.get_time-l_ela), '999,999') );
end loop;
end;
/
- Rows Redo CPU Elapsed
- 10 1,420 0 2
- 100 9,220 1 2
- 1,000 99,916 0 1
- 10,000 1,012,712 0 3
- 100,000 10,441,412 0 8
- 1,000,000 59,240,536 0 7
PL/SQL procedure successfully completed.
* log buffer 4.6 MB / 300MB 온라인 로그파일 6개 (2개 멤버씩 1개의 그룹 = 3개 그룹)
* 시간단위는 1/100초
SQLPLUS> declare
l_redo number;
l_cpu number;
l_ela number;
begin
dbms_output.put_line
( '-' || ' Rows' || ' Redo' ||
' CPU' || ' Elapsed') ;
for i in 1 .. 6
loop
l_redo := get_stat_val ('redo size');
insert into t select * from big_table where rownum <= power(10,i) ;
l_cpu := dbms_utility.get_cpu_time;
l_ela := dbms_utility.get_time;
-- commit work write wait ;
rollback ;
dbms_output.put_line
( '-' ||
to_char( power(10, i), '9,999,999') ||
to_char( (get_stat_val('redo size')-l_redo), '999,999,999') ||
to_char( (dbms_utility.get_cpu_time-l_cpu), '999,999') ||
to_char( (dbms_utility.get_time-l_ela), '999,999') );
end loop;
end;
/
- Rows Redo CPU Elapsed
- 10 1,528 1 0
- 100 10,072 0 0
- 1,000 102,908 1 1
- 10,000 1,047,952 0 1
- 100,000 10,901,836 3 3
- 1,000,000 61,741,852 19 40 <--
PL/SQL procedure successfully completed.
- 강좌 URL : http://www.gurubee.net/lecture/4027
- 구루비 강좌는 개인의 학습용으로만 사용 할 수 있으며, 다른 웹 페이지에 게재할 경우에는 출처를 꼭 밝혀 주시면 고맙겠습니다.~^^
- 구루비 강좌는 서비스 제공을 위한 목적이나, 학원 홍보, 수익을 얻기 위한 용도로 사용 할 수 없습니다.