Search in sources :

Example 6 with Profiler

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

the class SecurityGroupManagerImpl2Test method _schedule.

protected void _schedule(final int numVms) {
    System.out.println("Starting");
    List<Long> work = new ArrayList<Long>();
    for (long i = 100; i <= 100 + numVms; i++) {
        work.add(i);
    }
    Profiler profiler = new Profiler();
    profiler.start();
    _sgMgr.scheduleRulesetUpdateToHosts(work, false, null);
    profiler.stop();
    System.out.println("Done " + numVms + " in " + profiler.getDurationInMillis() + " ms");
}
Also used : Profiler(com.cloud.utils.Profiler) ArrayList(java.util.ArrayList)

Example 7 with Profiler

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

the class ClusterManagerImpl method getNotificationTask.

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

        @Override
        protected void runInContext() {
            while (true) {
                synchronized (_notificationMsgs) {
                    try {
                        _notificationMsgs.wait(1000);
                    } catch (final InterruptedException e) {
                    }
                }
                ClusterManagerMessage msg = null;
                while ((msg = getNextNotificationMessage()) != null) {
                    switch(msg.getMessageType()) {
                        case nodeAdded:
                            if (msg.getNodes() != null && msg.getNodes().size() > 0) {
                                final Profiler profiler = new Profiler();
                                profiler.start();
                                notifyNodeJoined(msg.getNodes());
                                profiler.stop();
                                if (profiler.getDurationInMillis() > 1000) {
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug("Notifying management server join event took " + profiler.getDurationInMillis() + " ms");
                                    }
                                } else {
                                    s_logger.warn("Notifying management server join event took " + profiler.getDurationInMillis() + " ms");
                                }
                            }
                            break;
                        case nodeRemoved:
                            if (msg.getNodes() != null && msg.getNodes().size() > 0) {
                                final Profiler profiler = new Profiler();
                                profiler.start();
                                notifyNodeLeft(msg.getNodes());
                                profiler.stop();
                                if (profiler.getDurationInMillis() > 1000) {
                                    if (s_logger.isDebugEnabled()) {
                                        s_logger.debug("Notifying management server leave event took " + profiler.getDurationInMillis() + " ms");
                                    }
                                } else {
                                    s_logger.warn("Notifying management server leave event took " + profiler.getDurationInMillis() + " ms");
                                }
                            }
                            break;
                        case nodeIsolated:
                            notifyNodeIsolated();
                            break;
                        default:
                            assert false;
                            break;
                    }
                }
                try {
                    Thread.sleep(1000);
                } catch (final InterruptedException e) {
                    s_logger.warn("Caught (previously ignored) interrupted exception", e);
                }
            }
        }
    };
}
Also used : ManagedContextRunnable(com.cloud.managed.context.ManagedContextRunnable) Profiler(com.cloud.utils.Profiler)

Example 8 with Profiler

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

the class ClusterManagerImpl method onSendingClusterPdu.

private void onSendingClusterPdu() {
    while (true) {
        final ClusterServicePdu pdu = popOutgoingClusterPdu(1000);
        if (pdu == null) {
            continue;
        }
        ClusterService peerService = null;
        for (int i = 0; i < 2; i++) {
            try {
                peerService = getPeerService(pdu.getDestPeer());
            } catch (final RemoteException e) {
                s_logger.error("Unable to get cluster service on peer : " + pdu.getDestPeer());
            }
            if (peerService != null) {
                s_logger.debug("Popped a PDU from the outgoing cluster pdu queue: " + pdu);
                try {
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Cluster PDU " + getSelfPeerName() + " -> " + pdu.getDestPeer() + ". agent: " + pdu.getAgentId() + ", pdu seq: " + pdu.getSequenceId() + ", pdu ack seq: " + pdu.getAckSequenceId() + ", json: " + pdu.getJsonPackage());
                    }
                    final Profiler profiler = new Profiler();
                    profiler.start();
                    final String strResult = peerService.execute(pdu);
                    profiler.stop();
                    if (s_logger.isDebugEnabled()) {
                        s_logger.debug("Cluster PDU " + getSelfPeerName() + " -> " + pdu.getDestPeer() + " completed. time: " + profiler.getDurationInMillis() + "ms. agent: " + pdu.getAgentId() + ", pdu seq: " + pdu.getSequenceId() + ", pdu ack seq: " + pdu.getAckSequenceId() + ", json: " + pdu.getJsonPackage());
                    }
                    if ("true".equals(strResult)) {
                        break;
                    }
                } catch (final RemoteException e) {
                    invalidatePeerService(pdu.getDestPeer());
                    if (s_logger.isInfoEnabled()) {
                        s_logger.info("Exception on remote execution, peer: " + pdu.getDestPeer() + ", iteration: " + i + ", exception message :" + e.getMessage());
                    }
                }
            }
        }
    }
}
Also used : Profiler(com.cloud.utils.Profiler) RemoteException(java.rmi.RemoteException)

Example 9 with Profiler

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

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<>();
    final List<ManagementServerHostVO> invalidatedNodeList = new ArrayList<>();
    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<>();
    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 regiester 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) SQLException(java.sql.SQLException) 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)

Example 10 with Profiler

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

the class GlobalLock method lock.

public boolean lock(final int timeoutSeconds) {
    int remainingMilliSeconds = timeoutSeconds * 1000;
    final Profiler profiler = new Profiler();
    boolean interrupted = false;
    try {
        while (true) {
            synchronized (this) {
                if (ownerThread != null && ownerThread == Thread.currentThread()) {
                    s_logger.warn("Global lock re-entrance detected");
                    lockCount++;
                    if (s_logger.isTraceEnabled()) {
                        s_logger.trace("lock " + name + " is acquired, lock count :" + lockCount);
                    }
                    return true;
                }
                if (ownerThread != null) {
                    profiler.start();
                    try {
                        wait((timeoutSeconds) * 1000L);
                    } catch (final InterruptedException e) {
                        interrupted = true;
                    }
                    profiler.stop();
                    remainingMilliSeconds -= profiler.getDurationInMillis();
                    if (remainingMilliSeconds < 0) {
                        return false;
                    }
                    continue;
                } else {
                    // take ownership temporarily to prevent others enter into stage of acquiring DB lock
                    ownerThread = Thread.currentThread();
                    addRef();
                }
            }
            if (DbUtil.getGlobalLock(name, remainingMilliSeconds / 1000)) {
                synchronized (this) {
                    lockCount++;
                    holdingStartTick = System.currentTimeMillis();
                    if (s_logger.isTraceEnabled()) {
                        s_logger.trace("lock " + name + " is acquired, lock count :" + lockCount);
                    }
                    return true;
                }
            } else {
                synchronized (this) {
                    ownerThread = null;
                    releaseRef();
                    return false;
                }
            }
        }
    } finally {
        if (interrupted) {
            Thread.currentThread().interrupt();
        }
    }
}
Also used : Profiler(com.cloud.utils.Profiler)

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