1
我有以下的Java代碼和平比較這兩個SQL查詢的性能。 getNamedStatistics()
打印v $ session表中的某些列,如一致性獲取,執行計數等。Oracle JDBC刷新共享池不工作
儘管我無法刷新oracle的內存,因此我可以比較這兩個查詢的性能。
clearOracleMemory();
start = System.nanoTime();
System.out.println("Named statistics --> " + getNamedStatistic(statistics, conn));
query1UsingStatement(conn);
System.out.println("Named statistics --> " + getNamedStatistic(statistics, conn));
end = System.nanoTime();
System.out.println("Took: " + ((end - start)/1000000) + "ms");
clearOracleMemory();
start = System.nanoTime();
System.out.println("Named statistics --> " + getNamedStatistic(statistics, conn));
query2UsingStatement(conn);
System.out.println("Named statistics --> " + getNamedStatistic(statistics, conn));
end = System.nanoTime();
System.out.println("Took: " + ((end - start)/1000000) + "ms");
ClearOracleMemory看起來像這樣:
private static void clearOracleMemory() {
try {
PreparedStatement stmt = conn.prepareStatement("alter system flush shared_pool");
ResultSet rs = stmt.executeQuery();
System.out.println("shared pool flushed");
}
catch (SQLException e) {
System.out.println("error clearing shared pool");
System.out.println(e.getMessage());
}
}
輸出示例:
shared pool flushed
Named statistics --> {CPU used by this session=45, consistent gets=5613, parse count (total)=194, parse time elapsed=14, parse time cpu=14, execute count=1544}
Named statistics --> {CPU used by this session=326, consistent gets=936322, parse count (total)=724, parse time elapsed=58, parse time cpu=60, execute count=3651}
Took: 3676ms
shared pool flushed
Named statistics --> {CPU used by this session=344, consistent gets=942088, parse count (total)=851, parse time elapsed=69, parse time cpu=73, execute count=5319}
Named statistics --> {CPU used by this session=2374, consistent gets=1019846, parse count (total)=20975, parse time elapsed=1728, parse time cpu=1732, execute count=26948}
Took: 28038ms
我想你也應該'改變系統沖洗buffer_cache' – Kacper
NOP Didnt什麼不同鍛鍊 – Asdf