declare file_name varchar2(100) := 'data.log'; db_dir_name varchar2(100) := 'LOADF'; dest_loc BLOB := empty_blob(); src_loc BFILE := BFILENAME(db_dir_name, file_name); destoff number := 1; srcoff number :=1; begin DBMS_LOB.OPEN(src_loc, DBMS_LOB.FILE_READONLY); DBMS_LOB.CREATETEMPORARY(lob_loc => dest_loc, cache => false); DBMS_LOB.OPEN(dest_loc, DBMS_LOB.LOB_READWRITE); DBMS_LOB.LOADBLOBFROMFILE (dest_loc,src_loc,DBMS_LOB.getLength(src_loc),destoff,srcoff); insert into lobins values (dest_loc); commit; DBMS_LOB.CLOSE(dest_loc); DBMS_LOB.CLOSE(src_loc); end; /
Showing posts with label blob. Show all posts
Showing posts with label blob. Show all posts
Wednesday, September 28, 2016
Insert a File as BLOB Using DBMS_LOB
Following script could be used to insert a file as a BLOB into a table. The file to be inserted must reside in the location referred by the database directory LOADF. File name in this case data.log. File is inserted to table called lobins which only has single column which is of BLOB type.
Tuesday, August 19, 2014
Nologging vs Logging for LOBs and enq: CF - contention
Changing the logging option is one of the possible performance tuning tasks when dealing with LOBs. However use of nologging will make recovery of these lob segments impossible as such use of this will also depends on the nature of the application data. For transient data where recovery is not expected in case of database failure nologging option would be suitable. When the logging option is not explicitly mentioned this results in the tablespace's logging option being inherited by the lob segment. Refer Oracle documentation for more logging related information on basicfile and securefile.
This post presents the result of a simple test carried out comparing the nologging vs logging for both basicfile and securefile LOB segments. The java code used for the test is given at the end of the post. First case is the basicfile. Nologging is not possible if the cache is enable on the lob segment. Therefore nocache option is chosen for both logging and nologging. The table definition is given below.
Redo size statistic and the log file sync wait event times are compared for the two test runs as these are directly related to the logging option. Graphs below show the comparison of these for each test run.
There's no surprise that nologging option generates the lowest amount of redo. The logging test case generated around 83-84MB of redo for insert and update which is roughly the same size as the LOB inserted/updated (800KB x 100). There's minimal logging during the nologging test. Since redo is counted for the entire test, the redo seen could be the redo generated for the table data insert (as oppose to lobs) which still is on a tablespace with logging. Nevertheless a clear difference could be observed in the amount of redo generated when nologging is used. This is also reflected in the log file sync time for the two test cases which got reduced from several minutes to under a minute.
Next the same test was executed but this time the lob segment was stored as securefile. The table DDL is given below. Only difference apart from the securefile is Pctversion 0 has been replaced with retention none. All other settings are same as the basic file (tablespaces, database and etc). Chunk size is depreciated in securefile, and when specified is considered only as a guidance.
Comparing redo size and log file sync time for nologging option between the basicfile and securefile shows a mix bag of results. Basicfile has performed well for inserts in reducing redo generated and log file sync while securefile performed well for updates.
Comparing the IO types on OEM console during the nologging test it was noted that securefile uses predominantly large writes while the basicfile uses small writes. Comparing the test result with logging enabled the securefile out performance basic file for insert and updates in terms of log file sync wait time. Both securefile and basicfile generates roughly the same amount of redo. It must be noted nocache logging is the default for secure file. The table below shows all the test results.
It seems that when application permits it's best to use nologging for lobs which reduce the amount of redo generated and log file sync waits. However there are some drawbacks to using nologging on LOBs which only comes to light when there are multiple sessions doing LOB related DMLS. Following is an AWR snippet from a load test on pre-production system. After CPU the top wait event is log file sync and high portion of this wait event is due an basicfile LOB related insert statement that store some transient data. Changing the lob segment option to nologging resulted in lower log file sync time but it also introduced high enq: CF - contention wait times. According to 1072417.1 enq: CF - contention is normal and expected when doing DML on LOBs with nocache nologging. CF contention occurs as oracle records the unrecoverable system change number (SCN) in the control file. From the application perspective the overall response time degraded after changing to nologging and had to be reverted back to cache logging.
Useful metalink notes
Performance Degradation as a Result of 'enq: CF - contention' [ID 1072417.1]
LOB Performance Guideline [ID 268476.1]
LOBS - Storage, Redo and Performance Issues [ID 66431.1]
LOBS - Storage, Read-consistency and Rollback [ID 162345.1]
Master Note - RDBMS Large Objects (LOBs) [ID 1268771.1]
Performance problems on a table that has hundreds of columns including LOBs [ID 1292685.1]
POOR PERFORMANCE WITH LOB INSERTS [ID 978045.1]
Securefiles Performance Appears Slower Than Basicfile LOB [ID 1323933.1]
Java Code Used for Testing
This post presents the result of a simple test carried out comparing the nologging vs logging for both basicfile and securefile LOB segments. The java code used for the test is given at the end of the post. First case is the basicfile. Nologging is not possible if the cache is enable on the lob segment. Therefore nocache option is chosen for both logging and nologging. The table definition is given below.
create table ses(sesid varchar2(100), sesob blob) SEGMENT CREATION IMMEDIATE TABLESPACE users
LOB
(
sesob
)
STORE AS object_lob_seg (
TABLESPACE lob32ktbs
DISABLE STORAGE IN ROW
CHUNK 32K
NOCACHE NOLOGGING
--NOCACHE LOGGING
PCTVERSION 0
STORAGE (MAXEXTENTS UNLIMITED)
INDEX object_lob_idx (
TABLESPACE lob32ktbs
STORAGE (MAXEXTENTS UNLIMITED)
)
)
/The test involves inserting an 800KB LOB into the table 100 times and then later updating it with similar size LOB. Since the LOB is greater than 4K, the table is created with disable in row. Chunk size is set to 32k and the lob segment is stored in a tablespace of 32K block size (lob32ktbs) while the table resides in a different (users) tablespace of 8K block size. Pctversion is set to 0 as no consistent reads are expected. Only option that is changed is the logging option. The test database version is 11.2.0.3Redo size statistic and the log file sync wait event times are compared for the two test runs as these are directly related to the logging option. Graphs below show the comparison of these for each test run.
There's no surprise that nologging option generates the lowest amount of redo. The logging test case generated around 83-84MB of redo for insert and update which is roughly the same size as the LOB inserted/updated (800KB x 100). There's minimal logging during the nologging test. Since redo is counted for the entire test, the redo seen could be the redo generated for the table data insert (as oppose to lobs) which still is on a tablespace with logging. Nevertheless a clear difference could be observed in the amount of redo generated when nologging is used. This is also reflected in the log file sync time for the two test cases which got reduced from several minutes to under a minute.
Next the same test was executed but this time the lob segment was stored as securefile. The table DDL is given below. Only difference apart from the securefile is Pctversion 0 has been replaced with retention none. All other settings are same as the basic file (tablespaces, database and etc). Chunk size is depreciated in securefile, and when specified is considered only as a guidance.
create table ses(sesid varchar2(100), sesob blob) SEGMENT CREATION IMMEDIATE TABLESPACE users
LOB
(
sesob
)
STORE AS securefile object_lob_seg (
TABLESPACE lob32ktbs
DISABLE STORAGE IN ROW
CHUNK 32K
NOCACHE NOLOGGING
--NOCACHE LOGGING
RETENTION NONE
STORAGE (MAXEXTENTS UNLIMITED)
INDEX object_lob_idx (
TABLESPACE lob32ktbs
STORAGE (MAXEXTENTS UNLIMITED)
)
)
/Similar to the earlier test the nologging generated low amount of redo compared to logging and resulted in short wait on log file sync event.
Comparing redo size and log file sync time for nologging option between the basicfile and securefile shows a mix bag of results. Basicfile has performed well for inserts in reducing redo generated and log file sync while securefile performed well for updates.
Comparing the IO types on OEM console during the nologging test it was noted that securefile uses predominantly large writes while the basicfile uses small writes. Comparing the test result with logging enabled the securefile out performance basic file for insert and updates in terms of log file sync wait time. Both securefile and basicfile generates roughly the same amount of redo. It must be noted nocache logging is the default for secure file. The table below shows all the test results.
It seems that when application permits it's best to use nologging for lobs which reduce the amount of redo generated and log file sync waits. However there are some drawbacks to using nologging on LOBs which only comes to light when there are multiple sessions doing LOB related DMLS. Following is an AWR snippet from a load test on pre-production system. After CPU the top wait event is log file sync and high portion of this wait event is due an basicfile LOB related insert statement that store some transient data. Changing the lob segment option to nologging resulted in lower log file sync time but it also introduced high enq: CF - contention wait times. According to 1072417.1 enq: CF - contention is normal and expected when doing DML on LOBs with nocache nologging. CF contention occurs as oracle records the unrecoverable system change number (SCN) in the control file. From the application perspective the overall response time degraded after changing to nologging and had to be reverted back to cache logging.
Useful metalink notes
Performance Degradation as a Result of 'enq: CF - contention' [ID 1072417.1]
LOB Performance Guideline [ID 268476.1]
LOBS - Storage, Redo and Performance Issues [ID 66431.1]
LOBS - Storage, Read-consistency and Rollback [ID 162345.1]
Master Note - RDBMS Large Objects (LOBs) [ID 1268771.1]
Performance problems on a table that has hundreds of columns including LOBs [ID 1292685.1]
POOR PERFORMANCE WITH LOB INSERTS [ID 978045.1]
Securefiles Performance Appears Slower Than Basicfile LOB [ID 1323933.1]
Java Code Used for Testing
public class LobLoggingTest {
final String URL = "jdbc:oracle:thin:@192.168.0.66:1521:ent11g2";
final String USERNAME = "asanga";
final String PASSWORD = "asa";
public static void main(String[] args) {
LobLoggingTest test = new LobLoggingTest();
//Insert test
test.insertTest();
System.out.println("\n\n************* end of insert test **************\n\n");
//Update test
test.updateTest();
}
public void insertTest() {
try {
OracleDataSource pool = new OracleDataSource();
pool.setURL(URL);
pool.setUser(USERNAME);
pool.setPassword(PASSWORD);
Connection con = pool.getConnection();
con.setAutoCommit(false);
long t1 = System.currentTimeMillis();
LobStat.displayStats(con);
LobStat.displayWaits(con);
byte[] x = new byte[800 * 1024];
x[1] = 10;
x[798 * 1024] = 20;
for (int i = 0; i < 100; i++) {
OraclePreparedStatement pr = (OraclePreparedStatement) con.prepareStatement("insert into ses values(?,?)");
String sesid = "abcdefghijklmnopqrstuvwxy" + Math.random();
pr.setString(1, sesid);
pr.setBytes(2, x);
pr.execute();
con.commit();
pr.close();
}
long t2 = System.currentTimeMillis();
LobStat.displayStats(con);
LobStat.displayWaits(con);
con.close();
System.out.println("time taken " + (t2 - t1));
} catch (Exception ex) {
ex.printStackTrace();
}
}
public void updateTest() {
try {
OracleDataSource pool = new OracleDataSource();
pool.setURL(URL);
pool.setUser(USERNAME);
pool.setPassword(PASSWORD);
Connection con = pool.getConnection();
con.setAutoCommit(false);
String[] sesids = new String[100];
PreparedStatement pr1 = con.prepareStatement("select sesid from ses");
ResultSet rs1 = pr1.executeQuery();
int i = 0;
while (rs1.next()) {
sesids[i] = rs1.getString(1);
i++;
}
rs1.close();
pr1.close();
con.close();
con = pool.getConnection();
LobStat.displayStats(con);
LobStat.displayWaits(con);
OraclePreparedStatement pr = (OraclePreparedStatement) con.prepareStatement("update ses set SESOB=? where sesid=?");
byte[] xx = new byte[800 * 1024];
xx[1] = 10;
xx[798 * 1024] = 20;
long t1 = System.currentTimeMillis();
for (String x : sesids) {
pr.setBytes(1, xx);
pr.setString(2, x);
pr.execute();
con.commit();
}
long t2 = System.currentTimeMillis();
System.out.println("time taken " + (t2 - t1));
LobStat.displayStats(con);
LobStat.displayWaits(con);
pr.close();
con.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
public class LobStat {
public static void displayStats(Connection con) {
try {
PreparedStatement pr = con.prepareStatement("select name,value from v$mystat,v$statname where v$mystat.statistic#=v$statname.statistic# "
+ " and v$statname.name in ('CPU used when call started',"
+ " 'CPU used by this session','db block gets','db block gets from cache','db block gets from cache (fastpath)',"
+ " 'db block gets direct','consistent gets','consistent gets from cache','consistent gets from cache (fastpath)',"
+ " 'consistent gets - examination','consistent gets direct','physical reads','physical reads direct',"
+ " 'physical read IO requests','physical read bytes','consistent changes','redo size','redo writes',"
+ " 'lob writes','lob writes unaligned','physical writes direct (lob)','physical writes','physical writes direct','physical writes from cache','physical writes direct temporary tablespace'"
+ " ,'physical writes direct temporary tablespace','securefile direct read bytes','securefile direct write bytes','securefile direct read ops'"
+ " ,'securefile direct write ops') order by 1");
ResultSet rs = pr.executeQuery();
while(rs.next()){
System.out.println(rs.getString(1)+" : "+rs.getDouble(2));
}
rs.close();
pr.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
public static void displayWaits(Connection con){
try {
PreparedStatement pr = con.prepareStatement("select event,total_waits,TIME_WAITED_MICRO from V$SESSION_EVENT where sid=SYS_CONTEXT ('USERENV', 'SID') and event in ('log file sync','enq: CF - contention')");
ResultSet rs = pr.executeQuery();
System.out.println("event : total waits : time waited micro");
while(rs.next()){
System.out.println(rs.getString(1)+" : "+rs.getLong(2)+" : "+rs.getLong(3));
}
rs.close();
pr.close();
} catch (SQLException ex) {
ex.printStackTrace();
}
}
}
Labels:
blob,
enq: CF - contention,
lob,
lobsegment,
nologging,
securefile
Monday, August 18, 2014
enq: HW - contention and latch: enqueue hash chains
An application uses serialized java objects to stored in the database to overcome the application server failovers. The java objects are stored as BLOB. Application has been using the same session storing mechanism for number of years (7+ years) and gone through the upgrades of Oracle versions 10.2 -> 11.1 -> 11.2 without any performance regress. During the inception (with a 10.2) high wait times on enq: HW - contention were encountered which was remedied with the use of the event 44951 (refer 740075.1)
However during a test, involving large number of concurrent application sessions (x10 baseline) the test system encountered high enq: HW - contention even though event 44951 has been set with level 1024.
Following actions were tried in order to reducing the number of and time spent on HW - contention event.
1. Large initial extent size for the lob segment.
4. Large chunk size for lob segment and tablespace block size equal to the chunk size. Lob segment was placed in a tablespace with a block size of 32K and chunk size 32K was used for the lob semgment.
Investigating secure file related issues came across the following MOS note (1532311.1) which mentioned high waits on buffer busy waits and enq: TX - contention when there are frequent updates on secure file lobs. Solution for this was to increase the secure file concurrency estimate hidden parameter (_securefiles_concurrency_estimate). However instead of relying on a parameter that depends on the concurrency, the application was modified by replacing the statement sequence of (insert/update) with an (insert/delete/insert).
Running the same test as earlier resulted in high latch: enqueue hash chain waits.
This wait event was as a result of bug 13775960 which results high enqueue hash chains for concurrent inserts on secure files (refer 13775960.8). Luckily there's patch for the bug (13775960 which supersede the patch 13395403) and once applied the enqueue hash chain wait events were resolved.
Even though Oracle documents says that secure file out perform the basic files as in this case the secure file themselves pose some issues of their own which must be tested against.
Useful metalink notes
Bug 13775960 - "enqueue hash chains" latch contention for delete/insert Securefile workload [ID 13775960.8]
Securefiles DMLs cause high 'buffer busy waits' & 'enq: TX - contention' wait events leading to whole database performance degradation [ID 1532311.1]
Bug 2530125 - Hang possible with "enqueue hash chains" latch held during deadlock detection [ID 2530125.8]
Bug 13395403 - "enqueue hash chains" latch contention on Securefile blob DMLs - superseded [ID 13395403.8]
'enq HW - contention' For Busy LOB Segment [ID 740075.1]
How To Analyze the Wait Statistic: 'enq: HW - contention' [ID 419348.1]
However during a test, involving large number of concurrent application sessions (x10 baseline) the test system encountered high enq: HW - contention even though event 44951 has been set with level 1024.
Following actions were tried in order to reducing the number of and time spent on HW - contention event.
1. Large initial extent size for the lob segment.
STORE AS "LOB_SEG"
(
...(INITIAL 5368709120 NEXT 134217728 ...
);2. Large value for next extent, ideally this should be greater than the (average size of the LOB inserted x number of concurrent inserts).STORE AS "LOB_SEG"
(
...INITIAL 5368709120 NEXT 134217728 ...
);3. Tablespace with uniform extent allocation and extent size is greater than the (average size of the LOB inserted x number of concurrent inserts).4. Large chunk size for lob segment and tablespace block size equal to the chunk size. Lob segment was placed in a tablespace with a block size of 32K and chunk size 32K was used for the lob semgment.
STORE AS SECUREFILE "LOB_SEG"
(
TABLESPACE "TBS32K" CHUNK 32768
);However these actions only slightly reduced the HW - contention wait events and the performance was not satisfactory. At this point it was decided to use the secure file for the lob segments as it was considered better in performance compared to basic file. Investigating secure file related issues came across the following MOS note (1532311.1) which mentioned high waits on buffer busy waits and enq: TX - contention when there are frequent updates on secure file lobs. Solution for this was to increase the secure file concurrency estimate hidden parameter (_securefiles_concurrency_estimate). However instead of relying on a parameter that depends on the concurrency, the application was modified by replacing the statement sequence of (insert/update) with an (insert/delete/insert).
Running the same test as earlier resulted in high latch: enqueue hash chain waits.
This wait event was as a result of bug 13775960 which results high enqueue hash chains for concurrent inserts on secure files (refer 13775960.8). Luckily there's patch for the bug (13775960 which supersede the patch 13395403) and once applied the enqueue hash chain wait events were resolved.
Even though Oracle documents says that secure file out perform the basic files as in this case the secure file themselves pose some issues of their own which must be tested against.
Useful metalink notes
Bug 13775960 - "enqueue hash chains" latch contention for delete/insert Securefile workload [ID 13775960.8]
Securefiles DMLs cause high 'buffer busy waits' & 'enq: TX - contention' wait events leading to whole database performance degradation [ID 1532311.1]
Bug 2530125 - Hang possible with "enqueue hash chains" latch held during deadlock detection [ID 2530125.8]
Bug 13395403 - "enqueue hash chains" latch contention on Securefile blob DMLs - superseded [ID 13395403.8]
'enq HW - contention' For Busy LOB Segment [ID 740075.1]
How To Analyze the Wait Statistic: 'enq: HW - contention' [ID 419348.1]
Labels:
blob,
enq: HW - contention,
latch: enqueue hash chains,
lob,
lobsegment
Tuesday, March 18, 2014
Oracle vs Standard JDBC Batching For Updates
Oracle provided two flavors of batching with the JDBC drivers. One was called standard which followed the JBDC 2.0 specification and the other flavor was an Oracle specific implementation (called Oracle Batching) which is independent of JDBC 2.0. It is not possible to mix both these modes in the same application. However with the latest implementation of the JDBC driver (12c) Oracle update batching is depreciated. Evolution of the documentation over the years on this is given below.
From 10.2 JDBC developers guide Oracle update batching is a more efficient model because the driver knows ahead of time how many operations will be batched. In this sense, the Oracle model is more static and predictable. With the standard model, the driver has no way of knowing in advance how many operations will be batched. In this sense, the standard model is more dynamic in nature.
From 11.2 JDBC developers guide Oracle recommends that you use JDBC standard features when possible. This recommendation applies to update batching as well. Oracle update batching is retained primarily for backwards compatibility.
From 12.1 JDBC developers guide Starting from Oracle Database 12c Release 1 (12.1), Oracle update batching is deprecated. Oracle recommends that you use standard JDBC batching instead of Oracle update batching.
As the Oracle mode batching is depreciated the comparison only holds for lower versions of the JDBC drivers. The test related to this post was carried out using 11.2 JDBC driver. The java code used for the test is given at the end of the post. Two tests were carried out. First involving updating number of rows in a table with standard, standard implementation of oracle batching and oracle batching. Standard batching test only execute the update batch once. The standard implementation mimics what the Oracle standard does by executing the update batch at fixed intervals (500 and 1000 updates at a time). Finally Oracle batching will use the values of 500 and 1000 for batch values. This test is to check if there's any considerable difference in the timing of the updates. Result table is given below.
There's not much difference in terms of time it takes to complete all the updates whether it is via standard batching or oracle batching. Scatter plot shown below.
The next test involved updating a column with a blob (size 8KB). The results table is given below.
There's not much difference in the update time between the different standard batching tests.
However there's some advantage when using standard batching compared to oracle standard as the number of updates are 25,000 or over. But the increase number of batching size requires more memory and this situation may be uncommon. For lower values again there's not much difference in terms of time saved.
These tests have shown that batching mode (Oracle or standard) does not have a real influence on the time taken for the updates. As mentioned earlier as of 12c the Oracle standard batching is depreciated and if these results hold true for 12c driver as well then there shouldn't be any performance degradation.
Test java code used
From 10.2 JDBC developers guide Oracle update batching is a more efficient model because the driver knows ahead of time how many operations will be batched. In this sense, the Oracle model is more static and predictable. With the standard model, the driver has no way of knowing in advance how many operations will be batched. In this sense, the standard model is more dynamic in nature.
From 11.2 JDBC developers guide Oracle recommends that you use JDBC standard features when possible. This recommendation applies to update batching as well. Oracle update batching is retained primarily for backwards compatibility.
From 12.1 JDBC developers guide Starting from Oracle Database 12c Release 1 (12.1), Oracle update batching is deprecated. Oracle recommends that you use standard JDBC batching instead of Oracle update batching.
As the Oracle mode batching is depreciated the comparison only holds for lower versions of the JDBC drivers. The test related to this post was carried out using 11.2 JDBC driver. The java code used for the test is given at the end of the post. Two tests were carried out. First involving updating number of rows in a table with standard, standard implementation of oracle batching and oracle batching. Standard batching test only execute the update batch once. The standard implementation mimics what the Oracle standard does by executing the update batch at fixed intervals (500 and 1000 updates at a time). Finally Oracle batching will use the values of 500 and 1000 for batch values. This test is to check if there's any considerable difference in the timing of the updates. Result table is given below.
| # Updates | Standared Batching | Standared Batching - 500 | Standared Batching - 1000 | Oracle Batching - 500 | Oracle Batchnig - 1000 |
| 100 | 0.35 | 0.35 | 0.36 | 0.36 | 0.36 |
| 200 | 0.62 | 0.62 | 0.65 | 0.63 | 0.63 |
| 500 | 1.43 | 1.41 | 1.47 | 1.43 | 1.45 |
| 1000 | 2.76 | 2.73 | 2.88 | 2.81 | 2.81 |
| 2000 | 5.72 | 5.38 | 5.64 | 5.54 | 5.68 |
| 5000 | 13.55 | 13.43 | 13.99 | 13.67 | 13.79 |
| 10000 | 27.82 | 26.58 | 28.05 | 27.31 | 27.58 |
| 25000 | 80.01 | 75.43 | 78.65 | 76.42 | 76.93 |
| 50000 | 165.24 | 158.99 | 164.32 | 159.13 | 159.04 |
| 75000 | 243.25 | 242.92 | 248.73 | 242.17 | 242.79 |
| 100000 | 330.92 | 330.84 | 333.34 | 327.65 | 331.22 |
There's not much difference in terms of time it takes to complete all the updates whether it is via standard batching or oracle batching. Scatter plot shown below.
The next test involved updating a column with a blob (size 8KB). The results table is given below.
| # Updates | Standared Batching | Standared Batching - 500 | Standared Batching - 1000 | Oracle Batching - 500 | Oracle Batchnig - 1000 |
| 100 | 1.47 | 1.53 | 1.50 | 1.68 | 1.76 |
| 200 | 2.79 | 2.96 | 2.91 | 3.14 | 3.19 |
| 500 | 6.88 | 7.37 | 7.14 | 7.68 | 7.87 |
| 1000 | 13.60 | 14.70 | 14.20 | 15.30 | 15.50 |
| 2000 | 27.31 | 29.25 | 30.13 | 30.07 | 30.41 |
| 5000 | 68.30 | 74.10 | 74.89 | 77.23 | 74.82 |
| 10000 | 143.31 | 151.05 | 143.14 | 151.68 | 152.43 |
| 25000 | 348.83 | 351.34 | 365.54 | 384.77 | 394.99 |
| 50000 | 701.67 | 727.28 | 707.79 | 857.79 | 859.15 |
There's not much difference in the update time between the different standard batching tests.
However there's some advantage when using standard batching compared to oracle standard as the number of updates are 25,000 or over. But the increase number of batching size requires more memory and this situation may be uncommon. For lower values again there's not much difference in terms of time saved.
These tests have shown that batching mode (Oracle or standard) does not have a real influence on the time taken for the updates. As mentioned earlier as of 12c the Oracle standard batching is depreciated and if these results hold true for 12c driver as well then there shouldn't be any performance degradation.
Test java code used
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.logging.Level;
import java.util.logging.Logger;
import oracle.jdbc.pool.OracleDataSource;
/**
*
* @author Asanga
*/
public class Update {
public static void main(String[] args) {
try {
OracleDataSource dataSource = new OracleDataSource();
dataSource.setURL("jdbc:oracle:thin:@192.168.0.66:1521:ent11g2");
dataSource.setUser("asanga");
dataSource.setPassword("asa");
// String SQL = "update x set b = ?, c = ? where a = ?"; // update blob
String SQL = "update x set b = ? where a = ?";
Connection con = dataSource.getConnection();
con.setAutoCommit(false);
long t1 = System.nanoTime();
// byte[] lob = new byte[8*1024];
// lob[10] =10;
// lob[8000]=20;
PreparedStatement pr = con.prepareStatement(SQL);
// ((OraclePreparedStatement)pr).setExecuteBatch(1000);
for(int i =1; i <= 75000; i++){
StringBuilder b = new StringBuilder("khf").append(i);
pr.setString(1, b.toString());
// pr.setBytes(2,lob );
pr.setInt(2, i);
pr.addBatch();
if((i > 0) && (i%1000 == 0)){
int[] ret =pr.executeBatch();
System.out.println(ret.length);
}
// pr.executeUpdate();
}
int[] ret = pr.executeBatch();
// ((OraclePreparedStatement)pr).sendBatch();
con.commit();
long t2 = System.nanoTime();
System.out.println("returned "+ret.length+" time : "+(t2-t1));
// System.out.println("time : "+(t2-t1));
pr.close();
con.close();
} catch (SQLException ex) {
Logger.getLogger(Update.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
Tuesday, September 13, 2011
Subscribe to:
Posts (Atom)


















