Example usage for org.springframework.util StopWatch start

List of usage examples for org.springframework.util StopWatch start

Introduction

In this page you can find the example usage for org.springframework.util StopWatch start.

Prototype

public void start() throws IllegalStateException 

Source Link

Document

Start an unnamed task.

Usage

From source file:com.persistent.cloudninja.scheduler.TenantBlobSizeGenerator.java

@Override
public boolean execute() {
    boolean retVal = true;
    StopWatch watch = new StopWatch();
    try {/* w  ww  . ja  va 2  s. com*/
        watch.start();
        LOGGER.debug("In generator");
        TenantBlobSizeQueue queue = (TenantBlobSizeQueue) getWorkQueue();
        //get all tenantIds
        List<TenantIdMasterEntity> listTenant = tenantIdMasterDao.getAllTenants();
        for (Iterator<TenantIdMasterEntity> iterator = listTenant.iterator(); iterator.hasNext();) {
            TenantIdMasterEntity tenant = (TenantIdMasterEntity) iterator.next();
            String tenantId = tenant.getTenantId();
            //put each tenant Id in queue
            queue.enqueue(tenantId);
            LOGGER.info("Generator : msg added is " + tenantId);
        }
        watch.stop();
        taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(), "GenerateMeterBlobSizeWork",
                "Measure blob size for " + listTenant.size() + " tenants");
    } catch (StorageException e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    }
    return retVal;
}

From source file:org.sventon.cache.logmessagecache.LogMessageCacheUpdater.java

/**
 * Updates the log entry cache with given revision information.
 *
 * @param revisionUpdate The updated revisions.
 *///from   www . ja  va 2s.  c  o m
public void update(final RevisionUpdate revisionUpdate) {
    final RepositoryName repositoryName = revisionUpdate.getRepositoryName();
    final List<LogEntry> revisions = revisionUpdate.getRevisions();

    LOGGER.info(
            "Listener got [" + revisions.size() + "] updated revision(s) for repository: " + repositoryName);

    final StopWatch stopWatch = new StopWatch();
    stopWatch.start();

    try {
        final LogMessageCache logMessageCache = logMessageCacheManager.getCache(repositoryName);
        if (revisionUpdate.isClearCacheBeforeUpdate()) {
            LOGGER.info("Clearing cache before population");
            logMessageCache.clear();
        }
        updateInternal(logMessageCache, revisions);
    } catch (final Exception ex) {
        LOGGER.warn("Could not update cache instance [" + repositoryName + "]", ex);
    }

    stopWatch.stop();
    LOGGER.info("Update completed in [" + stopWatch.getTotalTimeSeconds() + "] seconds");
}

From source file:com.persistent.cloudninja.scheduler.TenantDBBandwidthGenerator.java

@Override
public boolean execute() {
    StopWatch watch = new StopWatch();
    boolean retVal = true;
    try {/*from  www .  j  av  a 2 s  .co  m*/
        watch.start();
        LOGGER.debug("In generator");
        TenantDBBandwidthQueue queue = (TenantDBBandwidthQueue) getWorkQueue();
        Calendar calendar = Calendar.getInstance();
        SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
        dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
        String currentTime = dateFormat.format(calendar.getTime());
        queue.enqueue(currentTime);
        LOGGER.info("Generator : msg added is " + currentTime);
        watch.stop();
        taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(),
                "GenerateMeterTenantDBBandwidthWork", "");
    } catch (StorageException e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    }
    return retVal;
}

From source file:org.olegz.uuid.TimeBasedUUIDGeneratorTests.java

@Test
public void performanceTestSynch() {
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    for (int i = 0; i < 1000000; i++) {
        TimeBasedUUIDGenerator.generateId();
    }/*  w  ww.  j  ava  2  s.  c  om*/
    stopWatch.stop();
    System.out.println("Generated 1000000 UUID (sync) via TimeBasedUUIDGenerator.generateId(): in "
            + stopWatch.getTotalTimeSeconds() + " seconds");

    stopWatch = new StopWatch();
    stopWatch.start();
    for (int i = 0; i < 1000000; i++) {
        UUID.randomUUID();
    }
    stopWatch.stop();
    System.out.println("Generated 1000000 UUID  (sync) via UUID.randomUUID(): in "
            + stopWatch.getTotalTimeSeconds() + " seconds");
}

From source file:com.hd123.oauth2.config.SwaggerConfiguration.java

/**
 * Swagger Springfox configuration.//from   w  ww  . j a  v a2 s  .  co m
 */
