Skip to content

Commit cd37e22

Browse files
Koushik Daschiradeep
authored andcommitted
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>
1 parent f264571 commit cd37e22

4 files changed

Lines changed: 24 additions & 16 deletions

File tree

‎server/src/com/cloud/agent/manager/AgentManagerImpl.java‎

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
import java.util.concurrent.ConcurrentHashMap;
2929
import java.util.concurrent.ExecutorService;
3030
import java.util.concurrent.LinkedBlockingQueue;
31+
import java.util.concurrent.ScheduledExecutorService;
32+
import java.util.concurrent.ScheduledThreadPoolExecutor;
3133
import java.util.concurrent.ThreadPoolExecutor;
3234
import java.util.concurrent.TimeUnit;
3335
import java.util.concurrent.locks.Lock;
@@ -94,6 +96,7 @@
9496
import com.cloud.resource.ResourceManager;
9597
import com.cloud.resource.ResourceState;
9698
import com.cloud.resource.ServerResource;
99+
import com.cloud.server.ManagementService;
97100
import com.cloud.storage.StorageManager;
98101
import com.cloud.storage.StorageService;
99102
import com.cloud.storage.dao.StoragePoolDao;
@@ -220,7 +223,8 @@ public class AgentManagerImpl implements AgentManager, HandlerFactory, Manager {
220223

221224
protected ExecutorService _executor;
222225
protected ThreadPoolExecutor _connectExecutor;
223-
226+
protected ScheduledExecutorService _directAgentExecutor;
227+
224228
protected StateMachine2<Status, Status.Event, Host> _statusStateMachine = Status.getStateMachine();
225229

226230
@Inject ResourceManager _resourceMgr;
@@ -280,10 +284,15 @@ public boolean configure(final String name, final Map<String, Object> params) th
280284
new LinkedBlockingQueue<Runnable>(), new NamedThreadFactory("AgentConnectTaskPool"));
281285
//allow core threads to time out even when there are no items in the queue
282286
_connectExecutor.allowCoreThreadTimeOut(true);
283-
284-
_connection = new NioServer("AgentManager", _port, workers + 10, this);
285287

288+
_connection = new NioServer("AgentManager", _port, workers + 10, this);
286289
s_logger.info("Listening on " + _port + " with " + workers + " workers");
290+
291+
value = configs.get(Config.DirectAgentPoolSize.key());
292+
int size = NumbersUtil.parseInt(value, 500);
293+
_directAgentExecutor = new ScheduledThreadPoolExecutor(size, new NamedThreadFactory("DirectAgent"));
294+
s_logger.debug("Created DirectAgentAttache pool with size: " + size);
295+
287296
return true;
288297
}
289298

@@ -1521,7 +1530,9 @@ public void pullAgentOutMaintenance(long hostId) {
15211530
attache.setMaintenanceMode(false);
15221531
}
15231532
}
1524-
1525-
1526-
1533+
1534+
public ScheduledExecutorService getDirectAgentPool() {
1535+
return _directAgentExecutor;
1536+
}
1537+
15271538
}

‎server/src/com/cloud/agent/manager/DirectAgentAttache.java‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,11 @@
1818

1919
import java.util.ArrayList;
2020
import java.util.List;
21-
import java.util.concurrent.ScheduledExecutorService;
2221
import java.util.concurrent.ScheduledFuture;
23-
import java.util.concurrent.ScheduledThreadPoolExecutor;
2422
import java.util.concurrent.TimeUnit;
2523

2624
import org.apache.log4j.Logger;
2725

28-
import com.cloud.agent.AgentManager;
2926
import com.cloud.agent.api.Answer;
3027
import com.cloud.agent.api.Command;
3128
import com.cloud.agent.api.CronCommand;
@@ -37,13 +34,11 @@
3734
import com.cloud.host.Status;
3835
import com.cloud.host.Status.Event;
3936
import com.cloud.resource.ServerResource;
40-
import com.cloud.utils.concurrency.NamedThreadFactory;
4137

