AutoTune update - remove resources

This commit is contained in:
Robin Bygrave
2015-09-09 15:21:10 +12:00
parent 5b8ce8eaa0
commit 116cc3a3fe
15 changed files with 28 additions and 537 deletions
@@ -7,19 +7,15 @@ public class AutofetchConfig {
private AutofetchMode mode = AutofetchMode.DEFAULT_ONIFEMPTY;
private boolean queryTuning = false;
private boolean queryTuning;
private boolean queryTuningAddVersion = false;
private boolean queryTuningAddVersion;
private boolean profiling = false;
private boolean profiling;
private int profilingMin = 1;
private int profilingBase = 5;
private int profilingBase = 10;
private double profilingRate = 0.05;
private String logDirectory;
private double profilingRate = 0.01;
private int profileUpdateFrequency = 60;
@@ -101,22 +97,6 @@ public class AutofetchConfig {
this.profiling = profiling;
}
/**
* Return the minimum number of queries to profile before autofetch will start
* tuning the queries.
*/
public int getProfilingMin() {
return profilingMin;
}
/**
* Set the minimum number of queries to profile before autofetch will start
* tuning the queries.
*/
public void setProfilingMin(int profilingMin) {
this.profilingMin = profilingMin;
}
/**
* Return the base number of queries to profile before changing to profile
* only a percentage of following queries (profileRate).
@@ -148,20 +128,6 @@ public class AutofetchConfig {
this.profilingRate = profilingRate;
}
/**
* Return the log directory to put the autofetch log.
*/
public String getLogDirectory() {
return logDirectory;
}
/**
* Set the directory to put the autofetch log in.
*/
public void setLogDirectory(String logDirectory) {
this.logDirectory = logDirectory;
}
/**
* Return the frequency in seconds to update the autofetch tuned queries from
* the profiled information.
@@ -228,18 +194,16 @@ public class AutofetchConfig {
*/
public void loadSettings(PropertiesWrapper p) {
logDirectory = p.get("autofetch.logDirectory", logDirectory);
queryTuning = p.getBoolean("autofetch.querytuning", queryTuning);
queryTuningAddVersion = p.getBoolean("autofetch.queryTuningAddVersion", queryTuningAddVersion);
garbageCollectionOnShutdown = p.getBoolean("autofetch.garbageCollectionOnShutdown", garbageCollectionOnShutdown);
queryTuning = p.getBoolean("autotune.querytuning", queryTuning);
queryTuningAddVersion = p.getBoolean("autotune.queryTuningAddVersion", queryTuningAddVersion);
garbageCollectionOnShutdown = p.getBoolean("autotune.garbageCollectionOnShutdown", garbageCollectionOnShutdown);
profiling = p.getBoolean("autofetch.profiling", profiling);
mode = p.getEnum(AutofetchMode.class, "autofetch.implicitmode", mode);
profiling = p.getBoolean("autotune.profiling", profiling);
mode = p.getEnum(AutofetchMode.class, "autotune.implicitmode", mode);
profilingMin = p.getInt("autofetch.profiling.min", profilingMin);
profilingBase = p.getInt("autofetch.profiling.base", profilingBase);
profilingBase = p.getInt("autotune.profiling.base", profilingBase);
profilingRate = p.getDouble("autofetch.profiling.rate", profilingRate);
profileUpdateFrequency = p.getInt("autofetch.profiling.updatefrequency", profileUpdateFrequency);
profilingRate = p.getDouble("autotune.profiling.rate", profilingRate);
profileUpdateFrequency = p.getInt("autotune.profiling.updatefrequency", profileUpdateFrequency);
}
}
@@ -8,7 +8,7 @@ public class AutoTuneServiceFactory {
public static AutoTuneService create(SpiEbeanServer server, ServerConfig serverConfig) {
return new BaseAutoTuneService(server, serverConfig);
return new DefaultAutoTuneService(server, serverConfig);
}
}
@@ -23,9 +23,9 @@ import java.util.List;
/**
* Implementation of the AutoTuneService which is comprised of profiling and query tuning.
*/
public class BaseAutoTuneService implements AutoTuneService {
public class DefaultAutoTuneService implements AutoTuneService {
private static final Logger logger = LoggerFactory.getLogger(BaseAutoTuneService.class);
private static final Logger logger = LoggerFactory.getLogger(DefaultAutoTuneService.class);
private final long defaultGarbageCollectionWait;
@@ -35,7 +35,7 @@ public class BaseAutoTuneService implements AutoTuneService {
private final ProfileManager profileManager;
public BaseAutoTuneService(SpiEbeanServer server, ServerConfig serverConfig) {
public DefaultAutoTuneService(SpiEbeanServer server, ServerConfig serverConfig) {
AutofetchConfig config = serverConfig.getAutofetchConfig();
@@ -15,9 +15,9 @@ import com.avaje.ebeaninternal.api.SpiBackgroundExecutor;
import com.avaje.ebeaninternal.api.SpiEbeanServer;
import com.avaje.ebeaninternal.server.autofetch.AutoTuneService;
import com.avaje.ebeaninternal.server.autofetch.service.AutoTuneServiceFactory;
import com.avaje.ebeaninternal.server.changelog.DefaultChangeLogListener;
import com.avaje.ebeaninternal.server.changelog.DefaultChangeLogPrepare;
import com.avaje.ebeaninternal.server.changelog.DefaultChangeLogRegister;
import com.avaje.ebeaninternal.server.changelog.DefaultChangeLogListener;
import com.avaje.ebeaninternal.server.cluster.ClusterManager;
import com.avaje.ebeaninternal.server.deploy.BeanDescriptorManager;
import com.avaje.ebeaninternal.server.deploy.DeployOrmXml;
@@ -32,8 +32,6 @@ import com.avaje.ebeaninternal.server.persist.DefaultPersister;
import com.avaje.ebeaninternal.server.query.CQueryEngine;
import com.avaje.ebeaninternal.server.query.DefaultOrmQueryEngine;
import com.avaje.ebeaninternal.server.query.DefaultRelationalQueryEngine;
import com.avaje.ebeaninternal.server.resource.ResourceManager;
import com.avaje.ebeaninternal.server.resource.ResourceManagerFactory;
import com.avaje.ebeaninternal.server.text.json.DJsonContext;
import com.avaje.ebeaninternal.server.transaction.AutoCommitTransactionManager;
import com.avaje.ebeaninternal.server.transaction.DefaultTransactionScopeManager;
@@ -68,8 +66,6 @@ public class InternalConfiguration {
private final DeployInherit deployInherit;
private final ResourceManager resourceManager;
private final DeployOrmXml deployOrmXml;
private final TypeManager typeManager;
@@ -120,8 +116,7 @@ public class InternalConfiguration {
this.typeManager = new DefaultTypeManager(serverConfig, bootupClasses);
this.resourceManager = ResourceManagerFactory.createResourceManager(serverConfig);
this.deployOrmXml = new DeployOrmXml(resourceManager.getResourceSource());
this.deployOrmXml = new DeployOrmXml();
this.deployInherit = new DeployInherit(bootupClasses);
this.deployCreateProperties = new DeployCreateProperties(typeManager);
@@ -288,10 +283,6 @@ public class InternalConfiguration {
return deployInherit;
}
public ResourceManager getResourceManager() {
return resourceManager;
}
public DeployOrmXml getDeployOrmXml() {
return deployOrmXml;
}
@@ -1,18 +1,16 @@
package com.avaje.ebeaninternal.server.deploy;
import com.avaje.ebeaninternal.server.lib.util.Dnode;
import com.avaje.ebeaninternal.server.lib.util.DnodeReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import com.avaje.ebeaninternal.server.lib.resource.ResourceContent;
import com.avaje.ebeaninternal.server.lib.resource.ResourceSource;
import com.avaje.ebeaninternal.server.lib.util.Dnode;
import com.avaje.ebeaninternal.server.lib.util.DnodeReader;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
* Controls the creation and caching of BeanManager's, BeanDescriptors,
* BeanTable etc for both beans and tables(MapBeans).
@@ -27,15 +25,10 @@ public class DeployOrmXml {
private final HashMap<String, DNativeQuery> nativeQueryCache;
private final ArrayList<Dnode> ormXmlList;
private final ResourceSource resSource;
public DeployOrmXml(ResourceSource resSource) {
this.resSource = resSource;
public DeployOrmXml() {
this.nativeQueryCache = new HashMap<String, DNativeQuery>();
this.ormXmlList = findAllOrmXml();
initialiseNativeQueries();
}
@@ -106,17 +99,7 @@ public class DeployOrmXml {
private void readOrmXml(String ormXmlName, ArrayList<Dnode> ormXmlList) {
try {
Dnode ormXml;
ResourceContent content = resSource.getContent(ormXmlName);
if (content != null) {
// servlet resource or file system...
ormXml = readOrmXml(content.getInputStream());
} else {
// try the classpath...
ormXml = readOrmXmlFromClasspath(ormXmlName);
}
Dnode ormXml = readOrmXmlFromClasspath(ormXmlName);
if (ormXml != null) {
ormXml.setAttribute("ebean.filename", ormXmlName);
ormXmlList.add(ormXml);
@@ -1,108 +0,0 @@
package com.avaje.ebeaninternal.server.lib.resource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
/**
* Helper object used to find directories typically from the current working
* directory.
*/
public class DirectoryFinder {
private static final Logger logger = LoggerFactory.getLogger(DirectoryFinder.class);
/**
* Find a directory by search through subdirectories.
* <p>
* For example, used to find the WEB-INF directory starting from the current
* working directory.
* </p>
*
* <pre class="code">
*
* // search to a depth of 3 from the current working directory
* // looking for a directory WEB-INF that contains the subdirectory
* // data
*
* File dir = DirectoryFinder.find(null, &quot;WEB-INF/data&quot;, 3);
* if (dir != null) {
* //found the directory
* }
* </pre>
*/
public static File find(File startDir, String match, int maxDepth) {
String matchSub = null;
int slashPos = match.indexOf('/');
if (slashPos > -1) {
// match has sub directories
matchSub = match.substring(slashPos + 1);
match = match.substring(0, slashPos);
}
// search for the directory
File found = find(startDir, match, matchSub, 0, maxDepth);
if (found != null && matchSub != null) {
// match has sub directories
return new File(found, matchSub);
}
return found;
}
private static File find(File dir, String match, String matchSub, int depth, int maxDepth) {
if (dir == null) {
String curDir = System.getProperty("user.dir");
dir = new File(curDir);
}
if (dir.exists()) {
File[] list = dir.listFiles();
if (list != null){
for (int i = 0; i < list.length; i++) {
if (isMatch(list[i], match, matchSub)) {
return list[i];
}
}
// go through the directories again
// Aka *NOT* a depth first search
if (depth < maxDepth) {
for (int i = 0; i < list.length; i++) {
if (list[i].isDirectory()) {
File found = find(list[i], match, matchSub, depth + 1, maxDepth);
if (found != null) {
return found;
}
}
}
}
}
}
return null;
}
private static boolean isMatch(File f, String match, String matchSub) {
if (f == null) {
return false;
}
if (!f.isDirectory()) {
return false;
}
if (!f.getName().equalsIgnoreCase(match)) {
return false;
}
if (matchSub == null) {
return true;
}
File sub = new File(f, matchSub);
if (logger.isTraceEnabled()){
logger.trace("search; " + f.getPath());
}
return sub.exists();
}
}
@@ -1,70 +0,0 @@
package com.avaje.ebeaninternal.server.lib.resource;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
/**
* Content from a file system file.
*/
public class FileResourceContent implements ResourceContent {
/**
* The underlying file.
*/
final File file;
final String entryName;
/**
* Create with a File and the entryName.
*/
public FileResourceContent(File file, String entryName) {
this.file = file;
this.entryName = entryName;
}
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("[").append(getName());
sb.append("] size[").append(size());
sb.append("] lastModified[").append(new Date(lastModified()));
sb.append("]");
return sb.toString();
}
/**
* Returns the entry name which contains the path from the base directory.
* <p>
* This does not return the full path of the file, but the path relative to
* the FileIoSource directory.
* </p>
*/
public String getName() {
return entryName;
}
/**
* Return the time the file was last modified.
*/
public long lastModified() {
return file.lastModified();
}
/**
* Return the size of the file.
*/
public long size() {
return file.length();
}
/**
* Return the input stream for this file.
*/
public InputStream getInputStream() throws IOException {
return new FileInputStream(file);
}
}
@@ -1,50 +0,0 @@
package com.avaje.ebeaninternal.server.lib.resource;
import java.io.File;
/**
* A file system directory represented as a FileSource.
*/
public class FileResourceSource implements ResourceSource {
/**
* The directory name.
*/
final String directory;
final String baseDir;
/**
* Create the source based on a directory name.
*/
public FileResourceSource(String directory) {
this.directory = directory;
this.baseDir = directory + File.separator;
}
/**
* Create the source based on a directory file.
*/
public FileResourceSource(File dir) {
this(dir.getPath());
}
public String getRealPath() {
return directory;
}
/**
* Search for the given file and return as IoContent.
*/
public ResourceContent getContent(String entry) {
String fullPath = baseDir + entry;
File f = new File(fullPath);
if (f.exists()) {
return new FileResourceContent(f, entry);
}
return null;
}
}
@@ -1,34 +0,0 @@
package com.avaje.ebeaninternal.server.lib.resource;
import java.io.IOException;
import java.io.InputStream;
/**
* Represents content that can be read via the ResourceManager.
* <p>
* Typically either content from a File or a URL.
* </p>
*/
public interface ResourceContent {
/**
* The name of the content.
*/
String getName();
/**
* The size of the content in bytes.
*/
long size();
/**
* The last modified timestamp of the content.
*/
long lastModified();
/**
* The content itself.
*/
InputStream getInputStream() throws IOException;
}
@@ -1,26 +0,0 @@
package com.avaje.ebeaninternal.server.lib.resource;
/**
* A Source for ResourceManager.
* <p>
* Typically a File System Directory based source or a ServletContext URL
* resource based source (for Servlet WAR files).
* </p>
*/
public interface ResourceSource {
/**
* Return the File System path of the root of the ResourceSource.
* <p>
* This will return null IF the ResourceSource is an unpacked WAR file.
* </p>
*/
String getRealPath();
/**
* Find the content with a given entry name. This will return null if no
* matching content was found.
*/
ResourceContent getContent(String entry);
}
@@ -1,13 +0,0 @@
<html>
<head>
<meta http-equiv="CONTENT-TYPE" content="text/html; charset=iso-8859-1">
<title>AvajeLib</title>
</head>
<body BGCOLOR="#ffffff">
Service for reading content from either the file system or servlet context.
<p>
A service used to read deployment content such as xml files, images etc
taking into account the environment (servlet war file or file system).
</p>
</body>
</html>
@@ -1,29 +0,0 @@
package com.avaje.ebeaninternal.server.resource;
import java.io.File;
import com.avaje.ebeaninternal.server.lib.resource.ResourceSource;
/**
* The ResourceManager implementation.
*/
public class ResourceManager {
final ResourceSource resourceSource;
final File autofetchDir;
public ResourceManager(ResourceSource resourceSource, File autofetchDir) {
this.resourceSource = resourceSource;
this.autofetchDir = autofetchDir;
}
public ResourceSource getResourceSource() {
return resourceSource;
}
public File getAutofetchDirectory() {
return autofetchDir;
}
}
@@ -1,107 +0,0 @@
package com.avaje.ebeaninternal.server.resource;
import com.avaje.ebean.config.ServerConfig;
import com.avaje.ebeaninternal.server.lib.resource.DirectoryFinder;
import com.avaje.ebeaninternal.server.lib.resource.FileResourceSource;
import com.avaje.ebeaninternal.server.lib.resource.ResourceSource;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File;
/**
* Creates a ResourceManager for a server depending on the avaje.properties.
* <p>
* This can use URL based resource loading for web applications or file based
* otherwise.
* </p>
*/
public class ResourceManagerFactory {
private static final Logger logger = LoggerFactory.getLogger(ResourceManagerFactory.class);
/**
* Construct with the properties for a server.
*/
public ResourceManagerFactory() {
}
/**
* Create the resource manager given the properties for this server.
*/
public static ResourceManager createResourceManager(ServerConfig serverConfig) {
ResourceSource resourceSource = createResourceSource(serverConfig);
File autofetchDir = getAutofetchDir(serverConfig, resourceSource);
return new ResourceManager(resourceSource, autofetchDir);
}
/**
* Return the directory that autofetch file goes into.
*/
protected static File getAutofetchDir(ServerConfig serverConfig, ResourceSource resourceSource) {
String dir = null;
if (serverConfig.getAutofetchConfig() != null) {
dir = serverConfig.getAutofetchConfig().getLogDirectory();
}
if (dir != null) {
return new File(dir);
}
String realPath = resourceSource.getRealPath();
if (realPath != null) {
return new File(realPath);
} else {
throw new RuntimeException("No autofetch directory set?");
}
}
/**
* Return the resource loader for external sql files.
* <p>
* This can be url based (for webapps) or otherwise file based.
* </p>
*/
protected static ResourceSource createResourceSource(ServerConfig serverConfig) {
// default for web application, override this for file system
String defaultDir = serverConfig.getResourceDirectory();
// use File System directory
return createFileSource(defaultDir);
}
private static ResourceSource createFileSource(String fileDir) {
if (fileDir != null) {
// explicitly stated so
File dir = new File(fileDir);
if (dir.exists()) {
logger.info("ResourceManager initialised: type[file] [" + fileDir + "]");
return new FileResourceSource(fileDir);
} else {
String msg = "ResourceManager could not find directory [" + fileDir + "]";
throw new IllegalArgumentException(msg);
}
}
// try to guess the directory starting from the current working
// directory, and searching to a maximum depth of 3 subdirectories
File guessDir = DirectoryFinder.find(null, "WEB-INF", 3);
if (guessDir != null) {
// Typically this means we found the WEB-INF directory below the
// current working directory
logger.info("ResourceManager initialised: type[file] [" + guessDir.getPath() + "]");
return new FileResourceSource(guessDir.getPath());
}
// default to the current working directory
File workingDir = new File(".");
return new FileResourceSource(workingDir);
}
}
@@ -1,10 +0,0 @@
<HTML>
<HEAD>
<META HTTP-EQUIV="CONTENT-TYPE" CONTENT="text/html; charset=iso-8859-1">
<TITLE>Resource Management</TITLE>
</HEAD>
<Body BGCOLOR="#ffffff">
Resource Management
</Body>
</HTML>