Package org.perf4j

Examples of org.perf4j.StopWatch


    return stats;
  }


  public void operateWithFailover(Operation<?> op) throws HectorException {
    final StopWatch stopWatch = new Slf4JStopWatch(perf4jLogger);
    int retries = Math.min(op.failoverPolicy.numRetries, hostPools.size());
    HThriftClient client = null;
    boolean success = false;
    boolean retryable = false;
    Set<CassandraHost> excludeHosts = new HashSet<CassandraHost>();
    // TODO start timer for limiting retry time spent
    while ( !success ) {
      try {
        // TODO how to 'timeout' on this op when underlying pool is exhausted
        client =  getClientFromLBPolicy(excludeHosts);
        Cassandra.Client c = client.getCassandra(op.keyspaceName);
        // Keyspace can be null for some system_* api calls
        if ( !op.credentials.isEmpty() ) {
          c.login(new AuthenticationRequest(op.credentials));
        }

        op.executeAndSetResult(c, client.cassandraHost);
        success = true;
        stopWatch.stop(op.stopWatchTagName + ".success_");
        break;

      } catch (Exception ex) {
        HectorException he = exceptionsTranslator.translate(ex);
        if ( he instanceof HInvalidRequestException || he instanceof HCassandraInternalException ) {
          throw he;
        } else if ( he instanceof HectorTransportException) {
          --retries;
          client.close();
          markHostAsDown(client);
          excludeHosts.add(client.cassandraHost);
          retryable = true;
          if ( retries > 0 ) {
            monitor.incCounter(Counter.RECOVERABLE_TRANSPORT_EXCEPTIONS);
          }
        } else if (he instanceof HTimedOutException || he instanceof HUnavailableException ) {
          // DO NOT drecrement retries, we will be keep retrying on timeouts until it comes back
          retryable = true;
          monitor.incCounter(Counter.RECOVERABLE_TIMED_OUT_EXCEPTIONS);
          client.close();
          // TODO timecheck on how long we've been waiting on timeouts here
          // suggestion per user moores on hector-users
        } else if ( he instanceof PoolExhaustedException ) {
          retryable = true;
          --retries;
          if ( hostPools.size() == 1 ) {
            throw he;
          }
          monitor.incCounter(Counter.POOL_EXHAUSTED);
          excludeHosts.add(client.cassandraHost);
        }
        if ( retries <= 0 || retryable == false) throw he;
        log.error("Could not fullfill request on this host {}", client);
        log.error("Exception: ", he);
        monitor.incCounter(Counter.SKIP_HOST_SUCCESS);
        sleepBetweenHostSkips(op.failoverPolicy);
      } finally {
        if ( !success ) {
          monitor.incCounter(op.failCounter);
          stopWatch.stop(op.stopWatchTagName + ".fail_");
        }
        releaseClient(client);
      }
    }
  }
View Full Code Here


                if (nextStopWatch == null) {
                    throw new NoSuchElementException();
                }
            }

            StopWatch retVal = nextStopWatch;
            nextStopWatch = null;
            return retVal;
        }
View Full Code Here

                        //to indicate that we're done
                        done = true;
                        return null;
                    }

                    StopWatch parsedStopWatch = stopWatchParser.parseStopWatch(message);
                    if (parsedStopWatch != null) {
                        return parsedStopWatch;
                    }
                    //otherwise the message wasn't a valid stopWatch, so let the loop continue to get the next one
                }
View Full Code Here

     *
     * @param matchResult The regex match result
     * @return A new StopWatch that reflects the data from the match result.
     */
    public StopWatch parseStopWatchFromLogMatch(MatchResult matchResult) {
        return new StopWatch(Long.parseLong(matchResult.group(1)) /*start time*/,
                             Long.parseLong(matchResult.group(2)) /*elapsed time*/,
                             matchResult.group(3) /*tag*/,
                             matchResult.group(4) /*message, may be null*/);
    }
View Full Code Here

                throw new NoSuchElementException();
            }
        }

        //before I return, clear the state of the variables used to determine the next value.
        StopWatch retVal = nextStopWatch;
        hasNext = null;
        nextStopWatch = null;
        return retVal;
    }
