AutoTune update - clean up for query ignore

This commit is contained in:
Robin Bygrave
2015-09-10 22:36:12 +12:00
parent 262d52ed44
commit 9632279c2f
3 changed files with 55 additions and 24 deletions
@@ -20,7 +20,7 @@ public class BaseQueryTuner {
private final boolean queryTuning;
private boolean profiling;
private final boolean profiling;
private final AutoTuneMode mode;
@@ -29,12 +29,14 @@ public class BaseQueryTuner {
*/
private final Map<String, TunedQueryInfo> tunedQueryInfoMap = new ConcurrentHashMap<String, TunedQueryInfo>();
private final SpiEbeanServer server;
private final ProfilingListener profilingListener;
boolean fullProfiling = true;
/**
* Flag set true when there is no profiling or query tuning.
*/
private final boolean skipAll;
public BaseQueryTuner(AutoTuneConfig config, SpiEbeanServer server, ProfilingListener profilingListener) {
this.server = server;
@@ -42,6 +44,7 @@ public class BaseQueryTuner {
this.mode = config.getMode();
this.queryTuning = config.isQueryTuning();
this.profiling = config.isProfiling();
this.skipAll = !queryTuning && !profiling;
}
/**
@@ -65,15 +68,13 @@ public class BaseQueryTuner {
*/
public boolean tuneQuery(SpiQuery<?> query) {
if (!queryTuning && !profiling) {
if (skipAll || !tunableQuery(query)) {
return false;
}
if (!useAutoTune(query)) {
// not tuning this query but maybe profiling
if (fullProfiling) {
CallStack stack = server.createCallStack();
profiling(query, stack);
if (!useTuning(query)) {
if (profiling) {
profiling(query, server.createCallStack());
}
return false;
}
@@ -104,6 +105,31 @@ public class BaseQueryTuner {
return false;
}
/**
* Return false for row count, find ids, subQuery, delete and Versions queries.
* <p>
* These queries are not applicable for autoTune in that they don't have a select/fetch (fetch group).
* </p>
* <p>
* We also exclude queries that are explicitly set to load the L2 bean cache as we want full beans
* in that case.
* </p>
*/
private boolean tunableQuery(SpiQuery<?> query) {
SpiQuery.Type type = query.getType();
switch (type) {
case ROWCOUNT:
case ID_LIST:
case DELETE:
case SUBQUERY:
return false;
default:
// not using autoTune when explicitly loading the l2 bean cache
// or when using Versions query
return !query.isLoadBeanCache() && SpiQuery.TemporalMode.VERSIONS != query.getTemporalMode();
}
}
private void profiling(SpiQuery<?> query, CallStack stack) {
// create a query point to identify the query
@@ -117,13 +143,7 @@ public class BaseQueryTuner {
/**
* Return true if we should try to tune this query.
*/
private boolean useAutoTune(SpiQuery<?> query) {
if (query.isLoadBeanCache()) {
// when loading the cache don't tune the query
// as we want full objects loaded into the cache
return false;
}
private boolean useTuning(SpiQuery<?> query) {
Boolean autoFetch = query.isAutofetch();
if (autoFetch != null) {
@@ -9,19 +9,15 @@ import com.avaje.ebeaninternal.api.SpiQuery;
import com.avaje.ebeaninternal.server.autofetch.AutoTuneCollection;
import com.avaje.ebeaninternal.server.autofetch.ProfilingListener;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
/**
*
* Manages the collection of object graph usage profiling.
*/
public class ProfileManager implements ProfilingListener {
private static final Logger logger = LoggerFactory.getLogger(ProfileManager.class);
private final boolean queryTuningAddVersion;
/**
@@ -53,15 +49,27 @@ public class ProfileManager implements ProfilingListener {
ProfileOrigin profileOrigin = profileMap.get(origin.getOriginQueryPoint().getKey());
if (profileOrigin == null) {
profileOrigin = new ProfileOrigin(origin.getOriginQueryPoint(), queryTuningAddVersion, profilingBase, profilingRate);
profileOrigin.setOriginalQuery(query.getDetail().toString());
profileMap.put(origin.getOriginQueryPoint().getKey(), profileOrigin);
profileMap.put(origin.getOriginQueryPoint().getKey(), createProfileOrigin(origin, query));
return true;
} else {
return profileOrigin.isProfile();
}
}
/**
* Create the profile origin noting the query detail currently being used.
* <p>
* For new profiling entries it is useful to compare the profiling against the current
* query detail that is specified in the code (as the query might already be manually optimised).
* </p>
*/
private ProfileOrigin createProfileOrigin(ObjectGraphNode origin, SpiQuery<?> query) {
ProfileOrigin profileOrigin = new ProfileOrigin(origin.getOriginQueryPoint(), queryTuningAddVersion, profilingBase, profilingRate);
// set the current query detail (fetch group) so that we can compare against profiling for new entries
profileOrigin.setOriginalQuery(query.getDetail().toString());
return profileOrigin;
}
/**
* Gather query execution statistics. This could either be the originating
* query in which case the parentNode will be null, or a lazy loading query