Search in sources :

Example 16 with Profiler

use of com.cloud.utils.Profiler in project cosmic by MissionCriticalCloud.

the class ClusterManagerImpl method getHeartbeatTask.

private Runnable getHeartbeatTask() {
    return new ManagedContextRunnable() {

        @Override
        protected void runInContext() {
            final TransactionLegacy txn = TransactionLegacy.open("ClusterHeartbeat");
            try {
                final Profiler profiler = new Profiler();
                final Profiler profilerHeartbeatUpdate = new Profiler();
                final Profiler profilerPeerScan = new Profiler();
                try {
                    profiler.start();
                    profilerHeartbeatUpdate.start();
                    txn.transitToUserManagedConnection(getHeartbeatConnection());
                    if (s_logger.isTraceEnabled()) {
                        s_logger.trace("Cluster manager heartbeat update, id:" + _mshostId);
                    }
                    _mshostDao.update(_mshostId, _runId, DateUtil.currentGMTTime());
                    profilerHeartbeatUpdate.stop();
                    profilerPeerScan.start();
                    if (s_logger.isTraceEnabled()) {
                        s_logger.trace("Cluster manager peer-scan, id:" + _mshostId);
                    }
                    if (!_peerScanInited) {
                        _peerScanInited = true;
                        initPeerScan();
                    }
                    peerScan();
                    profilerPeerScan.stop();
                } catch (final SQLException e) {
                    s_logger.error("Unexpected exception in cluster heartbeat", e);
                    if (isRootCauseConnectionRelated(e.getCause())) {
                        invalidHeartbeatConnection();
                    }
                } finally {
                    profiler.stop();
                    if (profiler.getDurationInMillis() >= HeartbeatInterval.value()) {
                        if (s_logger.isDebugEnabled()) {
                            s_logger.debug("Management server heartbeat takes too long to finish. profiler: " + profiler.toString() + ", profilerHeartbeatUpdate: " + profilerHeartbeatUpdate.toString() + ", profilerPeerScan: " + profilerPeerScan.toString());
                        }
                    }
                }
            } catch (final CloudRuntimeException e) {
                s_logger.error("Runtime DB exception ", e.getCause());
                if (e.getCause() instanceof ClusterInvalidSessionException) {
                    s_logger.error("Invalid cluster session found, fence it");
                    queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeIsolated));
                }
                if (isRootCauseConnectionRelated(e.getCause())) {
                    invalidHeartbeatConnection();
                }
            } catch (final ActiveFencingException e) {
                queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeIsolated));
            } finally {
                txn.transitToAutoManagedConnection(TransactionLegacy.CLOUD_DB);
                txn.close("ClusterHeartbeat");
            }
        }
    };
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ManagedContextRunnable(com.cloud.managed.context.ManagedContextRunnable) Profiler(com.cloud.utils.Profiler) SQLException(java.sql.SQLException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 17 with Profiler

use of com.cloud.utils.Profiler in project cloudstack by apache.

the class SynchronousListener method waitFor.

public synchronized Answer[] waitFor(int s) throws InterruptedException {
    if (_disconnected) {
        return null;
    }
    if (_answers != null) {
        return _answers;
    }
    Profiler profiler = new Profiler();
    profiler.start();
    if (s <= 0) {
        wait();
    } else {
        int ms = s * 1000;
        wait(ms);
    }
    profiler.stop();
    if (s_logger.isTraceEnabled()) {
        s_logger.trace("Synchronized command - sending completed, time: " + profiler.getDurationInMillis() + ", answer: " + (_answers != null ? _answers[0].toString() : "null"));
    }
    return _answers;
}
Also used : Profiler(com.cloud.utils.Profiler)

Example 18 with Profiler

use of com.cloud.utils.Profiler in project cloudstack by apache.

the class SecurityGroupQueueTest method testNumJobsEqToNumVms2.

protected void testNumJobsEqToNumVms2(int numProducers, int maxVmId) {
    queue.clear();
    Thread[] pThreads = new Thread[numProducers];
    Producer[] producers = new Producer[numProducers];
    int numProduced = 0;
    Profiler p = new Profiler();
    p.start();
    for (int i = 0; i < numProducers; i++) {
        producers[i] = new Producer(maxVmId);
        pThreads[i] = new Thread(producers[i]);
        numProduced += i + 1;
        pThreads[i].start();
    }
    for (int i = 0; i < numProducers; i++) {
        try {
            pThreads[i].join();
        } catch (InterruptedException ie) {
            ie.printStackTrace();
        }
    }
    p.stop();
    System.out.println("Num Vms= " + maxVmId + " Queue size = " + queue.size() + " time=" + p.getDurationInMillis() + " ms");
    assertEquals(maxVmId, queue.size());
}
Also used : Profiler(com.cloud.utils.Profiler)

Example 19 with Profiler

use of com.cloud.utils.Profiler in project cloudstack by apache.

the class SecurityGroupManagerImpl2 method scheduleRulesetUpdateToHosts.

@Override
public void scheduleRulesetUpdateToHosts(List<Long> affectedVms, boolean updateSeqno, Long delayMs) {
    if (affectedVms.size() == 0) {
        return;
    }
    if (_schedulerDisabled) {
        s_logger.debug("Security Group Mgr v2: scheduler disabled, doing nothing for " + affectedVms.size() + " vms");
        return;
    }
    Set<Long> workItems = new TreeSet<Long>();
    workItems.addAll(affectedVms);
    workItems.removeAll(_disabledVms);
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Security Group Mgr v2: scheduling ruleset updates for " + affectedVms.size() + " vms " + " (unique=" + workItems.size() + "), current queue size=" + _workQueue.size());
    }
    Profiler p = new Profiler();
    p.start();
    int updated = 0;
    if (updateSeqno) {
        updated = _rulesetLogDao.createOrUpdate(workItems);
        if (updated < workItems.size()) {
            throw new CloudRuntimeException("Failed to create ruleset log entries");
        }
    }
    int newJobs = _workQueue.submitWorkForVms(workItems);
    _mBean.logScheduledDetails(workItems);
    p.stop();
    if (s_logger.isDebugEnabled()) {
        s_logger.debug("Security Group Mgr v2: done scheduling ruleset updates for " + workItems.size() + " vms: num new jobs=" + newJobs + " num rows insert or updated=" + updated + " time taken=" + p.getDurationInMillis());
    }
}
Also used : Profiler(com.cloud.utils.Profiler) TreeSet(java.util.TreeSet) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 20 with Profiler