4238
public class DirectAgentAttache extends AgentAttache {
4339
private final static Logger s_logger = Logger.getLogger(DirectAgentAttache.class);
4440

4541
ServerResource _resource;
46-
static ScheduledExecutorService s_executor = new ScheduledThreadPoolExecutor(500, new NamedThreadFactory("DirectAgent"));
4742
List<ScheduledFuture<?>> _futures = new ArrayList<ScheduledFuture<?>>();
4843
AgentManagerImpl _mgr;
4944
long _seq = 0;
@@ -94,15 +89,15 @@ public void send(Request req) throws AgentUnavailableException {
9489
if (answers != null && answers[0] instanceof StartupAnswer) {
9590
StartupAnswer startup = (StartupAnswer)answers[0];
9691
int interval = startup.getPingInterval();
97-
_futures.add(s_executor.scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
92+
_futures.add(_agentMgr.getDirectAgentPool().scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
9893
}
9994
} else {
10095
Command[] cmds = req.getCommands();
10196
if (cmds.length > 0 && !(cmds[0] instanceof CronCommand)) {
102-
s_executor.execute(new Task(req));
97+
_agentMgr.getDirectAgentPool().execute(new Task(req));
10398
} else {
10499
CronCommand cmd = (CronCommand)cmds[0];
105-
_futures.add(s_executor.scheduleAtFixedRate(new Task(req), cmd.getInterval(), cmd.getInterval(), TimeUnit.SECONDS));
100+
_futures.add(_agentMgr.getDirectAgentPool().scheduleAtFixedRate(new Task(req), cmd.getInterval(), cmd.getInterval(), TimeUnit.SECONDS));
106101
}
107102
}
108103
}
@@ -113,7 +108,7 @@ public void process(Answer[] answers) {
113108
StartupAnswer startup = (StartupAnswer)answers[0];
114109
int interval = startup.getPingInterval();
115110
s_logger.info("StartupAnswer received " + startup.getHostId() + " Interval = " + interval );
116-
_futures.add(s_executor.scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
111+
_futures.add(_agentMgr.getDirectAgentPool().scheduleAtFixedRate(new PingTask(), interval, interval, TimeUnit.SECONDS));
117112
}
118113
}
119114

‎server/src/com/cloud/configuration/Config.java‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,8 @@ public enum Config {
296296
VmOpCleanupWait("Advanced", ManagementServer.class, Long.class, "vm.op.cleanup.wait", "3600", "Time (in seconds) to wait before cleanuping up any vm work items", "Seconds"),
297297
VmOpCancelInterval("Advanced", ManagementServer.class, Long.class, "vm.op.cancel.interval", "3600", "Time (in seconds) to wait before cancelling a operation", "Seconds"),
298298

299-
300299
DefaultPageSize("Advanced", ManagementServer.class, Long.class, "default.page.size", "500", "Default page size for API list* commands", null),
300+
DirectAgentPoolSize("Advanced", ManagementServer.class, Integer.class, "direct.agent.pool.size", "500", "Default size for DirectAgentPool", null),
301301

302302
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"),
303303

‎setup/db/db/schema-40to410.sql‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -944,3 +944,5 @@ left join host_pod_ref on storage_pool.pod_id = host_pod_ref.id
944944
left join storage_pool_details on storage_pool_details.pool_id = storage_pool.id and storage_pool_details.value = 'true'
945945
left join op_host_capacity on storage_pool.id = op_host_capacity.host_id and op_host_capacity.capacity_type = 3
946946
left join async_job on async_job.instance_id = storage_pool.id and async_job.instance_type = "StoragePool" and async_job.job_status = 0;
947+
948+
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 'direct.agent.pool.size', '500', 'Default size for DirectAgentPool');

0 commit comments

Comments
 (0)