Differentiate between explicit queries and decomposed queries.

This commit is contained in:
Michael Bayne
2008-11-25 22:02:15 +00:00
parent 8ab95ec10e
commit 14a85d0de6
4 changed files with 19 additions and 14 deletions
+10 -4
View File
@@ -47,6 +47,9 @@ public class Stats
/** The total number of collection queries that were loaded from the database. */ /** The total number of collection queries that were loaded from the database. */
public final int uncachedQueries; public final int uncachedQueries;
/** The total number of one-phase collection queries that executed. */
public final int explicitQueries;
/** The number of record loads (individual or as part of a collection query) that were /** The number of record loads (individual or as part of a collection query) that were
* loaded from the cache. */ * loaded from the cache. */
public final long cachedRecords; public final long cachedRecords;
@@ -69,7 +72,7 @@ public class Stats
/** Creates a stats instance. */ /** Creates a stats instance. */
protected Snapshot (int totalOps, long connectionWaitTime, protected Snapshot (int totalOps, long connectionWaitTime,
int cachedQueries, int uncachedQueries, int cachedQueries, int uncachedQueries, int explicitQueries,
int cachedRecords, int uncachedRecords, int cachedRecords, int uncachedRecords,
Histogram queryHisto, long queryTime, Histogram queryHisto, long queryTime,
Histogram modifierHisto, long modifierTime) Histogram modifierHisto, long modifierTime)
@@ -78,6 +81,7 @@ public class Stats
this.connectionWaitTime = connectionWaitTime; this.connectionWaitTime = connectionWaitTime;
this.cachedQueries = cachedQueries; this.cachedQueries = cachedQueries;
this.uncachedQueries = uncachedQueries; this.uncachedQueries = uncachedQueries;
this.explicitQueries = explicitQueries;
this.cachedRecords = cachedRecords; this.cachedRecords = cachedRecords;
this.uncachedRecords = uncachedRecords; this.uncachedRecords = uncachedRecords;
this.queryHisto = queryHisto; this.queryHisto = queryHisto;
@@ -90,7 +94,8 @@ public class Stats
public synchronized Snapshot getSnapshot () public synchronized Snapshot getSnapshot ()
{ {
return new Snapshot(_totalOps, _connectionWaitTime, return new Snapshot(_totalOps, _connectionWaitTime,
_cachedQueries, _uncachedQueries, _cachedRecords, _uncachedRecords, _cachedQueries, _uncachedQueries, _explicitQueries,
_cachedRecords, _uncachedRecords,
_readHisto.clone(), _readTime, _writeHisto.clone(), _writeTime); _readHisto.clone(), _readTime, _writeHisto.clone(), _writeTime);
} }
@@ -115,11 +120,12 @@ public class Stats
} }
} }
public synchronized void noteQuery (int cachedQueries, int uncachedQueries, public synchronized void noteQuery (int cachedQueries, int uncachedQueries, int explicitQueries,
int cachedRecords, int uncachedRecords) int cachedRecords, int uncachedRecords)
{ {
_cachedQueries += cachedQueries; _cachedQueries += cachedQueries;
_uncachedQueries += uncachedQueries; _uncachedQueries += uncachedQueries;
_explicitQueries += explicitQueries;
_cachedRecords += cachedRecords; _cachedRecords += cachedRecords;
_uncachedRecords += uncachedRecords; _uncachedRecords += uncachedRecords;
} }
@@ -133,6 +139,6 @@ public class Stats
protected Histogram _writeHisto = new Histogram(0, 500, 20); protected Histogram _writeHisto = new Histogram(0, 500, 20);
protected long _writeTime; protected long _writeTime;
protected int _cachedQueries, _uncachedQueries; protected int _cachedQueries, _uncachedQueries, _explicitQueries;
protected int _cachedRecords, _uncachedRecords; protected int _cachedRecords, _uncachedRecords;
} }
@@ -95,7 +95,7 @@ public class FindAllKeysQuery<T extends PersistentRecord> extends Query<List<Key
// from Query // from Query
public void updateStats (Stats stats) public void updateStats (Stats stats)
{ {
stats.noteQuery(0, 1, 0, 0); // one uncached query stats.noteQuery(0, 1, 0, 0, 0); // one uncached query
} }
protected boolean _forUpdate; protected boolean _forUpdate;
@@ -215,18 +215,15 @@ public abstract class FindAllQuery<T extends PersistentRecord> extends Query<Lis
ResultSet rs = stmt.executeQuery(); ResultSet rs = stmt.executeQuery();
while (rs.next()) { while (rs.next()) {
result.add(_marsh.createObject(rs)); result.add(_marsh.createObject(rs));
_uncachedRecords++;
} }
} finally { } finally {
JDBCUtil.close(stmt); JDBCUtil.close(stmt);
} }
_uncachedQueries++; _explicitQueries++;
if (PersistenceContext.CACHE_DEBUG) { if (PersistenceContext.CACHE_DEBUG) {
log.info("Loaded " + _marsh.getTableName(), "query", _select, log.info("Loaded " + _marsh.getTableName(), "query", _select, "rows", result.size());
"uncached", _uncachedRecords);
} }
// TODO: do we want to cache these results? return result; // TODO: do we want to cache these results?
return result;
} }
protected SelectClause<T> _select; protected SelectClause<T> _select;
@@ -235,7 +232,8 @@ public abstract class FindAllQuery<T extends PersistentRecord> extends Query<Lis
// from Query // from Query
public void updateStats (Stats stats) public void updateStats (Stats stats)
{ {
stats.noteQuery(_cachedQueries, _uncachedQueries, _cachedRecords, _uncachedRecords); stats.noteQuery(_cachedQueries, _uncachedQueries, _explicitQueries,
_cachedRecords, _uncachedRecords);
} }
protected FindAllQuery (PersistenceContext ctx, Class<T> type) protected FindAllQuery (PersistenceContext ctx, Class<T> type)
@@ -365,5 +363,6 @@ public abstract class FindAllQuery<T extends PersistentRecord> extends Query<Lis
protected Class<T> _type; protected Class<T> _type;
protected DepotMarshaller<T> _marsh; protected DepotMarshaller<T> _marsh;
protected int _cachedQueries, _uncachedQueries, _cachedRecords, _uncachedRecords; protected int _cachedQueries, _uncachedQueries, _explicitQueries;
protected int _cachedRecords, _uncachedRecords;
} }
@@ -118,7 +118,7 @@ public class FindOneQuery<T extends PersistentRecord> extends Query<T>
// from Operation // from Operation
public void updateStats (Stats stats) public void updateStats (Stats stats)
{ {
stats.noteQuery(0, 0, _cachedRecords, 1-_cachedRecords); stats.noteQuery(0, 0, 0, _cachedRecords, 1-_cachedRecords);
} }
protected CacheKey getCacheKey () protected CacheKey getCacheKey ()