Search in sources :

Example 1 with Profiler

use of com.cloud.utils.Profiler in project CloudStack-archive by CloudStack-extras.

the class TestProfiler method testProfiler.

public void testProfiler() {
    s_logger.info("testProfiler() started");
    Profiler pf = new Profiler();
    pf.start();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
    }
    pf.stop();
    s_logger.info("Duration : " + pf.getDuration());
    Assert.assertTrue(pf.getDuration() >= 1000);
    s_logger.info("testProfiler() stopped");
}
Also used : Profiler(com.cloud.utils.Profiler)

Example 2 with Profiler

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

the class GlobalLock method lock.

public boolean lock(int timeoutSeconds) {
    int remainingMilliSeconds = timeoutSeconds * 1000;
    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 (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)

Example 3 with Profiler

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

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.transitToAutoManagedConnection(TransactionLegacy.CLOUD_DB);
                    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();
                } 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));
            } catch (final Throwable e) {
                s_logger.error("Unexpected exception in cluster heartbeat", e);
                if (isRootCauseConnectionRelated(e.getCause())) {
                    invalidHeartbeatConnection();
                }
            } finally {
                txn.close("ClusterHeartbeat");
            }
        }
    };
}
Also used : TransactionLegacy(com.cloud.utils.db.TransactionLegacy) ManagedContextRunnable(org.apache.cloudstack.managed.context.ManagedContextRunnable) Profiler(com.cloud.utils.Profiler) CloudRuntimeException(com.cloud.utils.exception.CloudRuntimeException)

Example 4 with Profiler

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

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) {
                    try {
                        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;
                        }
                    } catch (final Throwable e) {
                        s_logger.warn("Unexpected exception during cluster notification. ", e);
                    }
                }
                try {
                    Thread.sleep(1000);
                } catch (final InterruptedException e) {
                }
            }
        }
    };
}
Also used : ManagedContextRunnable(org.apache.cloudstack.managed.context.ManagedContextRunnable) Profiler(com.cloud.utils.Profiler)

Example 5 with Profiler

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

the class ClusterServiceServletImpl method executePostMethod.

private String executePostMethod(final HttpClient client, final PostMethod method) {
    int response = 0;
    String result = null;
    try {
        final Profiler profiler = new Profiler();
        profiler.start();
        response = client.executeMethod(method);
        if (response == HttpStatus.SC_OK) {
            result = method.getResponseBodyAsString();
            profiler.stop();
            if (s_logger.isDebugEnabled()) {
                s_logger.debug("POST " + _serviceUrl + " response :" + result + ", responding time: " + profiler.getDurationInMillis() + " ms");
            }
        } else {
            profiler.stop();
            s_logger.error("Invalid response code : " + response + ", from : " + _serviceUrl + ", method : " + method.getParameter("method") + " responding time: " + profiler.getDurationInMillis());
        }
    } catch (final HttpException e) {
        s_logger.error("HttpException from : " + _serviceUrl + ", method : " + method.getParameter("method"));
    } catch (final IOException e) {
        s_logger.error("IOException from : " + _serviceUrl + ", method : " + method.getParameter("method"));
    } catch (final Throwable e) {
        s_logger.error("Exception from : " + _serviceUrl + ", method : " + method.getParameter("method") + ", exception :", e);
    } finally {
        method.releaseConnection();
    }
    return result;
}
Also used : Profiler(com.cloud.utils.Profiler) HttpException(org.apache.commons.httpclient.HttpException) IOException(java.io.IOException)

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