diff --git a/src/main/java/com/avaje/ebean/AutoTune.java b/src/main/java/com/avaje/ebean/AutoTune.java index c5d17ac55..dc34f7b09 100644 --- a/src/main/java/com/avaje/ebean/AutoTune.java +++ b/src/main/java/com/avaje/ebean/AutoTune.java @@ -11,4 +11,14 @@ public interface AutoTune { */ void collectProfiling(); + /** + * Output the profiling. + *

+ * When profiling updates are applied to tuning at runtime this reports all tuning and profiling combined. + * When profiling is not applied at runtime then this reports the diff report with new and diff entries relative + * to the existing tuning. + *

+ */ + void reportProfiling(); + } diff --git a/src/main/java/com/avaje/ebean/config/AutoTuneConfig.java b/src/main/java/com/avaje/ebean/config/AutoTuneConfig.java index 2b1ff7996..85e5306b1 100644 --- a/src/main/java/com/avaje/ebean/config/AutoTuneConfig.java +++ b/src/main/java/com/avaje/ebean/config/AutoTuneConfig.java @@ -25,7 +25,9 @@ public class AutoTuneConfig { private int garbageCollectionWait = 100; - private boolean skipCollectionOnShutdown; + private boolean skipGarbageCollectionOnShutdown; + + private boolean skipProfileReportingOnShutdown; public AutoTuneConfig() { } @@ -200,17 +202,33 @@ public class AutoTuneConfig { } /** - * Return true if profiling collection should be skipped on shutdown. + * Return true if triggering garbage collection should be skipped on shutdown. + * You might set this when System.GC() slows a application shutdown too much. */ - public boolean isSkipCollectionOnShutdown() { - return skipCollectionOnShutdown; + public boolean isSkipGarbageCollectionOnShutdown() { + return skipGarbageCollectionOnShutdown; } /** - * Set to true if profiling collection should be skipped on shutdown. + * Set to true if triggering garbage collection should be skipped on shutdown. + * You might set this when System.GC() slows a application shutdown too much. */ - public void setSkipCollectionOnShutdown(boolean skipCollectionOnShutdown) { - this.skipCollectionOnShutdown = skipCollectionOnShutdown; + public void setSkipGarbageCollectionOnShutdown(boolean skipGarbageCollectionOnShutdown) { + this.skipGarbageCollectionOnShutdown = skipGarbageCollectionOnShutdown; + } + + /** + * Return true if profile reporting should be skipped on shutdown. + */ + public boolean isSkipProfileReportingOnShutdown() { + return skipProfileReportingOnShutdown; + } + + /** + * Set to true if profile reporting should be skipped on shutdown. + */ + public void setSkipProfileReportingOnShutdown(boolean skipProfileReportingOnShutdown) { + this.skipProfileReportingOnShutdown = skipProfileReportingOnShutdown; } /** @@ -222,8 +240,9 @@ public class AutoTuneConfig { queryTuningAddVersion = p.getBoolean("autoTune.queryTuningAddVersion", queryTuningAddVersion); queryTuningFile = p.get("autoTune.queryTuningFile", queryTuningFile); - skipCollectionOnShutdown = p.getBoolean("autoTune.skipCollectionOnShutdown", skipCollectionOnShutdown); - + skipGarbageCollectionOnShutdown = p.getBoolean("autoTune.skipGarbageCollectionOnShutdown", skipGarbageCollectionOnShutdown); + skipProfileReportingOnShutdown = p.getBoolean("autoTune.skipProfileReportingOnShutdown", skipProfileReportingOnShutdown); + mode = p.getEnum(AutoTuneMode.class, "autoTune.mode", mode); profiling = p.getBoolean("autoTune.profiling", profiling); diff --git a/src/main/java/com/avaje/ebeaninternal/server/autotune/service/AutoTuneDiffCollection.java b/src/main/java/com/avaje/ebeaninternal/server/autotune/service/AutoTuneDiffCollection.java index f281e796b..b367ff250 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/autotune/service/AutoTuneDiffCollection.java +++ b/src/main/java/com/avaje/ebeaninternal/server/autotune/service/AutoTuneDiffCollection.java @@ -82,13 +82,11 @@ public class AutoTuneDiffCollection { /** * Process checking profiling entries against existing query tuning. */ - public boolean process() { + public void process() { for (AutoTuneCollection.Entry entry : profiling.getEntries()) { addToDocument(entry); } - - return isEmpty(); } /** diff --git a/src/main/java/com/avaje/ebeaninternal/server/autotune/service/DefaultAutoTuneService.java b/src/main/java/com/avaje/ebeaninternal/server/autotune/service/DefaultAutoTuneService.java index 59377738c..328393128 100644 --- a/src/main/java/com/avaje/ebeaninternal/server/autotune/service/DefaultAutoTuneService.java +++ b/src/main/java/com/avaje/ebeaninternal/server/autotune/service/DefaultAutoTuneService.java @@ -25,7 +25,9 @@ public class DefaultAutoTuneService implements AutoTuneService { private final long defaultGarbageCollectionWait; - private final boolean skipCollectionOnShutdown; + private final boolean skipGarbageCollectionOnShutdown; + + private final boolean skipProfileReportingOnShutdown; private final BaseQueryTuner queryTuner; @@ -58,7 +60,8 @@ public class DefaultAutoTuneService implements AutoTuneService { this.serverName = server.getName(); this.profileManager = new ProfileManager(config, server); this.queryTuner = new BaseQueryTuner(config, server, profileManager); - this.skipCollectionOnShutdown = config.isSkipCollectionOnShutdown(); + this.skipGarbageCollectionOnShutdown = config.isSkipGarbageCollectionOnShutdown(); + this.skipProfileReportingOnShutdown = config.isSkipProfileReportingOnShutdown(); this.defaultGarbageCollectionWait = (long) config.getGarbageCollectionWait(); } @@ -123,7 +126,8 @@ public class DefaultAutoTuneService implements AutoTuneService { AutoTuneCollection profiling = profileManager.profilingCollection(false); AutoTuneDiffCollection event = new AutoTuneDiffCollection(profiling, queryTuner, true); - if (event.process()) { + event.process(); + if (event.isEmpty()) { long exeMillis = System.currentTimeMillis() - start; logger.debug("No query tuning updates for server:{} executionMillis:{}", serverName, exeMillis); @@ -152,7 +156,8 @@ public class DefaultAutoTuneService implements AutoTuneService { AutoTuneCollection profiling = profileManager.profilingCollection(reset); AutoTuneDiffCollection event = new AutoTuneDiffCollection(profiling, queryTuner, false); - if (!event.process()) { + event.process(); + if (event.isEmpty()) { logger.info("No new or diff entries for profiling server:{}", serverName); } else { @@ -195,12 +200,29 @@ public class DefaultAutoTuneService implements AutoTuneService { */ @Override public void shutdown() { - if (profiling && !skipCollectionOnShutdown) { - collectProfiling(-1); - saveProfilingOnShutdown(false); + if (profiling) { + if (!skipGarbageCollectionOnShutdown && !skipProfileReportingOnShutdown) { + // trigger GC to update profiling information on recently executed queries + collectProfiling(-1); + } + if (!skipProfileReportingOnShutdown) { + saveProfilingOnShutdown(false); + } } } + /** + * Output the profiling. + *

+ * When profiling updates are applied to tuning at runtime this reports all tuning and profiling combined. + * When profiling is not applied at runtime then this reports the diff report with new and diff entries relative + * to the existing tuning. + *

+ */ + public void reportProfiling() { + saveProfilingOnShutdown(false); + } + /** * Ask for a System.gc() so that we gather node usage information. *

diff --git a/src/test/java/com/avaje/tests/basic/TestBatchLazy.java b/src/test/java/com/avaje/tests/basic/TestBatchLazy.java index 8a2e3ca37..7c1e27457 100644 --- a/src/test/java/com/avaje/tests/basic/TestBatchLazy.java +++ b/src/test/java/com/avaje/tests/basic/TestBatchLazy.java @@ -33,6 +33,7 @@ public class TestBatchLazy extends BaseTestCase { } Ebean.getDefaultServer().getAutoTune().collectProfiling(); + Ebean.getDefaultServer().getAutoTune().reportProfiling(); }