Skip to content

Commit aa9701a

Browse files
author
Sheng Yang
committed
CLOUDSTACK-799: Redundant router: Speed up RvR status update
The basic idea behind this is, deploy a fix sized threadpool for updating RvR status, then using producer/consumer model. There is a global configuration router.check.poolsize(10 by default) to control the pool size. Using pool size 100 for 1000 RvR is tested with simulator and works well. Also we can adjust the global configuration option router.check.interval to e.g. 60s from default 30s to mitigate the issue.
1 parent f1c15f0 commit aa9701a

6 files changed

Lines changed: 97 additions & 16 deletions

File tree

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ public enum Config {
167167
RouterStatsInterval("Advanced", NetworkManager.class, Integer.class, "router.stats.interval", "300", "Interval (in seconds) to report router statistics.", null),
168168
ExternalNetworkStatsInterval("Advanced", NetworkManager.class, Integer.class, "external.network.stats.interval", "300", "Interval (in seconds) to report external network statistics.", null),
169169
RouterCheckInterval("Advanced", NetworkManager.class, Integer.class, "router.check.interval", "30", "Interval (in seconds) to report redundant router status.", null),
170+
RouterCheckPoolSize("Advanced", NetworkManager.class, Integer.class, "router.check.poolsize", "10", "Numbers of threads using to check redundant router status.", null),
170171
RouterTemplateId("Advanced", NetworkManager.class, Long.class, "router.template.id", "1", "Default ID for template.", null),
171172
RouterExtraPublicNics("Advanced", NetworkManager.class, Integer.class, "router.extra.public.nics", "2", "specify extra public nics used for virtual router(up to 5)", "0-5"),
172173
StartRetry("Advanced", AgentManager.class, Integer.class, "start.retry", "10", "Number of times to retry create and start commands", null),

‎server/src/com/cloud/network/dao/NetworkDao.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,4 +110,5 @@ public interface NetworkDao extends GenericDao<NetworkVO, Long> {
110110

111111
List<NetworkVO> listNetworksByAccount(long accountId, long zoneId, Network.GuestType type, boolean isSystem);
112112

113+
List<NetworkVO> listRedundantNetworks();
113114
}

‎server/src/com/cloud/network/dao/NetworkDaoImpl.java‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ protected NetworkDaoImpl() {
103103
AllFieldsSearch.and("vpcId", AllFieldsSearch.entity().getVpcId(), Op.EQ);
104104
SearchBuilder<NetworkOfferingVO> join1 = _ntwkOffDao.createSearchBuilder();
105105
join1.and("isSystem", join1.entity().isSystemOnly(), Op.EQ);
106+
join1.and("isRedundant", join1.entity().getRedundantRouter(), Op.EQ);
106107
AllFieldsSearch.join("offerings", join1, AllFieldsSearch.entity().getNetworkOfferingId(), join1.entity().getId(), JoinBuilder.JoinType.INNER);
107108
AllFieldsSearch.done();
108109

@@ -574,4 +575,12 @@ public List<NetworkVO> listNetworksByAccount(long accountId, long zoneId, Networ
574575
List<NetworkVO> networks = search(sc, null);
575576
return networks;
576577
}
578+
579+
@Override
580+
public List<NetworkVO> listRedundantNetworks() {
581+
SearchCriteria<NetworkVO> sc = AllFieldsSearch.create();
582+
sc.setJoinParameters("offerings", "isRedundant", true);
583+
584+
return listBy(sc, null);
585+
}
577586
}

‎server/src/com/cloud/network/router/VirtualNetworkApplianceManagerImpl.java‎

Lines changed: 78 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,14 @@
2828
import java.util.Iterator;
2929
import java.util.List;
3030
import java.util.Map;
31+
import java.util.Queue;
3132
import java.util.Set;
3233
import java.util.TimeZone;
34+
import java.util.concurrent.BlockingQueue;
35+
import java.util.concurrent.ConcurrentLinkedQueue;
36+
import java.util.concurrent.ExecutorService;
3337
import java.util.concurrent.Executors;
38+
import java.util.concurrent.LinkedBlockingQueue;
3439
import java.util.concurrent.ScheduledExecutorService;
3540
import java.util.concurrent.TimeUnit;
3641

@@ -339,6 +344,7 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
339344

340345
int _routerStatsInterval = 300;
341346
int _routerCheckInterval = 30;
347+
int _rvrStatusUpdatePoolSize = 10;
342348
protected ServiceOfferingVO _offering;
343349
private String _dnsBasicZoneUpdates = "all";
344350
private Set<String> _guestOSNeedGatewayOnNonDefaultNetwork = new HashSet<String>();
@@ -353,8 +359,11 @@ public class VirtualNetworkApplianceManagerImpl implements VirtualNetworkApplian
353359
ScheduledExecutorService _executor;
354360
ScheduledExecutorService _checkExecutor;
355361
ScheduledExecutorService _networkStatsUpdateExecutor;
362+
ExecutorService _rvrStatusUpdateExecutor;
356363

357364
Account _systemAcct;
365+
366+
BlockingQueue<Long> _vrUpdateQueue = null;
358367

359368
@Override
360369
public boolean sendSshKeysToHost(Long hostId, String pubKey, String prvKey) {
@@ -582,7 +591,7 @@ public boolean configure(final String name, final Map<String, Object> params) th
582591
_executor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterMonitor"));
583592
_checkExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("RouterStatusMonitor"));
584593
_networkStatsUpdateExecutor = Executors.newScheduledThreadPool(1, new NamedThreadFactory("NetworkStatsUpdater"));
585-
594+
586595
final ComponentLocator locator = ComponentLocator.getCurrentLocator();
587596

588597
final Map<String, String> configs = _configDao.getConfiguration("AgentManager", params);
@@ -609,7 +618,18 @@ public boolean configure(final String name, final Map<String, Object> params) th
609618

610619
value = configs.get("router.check.interval");
611620
_routerCheckInterval = NumbersUtil.parseInt(value, 30);
612-
621+
622+
value = configs.get("router.check.poolsize");
623+
_rvrStatusUpdatePoolSize = NumbersUtil.parseInt(value, 10);
624+
625+
/*
626+
* We assume that one thread can handle 20 requests in 1 minute in normal situation, so here we give the queue size up to 50 minutes.
627+
* It's mostly for buffer, since each time CheckRouterTask running, it would add all the redundant networks in the queue immediately
628+
*/
629+
_vrUpdateQueue = new LinkedBlockingQueue<Long>(_rvrStatusUpdatePoolSize * 1000);
630+
631+
_rvrStatusUpdateExecutor = Executors.newFixedThreadPool(_rvrStatusUpdatePoolSize, new NamedThreadFactory("RedundantRouterStatusMonitor"));
632+
613633
_instance = configs.get("instance.name");
614634
if (_instance == null) {
615635
_instance = "DEFAULT";
@@ -707,6 +727,9 @@ public boolean start() {
707727

708728
if (_routerCheckInterval > 0) {
709729
_checkExecutor.scheduleAtFixedRate(new CheckRouterTask(), _routerCheckInterval, _routerCheckInterval, TimeUnit.SECONDS);
730+
for (int i = 0; i < _rvrStatusUpdatePoolSize; i++) {
731+
_rvrStatusUpdateExecutor.execute(new RvRStatusUpdateTask());
732+
}
710733
} else {
711734
s_logger.debug("router.check.interval - " + _routerCheckInterval+ " so not scheduling the redundant router checking thread");
712735
}
@@ -1042,14 +1065,11 @@ protected void updateRoutersRedundantState(List<DomainRouterVO> routers) {
10421065
if (host == null || host.getStatus() != Status.Up) {
10431066
router.setRedundantState(RedundantState.UNKNOWN);
10441067
updated = true;
1045-
} else if (host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
1046-
/* Only cover hosts managed by this management server */
1047-
continue;
10481068
} else if (privateIP != null) {
10491069
final CheckRouterCommand command = new CheckRouterCommand();
10501070
command.setAccessDetail(NetworkElementCommand.ROUTER_IP, getRouterControlIp(router.getId()));
10511071
command.setAccessDetail(NetworkElementCommand.ROUTER_NAME, router.getInstanceName());
1052-
command.setWait(60);
1072+
command.setWait(30);
10531073
final Answer origAnswer = _agentMgr.easySend(router.getHostId(), command);
10541074
CheckRouterAnswer answer = null;
10551075
if (origAnswer instanceof CheckRouterAnswer) {
@@ -1131,11 +1151,11 @@ private int getRealPriority(DomainRouterVO router) {
11311151
return priority;
11321152
}
11331153

1134-
protected class CheckRouterTask implements Runnable {
1154+
protected class RvRStatusUpdateTask implements Runnable {
11351155

1136-
public CheckRouterTask() {
1156+
public RvRStatusUpdateTask() {
11371157
}
1138-
1158+
11391159
/*
11401160
* In order to make fail-over works well at any time, we have to ensure:
11411161
* 1. Backup router's priority = Master's priority - DELTA + 1
@@ -1198,9 +1218,9 @@ private void checkDuplicateMaster(List <DomainRouterVO> routers) {
11981218
String title = "More than one redundant virtual router is in MASTER state! Router " + router.getHostName() + " and router " + dupRouter.getHostName();
11991219
String context = "Virtual router (name: " + router.getHostName() + ", id: " + router.getId() + " and router (name: "
12001220
+ dupRouter.getHostName() + ", id: " + router.getId() + ") are both in MASTER state! If the problem persist, restart both of routers. ";
1201-
12021221
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER, router.getDataCenterIdToDeployIn(), router.getPodIdToDeployIn(), title, context);
12031222
_alertMgr.sendAlert(AlertManager.ALERT_TYPE_DOMAIN_ROUTER, dupRouter.getDataCenterIdToDeployIn(), dupRouter.getPodIdToDeployIn(), title, context);
1223+
s_logger.warn(context);
12041224
} else {
12051225
networkRouterMaps.put(routerGuestNtwkId, router);
12061226
}
@@ -1209,19 +1229,61 @@ private void checkDuplicateMaster(List <DomainRouterVO> routers) {
12091229
}
12101230
}
12111231

1232+
@Override
1233+
public void run() {
1234+
while (true) {
1235+
try {
1236+
Long networkId = _vrUpdateQueue.take();
1237+
List <DomainRouterVO> routers = _routerDao.listByNetworkAndRole(networkId, Role.VIRTUAL_ROUTER);
1238+
1239+
if (routers.size() != 2) {
1240+
continue;
1241+
}
1242+
/*
1243+
* We update the router pair which the lower id router owned by this mgmt server, in order
1244+
* to prevent duplicate update of router status from cluster mgmt servers
1245+
*/
1246+
DomainRouterVO router = routers.get(0);
1247+
if (routers.get(1).getId() < router.getId()) {
1248+
router = routers.get(1);
1249+
}
1250+
HostVO host = _hostDao.findById(router.getHostId());
1251+
if (host == null || host.getManagementServerId() == null ||
1252+
host.getManagementServerId() != ManagementServerNode.getManagementServerId()) {
1253+
continue;
1254+
}
1255+
updateRoutersRedundantState(routers);
1256+
checkDuplicateMaster(routers);
1257+
checkSanity(routers);
1258+
} catch (Exception ex) {
1259+
s_logger.error("Fail to complete the RvRStatusUpdateTask! ", ex);
1260+
}
1261+
}
1262+
}
1263+
1264+
}
1265+
1266+
protected class CheckRouterTask implements Runnable {
1267+
1268+
public CheckRouterTask() {
1269+
}
1270+
12121271
@Override
12131272
public void run() {
12141273
try {
12151274
final List<DomainRouterVO> routers = _routerDao.listIsolatedByHostId(null);
1216-
s_logger.debug("Found " + routers.size() + " routers. ");
1275+
s_logger.debug("Found " + routers.size() + " routers to update status. ");
12171276

1218-
updateRoutersRedundantState(routers);
12191277
updateSite2SiteVpnConnectionState(routers);
12201278

1221-
/* FIXME assumed the a pair of redundant routers managed by same mgmt server,
1222-
* then the update above can get the latest status */
1223-
checkDuplicateMaster(routers);
1224-
checkSanity(routers);
1279+
final List<NetworkVO> networks = _networkDao.listRedundantNetworks();
1280+
s_logger.debug("Found " + networks.size() + " networks to update RvR status. ");
1281+
for (NetworkVO network : networks) {
1282+
if (!_vrUpdateQueue.offer(network.getId(), 500, TimeUnit.MILLISECONDS)) {
1283+
s_logger.warn("Cannot insert into virtual router update queue! Adjustment of router.check.interval and router.check.poolsize maybe needed.");
1284+
break;
1285+
}
1286+
}
12251287
} catch (Exception ex) {
12261288
s_logger.error("Fail to complete the CheckRouterTask! ", ex);
12271289
}

‎server/test/com/cloud/vpc/dao/MockNetworkDaoImpl.java‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,4 +351,10 @@ public List<NetworkVO> listNetworksByAccount(long accountId, long zoneId, GuestT
351351
return null;
352352
}
353353

354+
@Override
355+
public List<NetworkVO> listRedundantNetworks() {
356+
// TODO Auto-generated method stub
357+
return null;
358+
}
359+
354360
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ CREATE TABLE `cloud`.`template_s3_ref` (
5252

5353
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'management-server', 's3.enable', 'false', 'enable s3');
5454

55+
INSERT IGNORE INTO `cloud`.`configuration` VALUES ('Advanced', 'DEFAULT', 'NetworkManager', 'router.check.poolsize' , '10', 'Numbers of threads using to check redundant router status.');
56+
5557
ALTER TABLE `cloud`.`snapshots` ADD COLUMN `s3_id` bigint unsigned COMMENT 'S3 to which this snapshot will be stored';
5658

5759
ALTER TABLE `cloud`.`snapshots` ADD CONSTRAINT `fk_snapshots__s3_id` FOREIGN KEY `fk_snapshots__s3_id` (`s3_id`) REFERENCES `s3` (`id`);

0 commit comments

Comments
 (0)