use of com.cloud.utils.Profiler in project cloudstack by apache.

the class ClusterManagerImpl method peerScan.

private void peerScan() throws ActiveFencingException {
    final Date cutTime = DateUtil.currentGMTTime();
    final Profiler profiler = new Profiler();
    profiler.start();
    final Profiler profilerQueryActiveList = new Profiler();
    profilerQueryActiveList.start();
    final List<ManagementServerHostVO> currentList = _mshostDao.getActiveList(new Date(cutTime.getTime() - HeartbeatThreshold.value()));
    profilerQueryActiveList.stop();
    final Profiler profilerSyncClusterInfo = new Profiler();
    profilerSyncClusterInfo.start();
    final List<ManagementServerHostVO> removedNodeList = new ArrayList<ManagementServerHostVO>();
    final List<ManagementServerHostVO> invalidatedNodeList = new ArrayList<ManagementServerHostVO>();
    if (_mshostId != null) {
        if (_mshostPeerDao.countStateSeenInPeers(_mshostId, _runId, ManagementServerHost.State.Down) > 0) {
            final String msg = "We have detected that at least one management server peer reports that this management server is down, perform active fencing to avoid split-brain situation";
            s_logger.error(msg);
            throw new ActiveFencingException(msg);
        }
        // only if we have already attached to cluster, will we start to check leaving nodes
        for (final Map.Entry<Long, ManagementServerHostVO> entry : _activePeers.entrySet()) {
            final ManagementServerHostVO current = getInListById(entry.getKey(), currentList);
            if (current == null) {
                if (entry.getKey().longValue() != _mshostId.longValue()) {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Detected management node left, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP());
                    }
                    removedNodeList.add(entry.getValue());
                }
            } else {
                if (current.getRunid() == 0) {
                    if (entry.getKey().longValue() != _mshostId.longValue()) {
                        if (s_logger.isDebugEnabled()) {
                            s_logger.debug("Detected management node left because of invalidated session, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP());
                        }
                        invalidatedNodeList.add(entry.getValue());
                    }
                } else {
                    if (entry.getValue().getRunid() != current.getRunid()) {
                        if (s_logger.isDebugEnabled()) {
                            s_logger.debug("Detected management node left and rejoined quickly, id:" + entry.getKey() + ", nodeIP:" + entry.getValue().getServiceIP());
                        }
                        entry.getValue().setRunid(current.getRunid());
                    }
                }
            }
        }
    }
    profilerSyncClusterInfo.stop();
    final Profiler profilerInvalidatedNodeList = new Profiler();
    profilerInvalidatedNodeList.start();
    // process invalidated node list
    if (invalidatedNodeList.size() > 0) {
        for (final ManagementServerHostVO mshost : invalidatedNodeList) {
            _activePeers.remove(mshost.getId());
            try {
                JmxUtil.unregisterMBean("ClusterManager", "Node " + mshost.getId());
            } catch (final Exception e) {
                s_logger.warn("Unable to deregiester cluster node from JMX monitoring due to exception " + e.toString());
            }
        }
        queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeRemoved, invalidatedNodeList));
    }
    profilerInvalidatedNodeList.stop();
    final Profiler profilerRemovedList = new Profiler();
    profilerRemovedList.start();
    // process removed node list
    final Iterator<ManagementServerHostVO> it = removedNodeList.iterator();
    while (it.hasNext()) {
        final ManagementServerHostVO mshost = it.next();
        if (!pingManagementNode(mshost)) {
            s_logger.warn("Management node " + mshost.getId() + " is detected inactive by timestamp and also not pingable");
            _activePeers.remove(mshost.getId());
            try {
                JmxUtil.unregisterMBean("ClusterManager", "Node " + mshost.getId());
            } catch (final Exception e) {
                s_logger.warn("Unable to deregiester cluster node from JMX monitoring due to exception " + e.toString());
            }
        } else {
            s_logger.info("Management node " + mshost.getId() + " is detected inactive by timestamp but is pingable");
            it.remove();
        }
    }
    if (removedNodeList.size() > 0) {
        queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeRemoved, removedNodeList));
    }
    profilerRemovedList.stop();
    final List<ManagementServerHostVO> newNodeList = new ArrayList<ManagementServerHostVO>();
    for (final ManagementServerHostVO mshost : currentList) {
        if (!_activePeers.containsKey(mshost.getId())) {
            _activePeers.put(mshost.getId(), mshost);
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("Detected management node joined, id:" + mshost.getId() + ", nodeIP:" + mshost.getServiceIP());
            }
            newNodeList.add(mshost);
            try {
                JmxUtil.registerMBean("ClusterManager", "Node " + mshost.getId(), new ClusterManagerMBeanImpl(this, mshost));
            } catch (final Exception e) {
                s_logger.warn("Unable to register cluster node into JMX monitoring due to exception " + ExceptionUtil.toString(e));
            }
        }
    }
    if (newNodeList.size() > 0) {
        queueNotification(new ClusterManagerMessage(ClusterManagerMessage.MessageType.nodeAdded, newNodeList));
    }
    profiler.stop();
    if (profiler.getDurationInMillis() >= HeartbeatInterval.value()) {
        if (s_logger.isDebugEnabled()) {
            s_logger.debug("Peer scan takes too long to finish. profiler: " + profiler.toString() + ", profilerQueryActiveList: " + profilerQueryActiveList.toString() + ", profilerSyncClusterInfo: " + profilerSyncClusterInfo.toString() + ", profilerInvalidatedNodeList: " + profilerInvalidatedNodeList.toString() + ", profilerRemovedList: " + profilerRemovedList.toString());
        }
    }
}
Also used : ArrayList(java.util.ArrayList) Date(java.util.Date) SQLNonTransientException(java.sql.SQLNonTransientException) ConfigurationException(javax.naming.ConfigurationException) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException) ConnectException(java.net.ConnectException) SQLRecoverableException(java.sql.SQLRecoverableException) IOException(java.io.IOException) RemoteException(java.rmi.RemoteException) Profiler(com.cloud.utils.Profiler) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

Profiler (com.cloud.utils.Profiler)21 CloudRuntimeException (com.cloud.utils.exception.CloudRuntimeException)5 IOException (java.io.IOException)4 RemoteException (java.rmi.RemoteException)4 ArrayList (java.util.ArrayList)4 ManagedContextRunnable (com.cloud.managed.context.ManagedContextRunnable)2 TransactionLegacy (com.cloud.utils.db.TransactionLegacy)2 ConnectException (java.net.ConnectException)2 SQLException (java.sql.SQLException)2 SQLNonTransientException (java.sql.SQLNonTransientException)2 SQLRecoverableException (java.sql.SQLRecoverableException)2 Date (java.util.Date)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 ConfigurationException (javax.naming.ConfigurationException)2 ManagedContextRunnable (org.apache.cloudstack.managed.context.ManagedContextRunnable)2 HttpException (org.apache.commons.httpclient.HttpException)2 TreeSet (java.util.TreeSet)1