@Bean
@Role(ROLE_SUPPORT)
@Profile(UN_PRODUCTION)
@Description("Heading OAuth2 API Documentation")
public Docket swaggerSpringfoxDocket() {
    final boolean debugAble = logger.isDebugEnabled();
    if (debugAble) {
        logger.debug("Starting Swagger");
    }
    final StopWatch watch = new StopWatch();
    watch.start();
    final ApiInfo apiInfo = apiInfo();
    final Docket docket = new Docket(SWAGGER_2).apiInfo(apiInfo).enable(!profileUtil.isProd())
            .enableUrlTemplating(false).forCodeGeneration(true).genericModelSubstitutes(ResponseEntity.class)
            .ignoredParameterTypes(Pageable.class)
            .directModelSubstitute(java.time.LocalDate.class, String.class)
            .directModelSubstitute(java.time.ZonedDateTime.class, Date.class)
            .directModelSubstitute(java.time.LocalDateTime.class, Date.class).useDefaultResponseMessages(false)
            .alternateTypeRules(newRule(
                    typeResolver.resolve(DeferredResult.class,
                            typeResolver.resolve(ResponseEntity.class, WildcardType.class)),
                    typeResolver.resolve(WildcardType.class)))
            .globalResponseMessage(GET,
                    newArrayList(new ResponseMessageBuilder().code(500).message("Internal Server Error")
                            .responseModel(new ModelRef("Error")).build()))
            .select().apis(any()).paths(regex(appProperties.getSwagger().getApiPattern())).build();
    watch.stop();

    if (debugAble) {
        logger.debug("Started Swagger in {} ms", watch.getTotalTimeMillis());
    }

    return docket;
}

From source file:com.persistent.cloudninja.scheduler.TenantBlobSizeProcessor.java

/** 
 * Calculates the blob sizes of private and public container.
 * /* w w  w.  ja  va2  s .c  o m*/
 */
@Override
public boolean execute() {
    boolean retVal = true;
    String tenantId = null;
    long blobSize = 0;
    try {
        LOGGER.debug("In Processor");
        TenantBlobSizeQueue queue = (TenantBlobSizeQueue) getWorkQueue();
        tenantId = queue.dequeue(SchedulerSettings.MessageVisibilityTimeout);
        if (tenantId == null) {
            retVal = false;
            LOGGER.debug("Processor : msg is null");
        } else {
            StopWatch watch = new StopWatch();
            watch.start();
            //get the size of blobs in private container.
            blobSize = storageUtility.getContainerSize("tntp-" + tenantId.toLowerCase());
            //get the size of blobs in public container.
            blobSize = blobSize + storageUtility.getContainerSize("tnts-" + tenantId.toLowerCase());
            LOGGER.debug("Processor : msg is " + tenantId);
            MeteringEntity metering = new MeteringEntity();
            metering.setTenantId(tenantId);

            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            String date = dateFormat.format(calendar.getTime());
            metering.setSnapshotTime(dateFormat.parse(date));
            //set the calculated size
            blobSize = blobSize / 1024;
            metering.setBlobStoreUsage(blobSize);
            meteringDao.add(metering);
            LOGGER.info("Processor : blobSize is " + blobSize);
            watch.stop();
            taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(),
                    "ProcessMeteringBlobSizes", "Measured " + blobSize + " kb for tenant " + tenantId);
        }
    } catch (Exception e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    }
    return retVal;
}

From source file:com.persistent.cloudninja.scheduler.TenantDBSizeProcessor.java

/** 
 * Calculates DB size of tenant DB./*from   w w  w.  j a v a2 s  . co  m*/
 */
@Override
public boolean execute() {

    boolean retVal = true;
    String tenantId = null;
    try {

        LOGGER.debug("In Processor");
        long dbSize = 0;
        TenantDBSizeQueue queue = (TenantDBSizeQueue) getWorkQueue();
        tenantId = queue.dequeue(SchedulerSettings.MessageVisibilityTimeout);
        if (tenantId == null) {
            retVal = false;
            LOGGER.debug("Processor : msg is null");
        } else {
            StopWatch watch = new StopWatch();
            watch.start();
            LOGGER.debug("Processor : msg is " + tenantId);
            dbSize = partitionStatsAndBWUsageDao.getDBSize(tenantId);
            MeteringEntity metering = new MeteringEntity();
            metering.setTenantId(tenantId);

            Calendar calendar = Calendar.getInstance();
            SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.S z");
            dateFormat.setTimeZone(TimeZone.getTimeZone("UTC"));
            String date = dateFormat.format(calendar.getTime());
            metering.setSnapshotTime(dateFormat.parse(date));

            metering.setDatabaseSize(dbSize);
            meteringDao.add(metering);
            LOGGER.info("Processor : dbSize is " + dbSize);
            watch.stop();
            taskCompletionDao.updateTaskCompletionDetails(watch.getTotalTimeSeconds(),
                    "ProcessMeteringTenantDatabaseSize",
                    "Measured " + dbSize + " for tenant " + tenantId + " database");
        }
    } catch (StorageException e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    } catch (ParseException e) {
        retVal = false;
        LOGGER.error(e.getMessage(), e);
    }
    return retVal;
}

