diff --git a/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java b/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java index 8c69dcdc4828..64664dd7eb7b 100644 --- a/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java +++ b/engine/orchestration/src/main/java/com/cloud/agent/manager/AgentManagerImpl.java @@ -220,6 +220,9 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl private boolean _reconcileCommandsEnabled = false; private Integer _reconcileCommandInterval; + private static final int AGENT_CONNECT_CORE_POOL_SIZE = 100; + private static final int AGENT_CONNECT_MAX_POOL_SIZE = 500; + @Inject ResourceManager _resourceMgr; @Inject @@ -248,6 +251,10 @@ public class AgentManagerImpl extends ManagerBase implements AgentManager, Handl "Percentage (as a value between 0 and 1) of direct.agent.pool.size to be used as upper thread cap for a single direct agent to process requests", false); protected final ConfigKey CheckTxnBeforeSending = new ConfigKey<>("Developer", Boolean.class, "check.txn.before.sending.agent.commands", "false", "This parameter allows developers to enable a check to see if a transaction wraps commands that are sent to the resource. This is not to be enabled on production systems.", true); + protected final ConfigKey AgentConnectExecutorCorePoolSize = new ConfigKey<>("Advanced", Integer.class, "agent.connect.executor.core.pool.size", "100", + "Core pool size for the thread pool that handles agent connect tasks.", false); + protected final ConfigKey AgentConnectExecutorMaxPoolSize = new ConfigKey<>("Advanced", Integer.class, "agent.connect.executor.max.pool.size", "500", + "Maximum pool size for the thread pool that handles agent connect tasks.", false); public static final List HOST_DOWN_ALERT_UNSUPPORTED_HOST_TYPES = Arrays.asList( Host.Type.SecondaryStorage, @@ -423,11 +430,28 @@ public void onManagementServerCancelMaintenance() { } private void initConnectExecutor() { - _connectExecutor = new ThreadPoolExecutor(100, 500, 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("AgentConnectTaskPool")); + Pair poolSizeValues = retrieveAgentConnectPoolCoreSizeAndMaxSize(); + _connectExecutor = new ThreadPoolExecutor(poolSizeValues.first(), poolSizeValues.second(), 60L, TimeUnit.SECONDS, new LinkedBlockingQueue<>(), new NamedThreadFactory("AgentConnectTaskPool")); // allow core threads to time out even when there are no items in the queue _connectExecutor.allowCoreThreadTimeOut(true); } + private Pair retrieveAgentConnectPoolCoreSizeAndMaxSize() { + Integer agentConnectCorePoolSize = AgentConnectExecutorCorePoolSize.value(); + Integer agentConnectMaxSize = AgentConnectExecutorMaxPoolSize.value(); + if (agentConnectCorePoolSize == null || agentConnectCorePoolSize < 0 || agentConnectMaxSize == null || agentConnectMaxSize < 0) { + logger.warn("Invalid agent connect pool size values. Defaulting to core pool size {} and max pool size {}", AGENT_CONNECT_CORE_POOL_SIZE, AGENT_CONNECT_MAX_POOL_SIZE); + return new Pair<>(AGENT_CONNECT_CORE_POOL_SIZE, AGENT_CONNECT_MAX_POOL_SIZE); + + } + if (agentConnectMaxSize < agentConnectCorePoolSize) { + logger.warn("Max agent connect pool size {} is lower than core pool size {}. " + + "Defaulting to core pool size {} and max pool size {}", agentConnectMaxSize, agentConnectCorePoolSize, AGENT_CONNECT_CORE_POOL_SIZE, AGENT_CONNECT_MAX_POOL_SIZE); + return new Pair<>(AGENT_CONNECT_CORE_POOL_SIZE, AGENT_CONNECT_MAX_POOL_SIZE); + } + return new Pair<>(agentConnectCorePoolSize, agentConnectMaxSize); + } + private void initAndScheduleMonitorExecutor() { _monitorExecutor = new ScheduledThreadPoolExecutor(1, new NamedThreadFactory("AgentMonitor")); _monitorExecutor.scheduleWithFixedDelay(new MonitorTask(), mgmtServiceConf.getPingInterval(), mgmtServiceConf.getPingInterval(), TimeUnit.SECONDS); @@ -2136,7 +2160,7 @@ public ConfigKey[] getConfigKeys() { return new ConfigKey[] { CheckTxnBeforeSending, Workers, Port, Wait, AlertWait, DirectAgentLoadSize, DirectAgentPoolSize, DirectAgentThreadCap, EnableKVMAutoEnableDisable, ReadyCommandWait, GranularWaitTimeForCommands, RemoteAgentSslHandshakeTimeout, RemoteAgentMaxConcurrentNewConnections, - RemoteAgentNewConnectionsMonitorInterval, KVMHostDiscoverySshPort }; + RemoteAgentNewConnectionsMonitorInterval, KVMHostDiscoverySshPort, AgentConnectExecutorCorePoolSize, AgentConnectExecutorMaxPoolSize }; } protected class SetHostParamsListener implements Listener {