001package io.ebean.config; 002 003/** 004 * Defines the AutoTune behaviour for a Database. 005 */ 006public class AutoTuneConfig { 007 008 private AutoTuneMode mode = AutoTuneMode.DEFAULT_OFF; 009 010 private String queryTuningFile = "ebean-autotune.xml"; 011 012 private boolean queryTuning; 013 014 private boolean queryTuningAddVersion; 015 016 private boolean profiling; 017 018 private String profilingFile = "ebean-profiling"; 019 020 private int profilingBase = 5; 021 022 private double profilingRate = 0.01; 023 024 private int profilingUpdateFrequency; 025 026 private int garbageCollectionWait = 100; 027 028 private boolean skipGarbageCollectionOnShutdown; 029 030 private boolean skipProfileReportingOnShutdown; 031 032 public AutoTuneConfig() { 033 } 034 035 /** 036 * Return true if we are profiling or query tuning. 037 * 038 * If we are not doing either then we don't need a CallStack. 039 */ 040 public boolean isActive() { 041 return profiling || queryTuning; 042 } 043 044 /** 045 * Return the name of the file that holds the query tuning information. 046 */ 047 public String getQueryTuningFile() { 048 return queryTuningFile; 049 } 050 051 /** 052 * Set the name of the file that holds the query tuning information. 053 */ 054 public void setQueryTuningFile(String queryTuningFile) { 055 this.queryTuningFile = queryTuningFile; 056 } 057 058 /** 059 * Return the name of the file that profiling information is written to. 060 */ 061 public String getProfilingFile() { 062 return profilingFile; 063 } 064 065 /** 066 * Set the name of the file that profiling information is written to. 067 */ 068 public void setProfilingFile(String profilingFile) { 069 this.profilingFile = profilingFile; 070 } 071 072 /** 073 * Return the frequency in seconds the profiling should be collected and automatically applied to the tuning. 074 */ 075 public int getProfilingUpdateFrequency() { 076 return profilingUpdateFrequency; 077 } 078 079 /** 080 * Set the frequency in seconds the profiling should be collected and automatically applied to the tuning. 081 */ 082 public void setProfilingUpdateFrequency(int profilingUpdateFrequency) { 083 this.profilingUpdateFrequency = profilingUpdateFrequency; 084 } 085 086 /** 087 * Return the mode used when autoTune has not been explicit defined on a 088 * query. 089 */ 090 public AutoTuneMode getMode() { 091 return mode; 092 } 093 094 /** 095 * Set the mode used when autoTune has not been explicit defined on a query. 096 */ 097 public void setMode(AutoTuneMode mode) { 098 this.mode = mode; 099 } 100 101 /** 102 * Return true if the queries are being tuned. 103 */ 104 public boolean isQueryTuning() { 105 return queryTuning; 106 } 107 108 /** 109 * Set to true if the queries should be tuned by autoTune. 110 */ 111 public void setQueryTuning(boolean queryTuning) { 112 this.queryTuning = queryTuning; 113 } 114 115 /** 116 * Return true if the version property should be added when the query is 117 * tuned. 118 * <p> 119 * If this is false then the version property will be added when profiling 120 * detects that the bean is possibly going to be modified. 121 * </p> 122 */ 123 public boolean isQueryTuningAddVersion() { 124 return queryTuningAddVersion; 125 } 126 127 /** 128 * Set to true to force the version property to be always added by the query 129 * tuning. 130 * <p> 131 * If this is false then the version property will be added when profiling 132 * detects that the bean is possibly going to be modified. 133 * </p> 134 * <p> 135 * Generally this is not expected to be turned on. 136 * </p> 137 */ 138 public void setQueryTuningAddVersion(boolean queryTuningAddVersion) { 139 this.queryTuningAddVersion = queryTuningAddVersion; 140 } 141 142 /** 143 * Return true if profiling information should be collected. 144 */ 145 public boolean isProfiling() { 146 return profiling; 147 } 148 149 /** 150 * Set to true if profiling information should be collected. 151 * <p> 152 * The profiling information is collected and then used to generate the tuned 153 * queries for autoTune. 154 * </p> 155 */ 156 public void setProfiling(boolean profiling) { 157 this.profiling = profiling; 158 } 159 160 /** 161 * Return the base number of queries to profile before changing to profile 162 * only a percentage of following queries (profileRate). 163 */ 164 public int getProfilingBase() { 165 return profilingBase; 166 } 167 168 /** 169 * Set the based number of queries to profile. 170 */ 171 public void setProfilingBase(int profilingBase) { 172 this.profilingBase = profilingBase; 173 } 174 175 /** 176 * Return the rate (%) of queries to be profiled after the 'base' amount of 177 * profiling. 178 */ 179 public double getProfilingRate() { 180 return profilingRate; 181 } 182 183 /** 184 * Set the rate (%) of queries to be profiled after the 'base' amount of 185 * profiling. 186 */ 187 public void setProfilingRate(double profilingRate) { 188 this.profilingRate = profilingRate; 189 } 190 191 /** 192 * Return the time in millis to wait after a system gc to collect profiling 193 * information. 194 * <p> 195 * The profiling information is collected on object finalise. As such we 196 * generally don't want to trigger GC (let the JVM do its thing) but on 197 * shutdown the autoTune manager will trigger System.gc() and then wait 198 * (default 100 millis) to hopefully collect profiling information - 199 * especially for short run unit tests. 200 * </p> 201 */ 202 public int getGarbageCollectionWait() { 203 return garbageCollectionWait; 204 } 205 206 /** 207 * Set the time in millis to wait after a System.gc() to collect profiling information. 208 */ 209 public void setGarbageCollectionWait(int garbageCollectionWait) { 210 this.garbageCollectionWait = garbageCollectionWait; 211 } 212 213 /** 214 * Return true if triggering garbage collection should be skipped on shutdown. 215 * You might set this when System.GC() slows a application shutdown too much. 216 */ 217 public boolean isSkipGarbageCollectionOnShutdown() { 218 return skipGarbageCollectionOnShutdown; 219 } 220 221 /** 222 * Set to true if triggering garbage collection should be skipped on shutdown. 223 * You might set this when System.GC() slows a application shutdown too much. 224 */ 225 public void setSkipGarbageCollectionOnShutdown(boolean skipGarbageCollectionOnShutdown) { 226 this.skipGarbageCollectionOnShutdown = skipGarbageCollectionOnShutdown; 227 } 228 229 /** 230 * Return true if profile reporting should be skipped on shutdown. 231 */ 232 public boolean isSkipProfileReportingOnShutdown() { 233 return skipProfileReportingOnShutdown; 234 } 235 236 /** 237 * Set to true if profile reporting should be skipped on shutdown. 238 */ 239 public void setSkipProfileReportingOnShutdown(boolean skipProfileReportingOnShutdown) { 240 this.skipProfileReportingOnShutdown = skipProfileReportingOnShutdown; 241 } 242 243 /** 244 * Load the settings from the properties file. 245 */ 246 public void loadSettings(PropertiesWrapper p) { 247 248 queryTuning = p.getBoolean("autoTune.queryTuning", queryTuning); 249 queryTuningAddVersion = p.getBoolean("autoTune.queryTuningAddVersion", queryTuningAddVersion); 250 queryTuningFile = p.get("autoTune.queryTuningFile", queryTuningFile); 251 252 skipGarbageCollectionOnShutdown = p.getBoolean("autoTune.skipGarbageCollectionOnShutdown", skipGarbageCollectionOnShutdown); 253 skipProfileReportingOnShutdown = p.getBoolean("autoTune.skipProfileReportingOnShutdown", skipProfileReportingOnShutdown); 254 255 mode = p.getEnum(AutoTuneMode.class, "autoTune.mode", mode); 256 257 profiling = p.getBoolean("autoTune.profiling", profiling); 258 profilingBase = p.getInt("autoTune.profilingBase", profilingBase); 259 profilingRate = p.getDouble("autoTune.profilingRate", profilingRate); 260 profilingFile = p.get("autoTune.profilingFile", profilingFile); 261 profilingUpdateFrequency = p.getInt("autoTune.profilingUpdateFrequency", profilingUpdateFrequency); 262 } 263}