List of usage examples for org.apache.commons.lang.time StopWatch StopWatch
public StopWatch()
Constructor.
From source file:org.apache.twill.yarn.YarnTwillController.java
@Override protected void doStartUp() { super.doStartUp(); // Submit and poll the status of the yarn application try {/*from w ww .j a va 2s. c o m*/ processController = startUp.call(); YarnApplicationReport report = processController.getReport(); ApplicationId appId = report.getApplicationId(); LOG.debug("Application {} with id {} submitted", appName, appId); YarnApplicationState state = report.getYarnApplicationState(); StopWatch stopWatch = new StopWatch(); stopWatch.start(); stopWatch.split(); long maxTime = TimeUnit.MILLISECONDS.convert(Constants.APPLICATION_MAX_START_SECONDS, TimeUnit.SECONDS); LOG.debug("Checking yarn application status for {} {}", appName, appId); while (!hasRun(state) && stopWatch.getSplitTime() < maxTime) { report = processController.getReport(); state = report.getYarnApplicationState(); LOG.debug("Yarn application status for {} {}: {}", appName, appId, state); TimeUnit.SECONDS.sleep(1); stopWatch.split(); } LOG.info("Yarn application {} {} is in state {}", appName, appId, state); if (state != YarnApplicationState.RUNNING) { LOG.info("Yarn application {} {} is not in running state. Shutting down controller.", appName, appId, Constants.APPLICATION_MAX_START_SECONDS); forceShutDown(); } else { try { URL resourceUrl = URI .create(String.format("http://%s:%d", report.getHost(), report.getRpcPort())) .resolve(TrackerService.PATH).toURL(); resourcesClient = new ResourceReportClient(resourceUrl); } catch (IOException e) { resourcesClient = null; } } } catch (Exception e) { throw Throwables.propagate(e); } }
From source file:org.apache.twill.yarn.YarnTwillController.java
@Override protected synchronized void doShutDown() { if (processController == null) { LOG.warn("No process controller for application that is not submitted."); return;//from w w w . j a v a 2 s .c om } // Stop polling if it is running. stopPollStatus(); // Wait for the stop message being processed try { Uninterruptibles.getUninterruptibly(getStopMessageFuture(), Constants.APPLICATION_MAX_STOP_SECONDS, TimeUnit.SECONDS); } catch (Exception e) { LOG.error("Failed to wait for stop message being processed.", e); // Kill the application through yarn kill(); } // Poll application status from yarn try { StopWatch stopWatch = new StopWatch(); stopWatch.start(); stopWatch.split(); long maxTime = TimeUnit.MILLISECONDS.convert(Constants.APPLICATION_MAX_STOP_SECONDS, TimeUnit.SECONDS); YarnApplicationReport report = processController.getReport(); FinalApplicationStatus finalStatus = report.getFinalApplicationStatus(); ApplicationId appId = report.getApplicationId(); while (finalStatus == FinalApplicationStatus.UNDEFINED && stopWatch.getSplitTime() < maxTime) { LOG.debug("Yarn application final status for {} {}: {}", appName, appId, finalStatus); TimeUnit.SECONDS.sleep(1); stopWatch.split(); finalStatus = processController.getReport().getFinalApplicationStatus(); } LOG.debug("Yarn application {} {} completed with status {}", appName, appId, finalStatus); // Application not finished after max stop time, kill the application if (finalStatus == FinalApplicationStatus.UNDEFINED) { kill(); } } catch (Exception e) { LOG.warn("Exception while waiting for application report: {}", e.getMessage(), e); kill(); } super.doShutDown(); }
From source file:org.apache.whirr.service.hadoop.integration.benchmark.HadoopServiceTeraSortBenchmark.java
private void runTeraGen() throws IOException { int numTaskTrackers = controller.getCluster().getInstances().size() - 1; long bytesPerNode = Long.parseLong(System.getProperty("terasortBytesPerNode", "1000000000")); long rows = numTaskTrackers * (bytesPerNode / 100); StopWatch stopWatch = new StopWatch(); TeraGen teraGen = new TeraGen(); teraGen.setConf(controller.getJobConf()); LOG.info("Starting TeraGen with {} tasktrackers, {} bytes per node, {} rows", new Object[] { numTaskTrackers, bytesPerNode, rows }); stopWatch.start();/*w w w . ja v a 2s . c o m*/ teraGen.run(new String[] { "" + rows, "input" }); stopWatch.stop(); LOG.info("TeraGen took {} ms", stopWatch.getTime()); }
From source file:org.apache.whirr.service.hadoop.integration.benchmark.HadoopServiceTeraSortBenchmark.java
private void runTeraSort() throws Exception { StopWatch stopWatch = new StopWatch(); TeraSort teraSort = new TeraSort(); teraSort.setConf(controller.getJobConf()); LOG.info("Starting TeraSort"); stopWatch.start();//from w w w .j ava 2 s . c om teraSort.run(new String[] { "input", "output" }); stopWatch.stop(); LOG.info("TeraSort took {} ms", stopWatch.getTime()); }
From source file:org.apache.whirr.service.hadoop.integration.benchmark.HadoopServiceTeraSortBenchmark.java
private void runTeraValidate() throws Exception { StopWatch stopWatch = new StopWatch(); TeraValidate teraValidate = new TeraValidate(); teraValidate.setConf(controller.getJobConf()); LOG.info("Starting TeraValidate"); stopWatch.start();//w ww . j ava 2s . c om teraValidate.run(new String[] { "output", "report" }); stopWatch.stop(); LOG.info("TeraValidate took {} ms", stopWatch.getTime()); }
From source file:org.apache.wiki.render.RenderingManagerTest.java
/** * Tests the relative speed of the DOM cache with respect to * page being parsed every single time./*from www . j av a 2 s . c o m*/ * @throws Exception */ public void testCache() throws Exception { m_engine.saveText("TestPage", TEST_TEXT); StopWatch sw = new StopWatch(); System.out.println("DOM cache speed test:"); sw.start(); for (int i = 0; i < 100; i++) { WikiPage page = m_engine.getPage("TestPage"); String pagedata = m_engine.getPureText(page); WikiContext context = new WikiContext(m_engine, page); MarkupParser p = m_manager.getParser(context, pagedata); WikiDocument d = p.parse(); String html = m_manager.getHTML(context, d); assertNotNull("noncached got null response", html); } sw.stop(); System.out.println(" Nocache took " + sw); long nocachetime = sw.getTime(); sw.reset(); sw.start(); for (int i = 0; i < 100; i++) { WikiPage page = m_engine.getPage("TestPage"); String pagedata = m_engine.getPureText(page); WikiContext context = new WikiContext(m_engine, page); String html = m_manager.getHTML(context, pagedata); assertNotNull("cached got null response", html); } sw.stop(); System.out.println(" Cache took " + sw); long speedup = nocachetime / sw.getTime(); System.out.println(" Approx speedup: " + speedup + "x"); }
From source file:org.attoparser.benchmark.AttoParserVSStandardSAXBenchmark.java
public static String standardSaxBenchmark(final String fileName, final int iterations) throws Exception { final SAXParserFactory parserFactory = SAXParserFactory.newInstance(); final SAXParser parser = parserFactory.newSAXParser(); /*// ww w . j a v a 2 s . c om * WARMUP BEGIN */ System.out.println("Warming up phase for SAX STARTED"); for (int i = 0; i < 10000; i++) { InputStream is = null; Reader reader = null; try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); reader = new BufferedReader(new InputStreamReader(is, "ISO-8859-1")); final InputSource inputSource = new InputSource(reader); final BenchmarkStandardSaxContentHandler handler = new BenchmarkStandardSaxContentHandler(); parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler); parser.setProperty("http://xml.org/sax/properties/declaration-handler", handler); parser.parse(inputSource, handler); parser.reset(); handler.getEventCounter(); } finally { try { if (reader != null) reader.close(); } catch (final Exception ignored) { /* ignored */} try { if (is != null) is.close(); } catch (final Exception ignored) { /* ignored */} } } /* * WARMUP END */ System.out.println("Warming up phase for SAX FINISHED"); final StopWatch sw = new StopWatch(); boolean started = false; int eventCounter = 0; for (int i = 0; i < iterations; i++) { InputStream is = null; Reader reader = null; try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); reader = new BufferedReader(new InputStreamReader(is, "ISO-8859-1")); final InputSource inputSource = new InputSource(reader); final BenchmarkStandardSaxContentHandler handler = new BenchmarkStandardSaxContentHandler(); parser.setProperty("http://xml.org/sax/properties/lexical-handler", handler); parser.setProperty("http://xml.org/sax/properties/declaration-handler", handler); if (started) { sw.resume(); } else { started = true; sw.start(); } parser.parse(inputSource, handler); parser.reset(); sw.suspend(); eventCounter = handler.getEventCounter(); } finally { try { if (reader != null) reader.close(); } catch (final Exception ignored) { /* ignored */} try { if (is != null) is.close(); } catch (final Exception ignored) { /* ignored */} } } sw.stop(); return "[" + eventCounter + "] " + sw.toString(); }
From source file:org.attoparser.benchmark.AttoParserVSStandardSAXBenchmark.java
public static String attoParserBenchmark(final String fileName, final int iterations) throws Exception { final IMarkupParser parser = new MarkupParser(MARKUP_PARSING_CONFIG); /*/* ww w. j a v a 2 s . c o m*/ * WARMUP BEGIN */ System.out.println("Warming up phase for ATTO STARTED"); for (int i = 0; i < 10000; i++) { InputStream is = null; Reader reader = null; try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); reader = new BufferedReader(new InputStreamReader(is, "ISO-8859-1")); final BenchmarkMarkupHandler handler = new BenchmarkMarkupHandler(); parser.parse(reader, handler); handler.getEventCounter(); } finally { try { if (reader != null) reader.close(); } catch (final Exception ignored) { /* ignored */} try { if (is != null) is.close(); } catch (final Exception ignored) { /* ignored */} } } /* * WARMUP END */ System.out.println("Warming up phase for ATTO FINISHED"); final StopWatch sw = new StopWatch(); boolean started = false; int eventCounter = 0; for (int i = 0; i < iterations; i++) { InputStream is = null; Reader reader = null; try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); reader = new BufferedReader(new InputStreamReader(is, "ISO-8859-1")); final BenchmarkMarkupHandler benchmarkHandler = new BenchmarkMarkupHandler(); final IMarkupHandler handler = benchmarkHandler; if (started) { sw.resume(); } else { started = true; sw.start(); } parser.parse(reader, handler); sw.suspend(); eventCounter = benchmarkHandler.getEventCounter(); } finally { try { if (reader != null) reader.close(); } catch (final Exception ignored) { /* ignored */} try { if (is != null) is.close(); } catch (final Exception ignored) { /* ignored */} } } sw.stop(); return "[" + eventCounter + "] " + sw.toString(); }
From source file:org.attoparser.benchmark.AttoParserVSStandardSAXBenchmark.java
public static String attoParserHtmlBenchmark(final String fileName, final int iterations) throws Exception { final IMarkupParser parser = new MarkupParser(HTML_MARKUP_PARSING_CONFIG); /*//from w ww.ja v a 2s . com * WARMUP BEGIN */ System.out.println("Warming up phase for ATTO(HTML) STARTED"); for (int i = 0; i < 10000; i++) { InputStream is = null; Reader reader = null; try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); reader = new BufferedReader(new InputStreamReader(is, "ISO-8859-1")); final BenchmarkMarkupHandler handler = new BenchmarkMarkupHandler(); parser.parse(reader, handler); handler.getEventCounter(); } finally { try { if (reader != null) reader.close(); } catch (final Exception ignored) { /* ignored */} try { if (is != null) is.close(); } catch (final Exception ignored) { /* ignored */} } } /* * WARMUP END */ System.out.println("Warming up phase for ATTO(HTML) FINISHED"); final StopWatch sw = new StopWatch(); boolean started = false; int eventCounter = 0; for (int i = 0; i < iterations; i++) { InputStream is = null; Reader reader = null; try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); reader = new BufferedReader(new InputStreamReader(is, "ISO-8859-1")); final BenchmarkMarkupHandler handler = new BenchmarkMarkupHandler(); if (started) { sw.resume(); } else { started = true; sw.start(); } parser.parse(reader, handler); sw.suspend(); eventCounter = handler.getEventCounter(); } finally { try { if (reader != null) reader.close(); } catch (final Exception ignored) { /* ignored */} try { if (is != null) is.close(); } catch (final Exception ignored) { /* ignored */} } } sw.stop(); return "[" + eventCounter + "] " + sw.toString(); }
From source file:org.attoparser.benchmark.AttoParserVSStandardSAXBenchmark.java
public static void attoDOMOutput(final String fileName) throws Exception { final IMarkupParser parser = new MarkupParser(MARKUP_PARSING_CONFIG); InputStream is = null;//from w w w .j av a 2 s .co m Reader reader = null; final StopWatch sw = new StopWatch(); try { is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fileName); reader = new BufferedReader(new InputStreamReader(is, "ISO-8859-1")); sw.start(); final DOMBuilderMarkupHandler handler = new DOMBuilderMarkupHandler(); parser.parse(reader, handler); final Document document = handler.getDocument(); final StringWriter writer = new StringWriter(); DOMWriter.write(document, writer); System.out.println(writer.toString()); sw.stop(); } finally { try { if (reader != null) reader.close(); } catch (final Exception ignored) { /* ignored */} try { if (is != null) is.close(); } catch (final Exception ignored) { /* ignored */} } }