Test tear-down: limit number of threads in Entities.destroyAll In stress/scale tests that create 1000s of apps, trying to stop them all concurrently with a thread per app causes an OutOfMemoryError due to too many threads.
Project: http://git-wip-us.apache.org/repos/asf/brooklyn-server/repo Commit: http://git-wip-us.apache.org/repos/asf/brooklyn-server/commit/bfc66f7f Tree: http://git-wip-us.apache.org/repos/asf/brooklyn-server/tree/bfc66f7f Diff: http://git-wip-us.apache.org/repos/asf/brooklyn-server/diff/bfc66f7f Branch: refs/heads/master Commit: bfc66f7f352690605ffeb03b6146a13e969f1bfd Parents: b97942d Author: Aled Sage <[email protected]> Authored: Tue Jun 6 11:20:35 2017 +0100 Committer: Aled Sage <[email protected]> Committed: Fri Jun 16 13:31:23 2017 +0100 ---------------------------------------------------------------------- core/src/main/java/org/apache/brooklyn/core/entity/Entities.java | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/brooklyn-server/blob/bfc66f7f/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java ---------------------------------------------------------------------- diff --git a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java index acad9d2..46a9cea 100644 --- a/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java +++ b/core/src/main/java/org/apache/brooklyn/core/entity/Entities.java @@ -879,6 +879,8 @@ public class Entities { * Apps will be stopped+destroyed+unmanaged concurrently, waiting for all to complete. */ public static void destroyAll(final ManagementContext mgmt) { + final int MAX_THREADS = 100; + if (mgmt instanceof NonDeploymentManagementContext) { // log here because it is easy for tests to destroyAll(app.getMgmtContext()) // which will *not* destroy the mgmt context if the app has been stopped! @@ -889,7 +891,7 @@ public class Entities { } if (!mgmt.isRunning()) return; - ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newCachedThreadPool()); + ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(MAX_THREADS)); List<ListenableFuture<?>> futures = Lists.newArrayList(); final AtomicReference<Exception> error = Atomics.newReference(); try {
