【发布时间】:2017-04-14 16:15:22
【问题描述】:
我有下面的java代码比较这两个SQL查询的性能。
getNamedStatistics()打印 v$session 表中的一些列,如一致获取、执行计数等。
虽然我不能刷新 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
【问题讨论】:
-
我觉得你也应该
alter system flush buffer_cache -
没有任何区别
标签: java oracle jdbc oracle11g