mirror of https://github.com/apache/cloudstack.git
CLOUDSTACK-810: Make DirectAgent thread pool size configurable Removed hard-coding of directagent thread pool size and now reading it from configuration
Signed-off-by: Chiradeep Vittal <chiradeep@apache.org>
This commit is contained in:
parent
f264571e92
commit
cd37e22f9b
|
|
@ -28,6 +28,8 @@ import java.util.Random;
|
|||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.LinkedBlockingQueue;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.ThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.concurrent.locks.Lock;
|
||||
|
|
@ -94,6 +96,7 @@ import com.cloud.resource.Discoverer;
|
|||
import com.cloud.resource.ResourceManager;
|
||||
import com.cloud.resource.ResourceState;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.server.ManagementService;
|
||||
import com.cloud.storage.StorageManager;
|
||||
import com.cloud.storage.StorageService;
|
||||
import com.cloud.storage.dao.StoragePoolDao;
|
||||
|
|
@ -220,7 +223,8 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||
|
||||
protected ExecutorService _executor;
|
||||
protected ThreadPoolExecutor _connectExecutor;
|
||||
|
||||
protected ScheduledExecutorService _directAgentExecutor;
|
||||
|
||||
protected StateMachine2<Status, Status.Event, Host> _statusStateMachine = Status.getStateMachine();
|
||||
|
||||
@Inject ResourceManager _resourceMgr;
|
||||
|
|
@ -280,10 +284,15 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||
new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("AgentConnectTaskPool"));
|
||||
//allow core threads to time out even when there are no items in the queue
|
||||
_connectExecutor.allowCoreThreadTimeOut(true);
|
||||
|
||||
_connection = new NioServer("AgentManager", _port, workers + 10, this);
|
||||
|
||||
_connection = new NioServer("AgentManager", _port, workers + 10, this);
|
||||
s_logger.info("Listening on " + _port + " with " + workers + " workers");
|
||||
|
||||
value = configs.get(Config.DirectAgentPoolSize.key());
|
||||
int size = NumbersUtil.parseInt(value, 500);
|
||||
_directAgentExecutor = new ScheduledThreadPoolExecutor(size, new NamedThreadFactory("DirectAgent"));
|
||||
s_logger.debug("Created DirectAgentAttache pool with size: " + size);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -1521,7 +1530,9 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
|
|||
attache.setMaintenanceMode(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public ScheduledExecutorService getDirectAgentPool() {
|
||||
return _directAgentExecutor;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,14 +18,11 @@ package com.cloud.agent.manager;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.ScheduledExecutorService;
|
||||
import java.util.concurrent.ScheduledFuture;
|
||||
import java.util.concurrent.ScheduledThreadPoolExecutor;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.apache.log4j.Logger;
|
||||
|
||||
import com.cloud.agent.AgentManager;
|
||||
import com.cloud.agent.api.Answer;
|
||||
import com.cloud.agent.api.Command;
|
||||
import com.cloud.agent.api.CronCommand;
|
||||
|
|
@ -37,13 +34,11 @@ import com.cloud.exception.AgentUnavailableException;
|
|||
import com.cloud.host.Status;
|
||||
import com.cloud.host.Status.Event;
|
||||
import com.cloud.resource.ServerResource;
|
||||
import com.cloud.utils.concurrency.NamedThreadFactory;
|
||||
|
||||
public class DirectAgentAttache extends AgentAttache {
|
||||
private final static Logger s_logger = Logger.getLogger(DirectAgentAttache.class);
|
||||
|
||||
ServerResource _resource;
|
||||
static ScheduledExecutorService s_executor = new ScheduledThreadPoolExecutor(500, new NamedThreadFactory("DirectAgent"));
|
||||
List<ScheduledFuture<?>> _futures = new ArrayList<ScheduledFuture<?>>();
|
||||
AgentManagerImpl _mgr;
|
||||
long _seq = 0;
|
||||
|
|
@ -94,15 +89,15 @@ public class DirectAgentAttache extends AgentAttache {
|
|||
if (answers != null && answers[0] instanceof StartupAnswer) {
|
||||
StartupAnswer startup = (StartupAnswer)answers[0];
|
||||
int interval = startup.getPingInterval();
|
||||
_futures.add(s_executor.scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
|
||||
_futures.add(_agentMgr.getDirectAgentPool().scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
|
||||
}
|
||||
} else {
|
||||
Command[] cmds = req.getCommands();
|
||||
if (cmds.length > 0 && !(cmds[0] instanceof CronCommand)) {
|
||||
s_executor.execute(new Task(req));
|
||||
_agentMgr.getDirectAgentPool().execute(new Task(req));
|
||||
} else {
|
||||
CronCommand cmd = (CronCommand)cmds[0];
|
||||
_futures.add(s_executor.scheduleAtFixedRate(new Task(req), cmd.getInterval(), cmd.getInterval(), TimeUnit.SECONDS));
|
||||
_futures.add(_agentMgr.getDirectAgentPool().scheduleAtFixedRate(new Task(req), cmd.getInterval(), cmd.getInterval(), TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -113,7 +108,7 @@ public class DirectAgentAttache extends AgentAttache {
|
|||
StartupAnswer startup = (StartupAnswer)answers[0];
|
||||
int interval = startup.getPingInterval();
|
||||
s_logger.info("StartupAnswer received " + startup.getHostId() + " Interval = " + interval );
|
||||
_futures.add(s_executor.scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
|
||||
_futures.add(_agentMgr.getDirectAgentPool().scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -296,8 +296,8 @@ public enum Config {
|
|||
VmOpCleanupWait("Advanced", ManagementServer.class, Long.class, "vm.op.cleanup.wait", "3600", "Time (in seconds) to wait before cleanuping up any vm work items", "Seconds"),
|
||||
VmOpCancelInterval("Advanced", ManagementServer.class, Long.class, "vm.op.cancel.interval", "3600", "Time (in seconds) to wait before cancelling a operation", "Seconds"),
|
||||
|
||||
|
||||
DefaultPageSize("Advanced", ManagementServer.class, Long.class, "default.page.size", "500", "Default page size for API list* commands", null),
|
||||
DirectAgentPoolSize("Advanced", ManagementServer.class, Integer.class, "direct.agent.pool.size", "500", "Default size for DirectAgentPool", null),
|
||||
|
||||
TaskCleanupRetryInterval("Advanced", ManagementServer.class, Integer.class, "task.cleanup.retry.interval", "600", "Time (in seconds) to wait before retrying cleanup of tasks if the cleanup failed previously. 0 means to never retry.", "Seconds"),
|
||||
|
||||
|
|
|
|||
|
|
@ -944,3 +944,5 @@ left join host_pod_ref on storage_pool.pod_id = host_pod_ref.id
|
|||
left join storage_pool_details on storage_pool_details.pool_id = storage_pool.id and storage_pool_details.value = 'true'
|
||||
left join op_host_capacity on storage_pool.id = op_host_capacity.host_id and op_host_capacity.capacity_type = 3
|
||||
left join async_job on async_job.instance_id = storage_pool.id and async_job.instance_type = "StoragePool" and async_job.job_status = 0;
|
||||
|
||||
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'direct.agent.pool.size', '500', 'Default size for DirectAgentPool');
|
||||
|
|
|
|||
Loading…
Reference in New Issue