mirror of
https://github.com/ebean-orm/ebean.git
synced 2024-04-21 10:51:47 +00:00
AutoTune update - rename and profiling against original query
This commit is contained in:
@@ -106,10 +106,9 @@ public interface EbeanServer {
|
||||
void shutdown(boolean shutdownDataSource, boolean deregisterDriver);
|
||||
|
||||
/**
|
||||
* Return the AdminAutofetch which is used to control and configure the
|
||||
* Autofetch service at runtime.
|
||||
* Return AutoTune which is used to control the AutoTune service at runtime.
|
||||
*/
|
||||
AdminAutofetch getAdminAutofetch();
|
||||
AutoTune getAutoTune();
|
||||
|
||||
/**
|
||||
* Return the name. This is used with {@link Ebean#getServer(String)} to get a
|
||||
|
||||
@@ -130,7 +130,7 @@ public class ServerConfig {
|
||||
/**
|
||||
* Config controlling the autofetch behaviour.
|
||||
*/
|
||||
private AutofetchConfig autofetchConfig = new AutofetchConfig();
|
||||
private AutoTuneConfig autoTuneConfig = new AutoTuneConfig();
|
||||
|
||||
/**
|
||||
* The JSON format used for DateTime types. Default to millis.
|
||||
@@ -1106,15 +1106,15 @@ public class ServerConfig {
|
||||
/**
|
||||
* Return the configuration for the Autofetch feature.
|
||||
*/
|
||||
public AutofetchConfig getAutofetchConfig() {
|
||||
return autofetchConfig;
|
||||
public AutoTuneConfig getAutoTuneConfig() {
|
||||
return autoTuneConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the configuration for the Autofetch feature.
|
||||
*/
|
||||
public void setAutofetchConfig(AutofetchConfig autofetchConfig) {
|
||||
this.autofetchConfig = autofetchConfig;
|
||||
public void setAutoTuneConfig(AutoTuneConfig autoTuneConfig) {
|
||||
this.autoTuneConfig = autoTuneConfig;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2003,7 +2003,7 @@ public class ServerConfig {
|
||||
* This is broken out for the same reason as above - preserve existing behaviour but let it be overridden.
|
||||
*/
|
||||
protected void loadAutofetchSettings(PropertiesWrapper p) {
|
||||
autofetchConfig.loadSettings(p);
|
||||
autoTuneConfig.loadSettings(p);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -2017,8 +2017,8 @@ public class ServerConfig {
|
||||
if (namingConvention != null) {
|
||||
namingConvention.loadFromProperties(p);
|
||||
}
|
||||
if (autofetchConfig == null) {
|
||||
autofetchConfig = new AutofetchConfig();
|
||||
if (autoTuneConfig == null) {
|
||||
autoTuneConfig = new AutoTuneConfig();
|
||||
}
|
||||
loadAutofetchSettings(p);
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package com.avaje.ebeaninternal.server.autofetch;
|
||||
|
||||
import com.avaje.ebean.bean.NodeUsageListener;
|
||||
import com.avaje.ebean.bean.ObjectGraphNode;
|
||||
import com.avaje.ebeaninternal.api.SpiQuery;
|
||||
|
||||
/**
|
||||
* Profiling listener gets call backs for node usage and the associated query executions.
|
||||
@@ -21,5 +22,5 @@ public interface ProfilingListener extends NodeUsageListener {
|
||||
* Return true if this request should be profiled (based on the
|
||||
* profiling ratio and collection count for this origin).
|
||||
*/
|
||||
boolean isProfileRequest(ObjectGraphNode origin);
|
||||
boolean isProfileRequest(ObjectGraphNode origin, SpiQuery<?> query);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@ import javax.xml.bind.annotation.XmlType;
|
||||
* <attribute name="key" use="required" type="{http://www.w3.org/2001/XMLSchema}string" />
|
||||
* <attribute name="beanType" type="{http://www.w3.org/2001/XMLSchema}string" />
|
||||
* <attribute name="detail" type="{http://www.w3.org/2001/XMLSchema}string" />
|
||||
* <attribute name="tuneDetail" type="{http://www.w3.org/2001/XMLSchema}string" />
|
||||
* <attribute name="original" type="{http://www.w3.org/2001/XMLSchema}string" />
|
||||
* </restriction>
|
||||
* </complexContent>
|
||||
* </complexType>
|
||||
@@ -45,8 +45,8 @@ public class Origin {
|
||||
protected String beanType;
|
||||
@XmlAttribute(name = "detail")
|
||||
protected String detail;
|
||||
@XmlAttribute(name = "tuneDetail")
|
||||
protected String tuneDetail;
|
||||
@XmlAttribute(name = "original")
|
||||
protected String original;
|
||||
|
||||
/**
|
||||
* Gets the value of the callStack property.
|
||||
@@ -145,27 +145,27 @@ public class Origin {
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the value of the tuneDetail property.
|
||||
* Gets the value of the original property.
|
||||
*
|
||||
* @return
|
||||
* possible object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public String getTuneDetail() {
|
||||
return tuneDetail;
|
||||
public String getOriginal() {
|
||||
return original;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the value of the tuneDetail property.
|
||||
* Sets the value of the original property.
|
||||
*
|
||||
* @param value
|
||||
* allowed object is
|
||||
* {@link String }
|
||||
*
|
||||
*/
|
||||
public void setTuneDetail(String value) {
|
||||
this.tuneDetail = value;
|
||||
public void setOriginal(String value) {
|
||||
this.original = value;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -3,8 +3,9 @@ package com.avaje.ebeaninternal.server.autofetch.service;
|
||||
import com.avaje.ebean.bean.NodeUsageCollector;
|
||||
import com.avaje.ebean.bean.ObjectGraphNode;
|
||||
import com.avaje.ebean.bean.ObjectGraphOrigin;
|
||||
import com.avaje.ebean.config.AutofetchConfig;
|
||||
import com.avaje.ebean.config.AutoTuneConfig;
|
||||
import com.avaje.ebeaninternal.api.SpiEbeanServer;
|
||||
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;
|
||||
@@ -40,7 +41,7 @@ public class ProfileManager implements ProfilingListener {
|
||||
|
||||
private final SpiEbeanServer server;
|
||||
|
||||
public ProfileManager(AutofetchConfig config, SpiEbeanServer server) {
|
||||
public ProfileManager(AutoTuneConfig config, SpiEbeanServer server) {
|
||||
this.server = server;
|
||||
this.profilingRate = config.getProfilingRate();
|
||||
this.profilingBase = config.getProfilingBase();
|
||||
@@ -48,10 +49,17 @@ public class ProfileManager implements ProfilingListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isProfileRequest(ObjectGraphNode origin) {
|
||||
public boolean isProfileRequest(ObjectGraphNode origin, SpiQuery<?> query) {
|
||||
|
||||
ProfileOrigin profileOrigin = profileMap.get(origin.getOriginQueryPoint().getKey());
|
||||
return profileOrigin == null || profileOrigin.isProfile();
|
||||
if (profileOrigin == null) {
|
||||
profileOrigin = new ProfileOrigin(origin.getOriginQueryPoint(), queryTuningAddVersion, profilingBase, profilingRate);
|
||||
profileOrigin.setOriginalQuery(query.getDetail().toString());
|
||||
profileMap.put(origin.getOriginQueryPoint().getKey(), profileOrigin);
|
||||
return true;
|
||||
} else {
|
||||
return profileOrigin.isProfile();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -38,6 +38,8 @@ public class ProfileOrigin {
|
||||
|
||||
private final AtomicLong profileCount = new AtomicLong();
|
||||
|
||||
private String originalQuery;
|
||||
|
||||
public ProfileOrigin(ObjectGraphOrigin origin, boolean queryTuningAddVersion, int profilingBase, double profilingRate) {
|
||||
this.origin = origin;
|
||||
this.queryTuningAddVersion = queryTuningAddVersion;
|
||||
@@ -45,6 +47,14 @@ public class ProfileOrigin {
|
||||
this.profilingRate = profilingRate;
|
||||
}
|
||||
|
||||
public String getOriginalQuery() {
|
||||
return originalQuery;
|
||||
}
|
||||
|
||||
public void setOriginalQuery(String originalQuery) {
|
||||
this.originalQuery = originalQuery;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this query should be profiled based on a percentage rate.
|
||||
*/
|
||||
@@ -74,7 +84,7 @@ public class ProfileOrigin {
|
||||
}
|
||||
|
||||
OrmQueryDetail detail = buildDetail(rootDesc);
|
||||
AutoTuneCollection.Entry entry = req.add(origin, detail);
|
||||
AutoTuneCollection.Entry entry = req.add(origin, detail, originalQuery);
|
||||
|
||||
Collection<ProfileOriginQuery> values = queryStatsMap.values();
|
||||
for (ProfileOriginQuery queryEntry : values) {
|
||||
|
||||
@@ -81,7 +81,7 @@ public class OrmQueryDetail implements Serializable {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if equal in terms of autofetch (select and joins).
|
||||
* Return true if equal in terms of autoTune (select and fetch).
|
||||
*/
|
||||
public boolean isAutoTuneEqual(OrmQueryDetail otherDetail) {
|
||||
|
||||
@@ -91,6 +91,9 @@ public class OrmQueryDetail implements Serializable {
|
||||
if (fetchPaths == null) {
|
||||
return otherDetail.fetchPaths == null;
|
||||
}
|
||||
if (fetchPaths.size() != otherDetail.fetchPaths.size()) {
|
||||
return false;
|
||||
}
|
||||
Set<Map.Entry<String, OrmQueryProperties>> entries = fetchPaths.entrySet();
|
||||
for (Map.Entry<String, OrmQueryProperties> entry : entries) {
|
||||
OrmQueryProperties chunk = otherDetail.getChunk(entry.getKey(), false);
|
||||
@@ -100,7 +103,6 @@ public class OrmQueryDetail implements Serializable {
|
||||
}
|
||||
|
||||
return true;
|
||||
//return autofetchPlanHash() == otherDetail.autofetchPlanHash();
|
||||
}
|
||||
|
||||
private boolean isSame(OrmQueryProperties p1, OrmQueryProperties p2) {
|
||||
@@ -110,22 +112,6 @@ public class OrmQueryDetail implements Serializable {
|
||||
return p1.isSame(p2);
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Calculate the hash for the query plan.
|
||||
// */
|
||||
// private int autofetchPlanHash() {
|
||||
//
|
||||
// int hc = (baseProps == null ? 1 : baseProps.autofetchPlanHash());
|
||||
//
|
||||
// if (fetchPaths != null) {
|
||||
// for (OrmQueryProperties p : fetchPaths.values()) {
|
||||
// hc = hc * 31 + p.autofetchPlanHash();
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return hc;
|
||||
// }
|
||||
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
if (baseProps != null) {
|
||||
@@ -236,7 +222,7 @@ public class OrmQueryDetail implements Serializable {
|
||||
boolean tuned = false;
|
||||
|
||||
OrmQueryProperties tunedRoot = tunedDetail.getChunk(null, false);
|
||||
if (tunedRoot != null && tunedRoot.hasProperties()) {
|
||||
if (tunedRoot != null) {
|
||||
tuned = true;
|
||||
baseProps.setTunedProperties(tunedRoot);
|
||||
|
||||
|
||||
@@ -215,9 +215,13 @@ public class OrmQueryProperties implements Serializable {
|
||||
* Set the properties from a matching autofetch tuned properties.
|
||||
*/
|
||||
public void setTunedProperties(OrmQueryProperties tunedProperties) {
|
||||
this.properties = tunedProperties.properties;
|
||||
this.trimmedProperties = tunedProperties.trimmedProperties;
|
||||
this.included = tunedProperties.included;
|
||||
if (tunedProperties.hasProperties()) {
|
||||
this.properties = tunedProperties.properties;
|
||||
this.trimmedProperties = tunedProperties.trimmedProperties;
|
||||
this.included = tunedProperties.included;
|
||||
this.queryFetchBatch = Math.max(queryFetchBatch, tunedProperties.queryFetchBatch);
|
||||
this.lazyFetchBatch = Math.max(lazyFetchBatch, tunedProperties.lazyFetchBatch);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -262,6 +266,7 @@ public class OrmQueryProperties implements Serializable {
|
||||
copy.parentPath = parentPath;
|
||||
copy.path = path;
|
||||
copy.properties = properties;
|
||||
copy.trimmedProperties = trimmedProperties;
|
||||
copy.cache = cache;
|
||||
copy.readOnly = readOnly;
|
||||
copy.queryFetchAll = queryFetchAll;
|
||||
|
||||
Reference in New Issue
Block a user