View Full Code Here

    }

    public void testThreeDataPoints() throws Exception {
        GoogleChartGenerator chart = new GoogleChartGenerator();

        StopWatch stopWatch = new StopWatch(START_TIME + 2000L, 2000L, "tag", null);
        GroupedTimingStatistics statistics = new GroupedTimingStatistics();
        statistics.setStartTime(START_TIME);
        statistics.setStopTime(START_TIME + 30000L);
        chart.appendData(statistics.addStopWatch(stopWatch));

        stopWatch = new StopWatch(START_TIME + 32000L, 3000L, "tag", null);
        statistics = new GroupedTimingStatistics();
        statistics.setStartTime(START_TIME + 30000L);
        statistics.setStopTime(START_TIME + 60000L);
        chart.appendData(statistics.addStopWatch(stopWatch));

        stopWatch = new StopWatch(START_TIME + 62000L, 1500L, "tag", null);
        statistics = new GroupedTimingStatistics();
        statistics.setStartTime(START_TIME + 60000L);
        statistics.setStopTime(START_TIME + 90000L);
        chart.appendData(statistics.addStopWatch(stopWatch));
View Full Code Here

    public void testTwoSeriesThreeDataPoints() throws Exception {
        GoogleChartGenerator chart = new GoogleChartGenerator();
        GoogleChartGenerator tpsChart = new GoogleChartGenerator(StatsValueRetriever.TPS_VALUE_RETRIEVER);

        StopWatch watch1 = new StopWatch(START_TIME + 2000L, 2000L, "tag1", null);
        StopWatch watch2 = new StopWatch(START_TIME + 2000L, 1000L, "tag2", null);
        GroupedTimingStatistics statistics = new GroupedTimingStatistics();
        statistics.setStartTime(START_TIME);
        statistics.setStopTime(START_TIME + 30000L);
        statistics.addStopWatch(watch1).addStopWatch(watch2);
        chart.appendData(statistics);
        tpsChart.appendData(statistics);

        watch1 = new StopWatch(START_TIME + 32000L, 3000L, "tag1", null);
        watch2 = new StopWatch(START_TIME + 32000L, 2500L, "tag2", null);
        StopWatch watch2b = new StopWatch(START_TIME + 32000L, 2000L, "tag2", null);
        statistics = new GroupedTimingStatistics();
        statistics.setStartTime(START_TIME + 30000L);
        statistics.setStopTime(START_TIME + 60000L);
        statistics.addStopWatch(watch1).addStopWatch(watch2).addStopWatch(watch2b);
        chart.appendData(statistics);
        tpsChart.appendData(statistics);

        watch1 = new StopWatch(START_TIME + 62000L, 1500L, "tag1", null);
        statistics = new GroupedTimingStatistics();
        statistics.setStartTime(START_TIME + 60000L);
        statistics.setStopTime(START_TIME + 90000L);
        statistics.addStopWatch(watch1);
        chart.appendData(statistics);
View Full Code Here

public class StopWatchParserTest extends TestCase {

    public void testStopWatchParser() throws Exception {
        StopWatchParser parser = new StopWatchParser();

        StopWatch stopWatch = new StopWatch(123, 456, "tag", "message");
        assertEquals(stopWatch, parser.parseStopWatch(stopWatch.toString()));

        stopWatch = new StopWatch(789, 101112, "tag2", null);
        assertEquals(stopWatch, parser.parseStopWatch(stopWatch.toString()));

        assertNull(parser.parseStopWatch("not a stop watch string"));

        assertNull(parser.match("not a stop watch string"));
    }
View Full Code Here

        logger.setAdditive(false);
        logger.setLevel(Level.INFO);
        appender.start();

        for (int i = 0; i < 1000; i++) {
            StopWatch stopWatch = new StopWatch("testOverflow");
            Math.random(); //this should happen super fast, faster than the appender's Dispatcher thread can drain
            logger.info(stopWatch.stop());
        }

        //again close the appender
        appender.stop();
        assertTrue("Expected some stop watch messages to get discarded", appender.getNumDiscardedMessages() > 0);
View Full Code Here

        Thread.sleep(50); //need to sleep because notification is sent in a separate thread.
        assertNull(notificationListener.lastReceivedNotification);

        //add a stop watch that should make the mean be too high, causing a notification to be sent
        GroupedTimingStatistics badStats = groupedTimingStats.clone();
        badStats.addStopWatch(new StopWatch(groupedTimingStats.getStartTime(), 100000L, "tag", "message"));
        mBean.updateCurrentTimingStatistics(badStats);
        Thread.sleep(50);
        assertEquals(StatisticsExposingMBean.OUT_OF_RANGE_NOTIFICATION_TYPE,
                     notificationListener.lastReceivedNotification.getType());
        notificationListener.lastReceivedNotification = null;
View Full Code Here

TOP

Related Classes of org.perf4j.StopWatch

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.