From source file:org.olegz.uuid.TimeBasedUUIDGeneratorTests.java

@Test
public void performanceTestAsynch() throws Exception {
    ExecutorService executor = Executors.newFixedThreadPool(100);
    StopWatch stopWatch = new StopWatch();
    stopWatch.start();
    for (int i = 0; i < 1000000; i++) {
        executor.execute(new Runnable() {
            public void run() {
                TimeBasedUUIDGenerator.generateId();
            }//from w  w  w .j  a va2 s.  c  om
        });
    }
    executor.shutdown();
    executor.awaitTermination(10, TimeUnit.SECONDS);
    stopWatch.stop();
    System.out.println("Generated 1000000 UUID (async) via TimeBasedUUIDGenerator.generateId(): in "
            + stopWatch.getTotalTimeSeconds() + " seconds");

    executor = Executors.newFixedThreadPool(100);
    stopWatch = new StopWatch();
    stopWatch.start();
    for (int i = 0; i < 1000000; i++) {
        executor.execute(new Runnable() {
            public void run() {
                UUID.randomUUID();
            }
        });
    }
    executor.shutdown();
    executor.awaitTermination(10, TimeUnit.SECONDS);
    stopWatch.stop();
    System.out.println("Generated 1000000 UUID (async) via UUID.randomUUID(): in "
            + stopWatch.getTotalTimeSeconds() + " seconds");
}

From source file:curly.commons.logging.MethodExecutionAspectInterceptor.java

@Around(value = "execution(* *(..)) && @annotation(loggable)) ", argNames = "joinPoint, loggable")
public Object invoke(ProceedingJoinPoint joinPoint, Loggable loggable) throws Throwable {
    if (executionEnabled) {
        StopWatch watch = new StopWatch(joinPoint.toShortString());
        watch.start();
        try {// www.j  av a  2s.c o  m
            return joinPoint.proceed();
        } finally {
            watch.stop();
            synchronized (this) {
                if (actuatorEnabled && (gaugeService != null)) {
                    String gagueName = "gauge.execution." + joinPoint.getTarget() + "."
                            + joinPoint.getSignature().getName();
                    gaugeService.submit(gagueName, watch.getLastTaskTimeMillis());
                }
                log(loggable.value(), joinPoint.getTarget().getClass(), "Executed method {} in {} ms",
                        joinPoint.getSignature().getName(), watch.getLastTaskTimeMillis());
            }
        }

    }
    return joinPoint.proceed();
}

From source file:org.ngrinder.perftest.service.ConsoleManagerTest.java

@Test
public void testConsoleManagerWhenExceedingLimit() {
    // Get all console
    int initialSize = manager.getAvailableConsoleSize();
    SingleConsole availableConsole = null;
    for (int i = 1; i <= initialSize; i++) {
        availableConsole = manager.getAvailableConsole(ConsolePropertiesFactory.createEmptyConsoleProperties());
    }/* w ww.j  av a  2 s .  c o  m*/
    final SingleConsole lastConsole = availableConsole;
    assertThat(manager.getAvailableConsoleSize(), is(0));
    StopWatch elapseTime = new StopWatch();
    elapseTime.start();
    // Try to get more console, it will take time
    try {
        manager.getAvailableConsole(ConsolePropertiesFactory.createEmptyConsoleProperties());
        fail("should throw Exception");
    } catch (NGrinderRuntimeException e) {
    }
    elapseTime.stop();
    assertThat(elapseTime.getTotalTimeSeconds(), lessThan(3000D));
    // Let's try the case when console is returned back.
    Thread thread = new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                Thread.sleep(1000);
                manager.returnBackConsole("test", lastConsole);
            } catch (InterruptedException e) {
            }

        }
    });
    elapseTime = new StopWatch();
    elapseTime.start();
    thread.start();
    // Try to get more console, it will return console just after console is
    // returned back
    SingleConsole anotherConsole = manager
            .getAvailableConsole(ConsolePropertiesFactory.createEmptyConsoleProperties());
    elapseTime.stop();
    assertThat(elapseTime.getTotalTimeSeconds(), lessThan(3000D));
    assertThat(manager.getAvailableConsoleSize(), is(0));
    manager.returnBackConsole("test", anotherConsole);

    // return console again is always allowed
    manager.returnBackConsole("test", anotherConsole);
    ThreadUtils.sleep(2000);
    assertThat(manager.getAvailableConsoleSize(), is(1));
    assertThat(manager.getConsoleInUse().size(), is(initialSize - 1));
}