You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cloudstack.apache.org by ch...@apache.org on 2013/01/18 02:22:19 UTC

git commit: CLOUDSTACK-810: Make DirectAgent thread pool size configurable Removed hard-coding of directagent thread pool size and now reading it from configuration

Updated Branches:
  refs/heads/master f264571e9 -> cd37e22f9


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 <ch...@apache.org>


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/cd37e22f
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/cd37e22f
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/cd37e22f

Branch: refs/heads/master
Commit: cd37e22f9baf15f1369e5087197dafbcaf2ad65e
Parents: f264571
Author: Koushik Das <ko...@citrix.com>
Authored: Mon Jan 7 13:40:55 2013 +0530
Committer: Chiradeep Vittal <ch...@apache.org>
Committed: Thu Jan 17 17:21:52 2013 -0800

----------------------------------------------------------------------
 .../com/cloud/agent/manager/AgentManagerImpl.java  |   23 +++++++++++----
 .../cloud/agent/manager/DirectAgentAttache.java    |   13 ++------
 server/src/com/cloud/configuration/Config.java     |    2 +-
 setup/db/db/schema-40to410.sql                     |    2 +
 4 files changed, 24 insertions(+), 16 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cd37e22f/server/src/com/cloud/agent/manager/AgentManagerImpl.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/agent/manager/AgentManagerImpl.java b/server/src/com/cloud/agent/manager/AgentManagerImpl.java
index 8141fdb..8b3ee6b 100755
--- a/server/src/com/cloud/agent/manager/AgentManagerImpl.java
+++ b/server/src/com/cloud/agent/manager/AgentManagerImpl.java
@@ -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;
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cd37e22f/server/src/com/cloud/agent/manager/DirectAgentAttache.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/agent/manager/DirectAgentAttache.java b/server/src/com/cloud/agent/manager/DirectAgentAttache.java
index 848c7e6..9b7d69f 100755
--- a/server/src/com/cloud/agent/manager/DirectAgentAttache.java
+++ b/server/src/com/cloud/agent/manager/DirectAgentAttache.java
@@ -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));
         }
     }
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cd37e22f/server/src/com/cloud/configuration/Config.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/configuration/Config.java b/server/src/com/cloud/configuration/Config.java
index b91fbdd..ce3698f 100755
--- a/server/src/com/cloud/configuration/Config.java
+++ b/server/src/com/cloud/configuration/Config.java
@@ -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"),
 

http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/cd37e22f/setup/db/db/schema-40to410.sql
----------------------------------------------------------------------
diff --git a/setup/db/db/schema-40to410.sql b/setup/db/db/schema-40to410.sql
index c115135..a9d168d 100644
--- a/setup/db/db/schema-40to410.sql
+++ b/setup/db/db/schema-40to410.sql
@@ -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');