Search in sources :

Example 11 with Profiler

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

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(((long) timeoutSeconds) * 1000L);
                    } catch (InterruptedException e) {
                        interrupted = true;
                    }
                    profiler.stop();
                    remainingMilliSeconds -= profiler.getDuration();
                    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 12 with Profiler

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

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.getDuration() + " ms");
}
Also used : Profiler(com.cloud.utils.Profiler) ArrayList(java.util.ArrayList)

Example 13 with Profiler

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

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.getDuration() + " ms");
    assertEquals(maxVmId, queue.size());
}
Also used : Profiler(com.cloud.utils.Profiler)

Example 14 with Profiler

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

the class SynchronousListener method waitFor.

public synchronized Answer[] waitFor(final int s) throws InterruptedException {
    if (_disconnected) {
        return null;
    }
    if (_answers != null) {
        return _answers;
    }
    final Profiler profiler = new Profiler();
    profiler.start();
    if (s <= 0) {
        wait();
    } else {
        final 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 15 with Profiler

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

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"));
    } 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