2016-11-30 59 views
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 
+0

我想你也應該'改變系統沖洗buffer_cache' – Kacper

+0

NOP Didnt什麼不同鍛鍊 – Asdf

回答

4

究竟是什麼使你認爲共享池不就臉紅?

我懷疑你混淆了共享池和會話統計信息嗎?會話統計數據統計了會話的不同資源的消耗。刷新共享池會影響會話消耗的次數(因爲它會要求解析語句),但顯然這不會重置資源消耗計數器。

我建議您重新看看分配的讀數,這裏詳細列出了這些讀數。

問候

你友好的老師,誰設置你問