List of usage examples for org.apache.commons.lang.time StopWatch toString
public String toString()
Gets a summary of the time that the stopwatch recorded as a string.
The format used is ISO8601-like, hours:minutes:seconds.milliseconds.
From source file:nl.utwente.bigdata.OutgoingLinks.java
public static void main(String[] args) throws Exception { // Tijd bijhouden StopWatch timer = new StopWatch(); timer.start();// w w w .j a v a 2s . co m // HashMap van PageRanks initializeren //pageRanks = new HashMap<String, Float>(); Configuration conf = new Configuration(); String[] otherArgs = new GenericOptionsParser(conf, args).getRemainingArgs(); if (otherArgs.length < 2) { System.err.println("Usage: pageRank <in> [<in>...] <out>"); System.exit(2); } Job job = new Job(conf, "Twitter Reader"); job.setJarByClass(OutgoingLinks.class); job.setMapperClass(OutgoingLinksMapper.class); job.setReducerClass(OutgoingLinksReducer.class); job.setOutputKeyClass(Text.class); job.setOutputValueClass(Text.class); for (int i = 0; i < otherArgs.length - 1; ++i) { FileInputFormat.addInputPath(job, new Path(otherArgs[i])); } FileOutputFormat.setOutputPath(job, new Path(otherArgs[otherArgs.length - 1])); boolean succesful = job.waitForCompletion(true); if (succesful) { timer.stop(); System.out.println("Elapsed " + timer.toString()); //System.exit(0); } else { //System.exit(1); } }
From source file:org.apache.hadoop.hbase.regionserver.IdxRegionIndexManager.java
/** * Fills the index. Scans the region for latest rows and sends key values * to the matching index builder/* w w w . ja v a 2 s. c o m*/ * * @param builders the map of builders keyed by column:qualifer pair * @return the keyset (a fresh set) * @throws IOException may be thrown by the scan */ private ObjectArrayList<KeyValue> fillIndex(Map<Pair<byte[], byte[]>, CompleteIndexBuilder> builders) throws IOException { ObjectArrayList<KeyValue> newKeys = this.keys == null ? new ObjectArrayList<KeyValue>() : // in case we already have keys in the store try to guess the new size new ObjectArrayList<KeyValue>(this.keys.size() + this.region.averageNumberOfMemStoreSKeys() * 2); StopWatch stopWatch = new StopWatch(); stopWatch.start(); InternalScanner scanner = region.getScanner(createScan(builders.keySet())); try { boolean moreRows; int id = 0; do { List<KeyValue> nextRow = new ArrayList<KeyValue>(); moreRows = scanner.next(nextRow); if (nextRow.size() > 0) { KeyValue firstOnRow = KeyValue.createFirstOnRow(nextRow.get(0).getRow()); newKeys.add(firstOnRow); // add keyvalue to the heapsize heapSize += firstOnRow.heapSize(); for (KeyValue keyValue : nextRow) { try { CompleteIndexBuilder idx = builders .get(Pair.of(keyValue.getFamily(), keyValue.getQualifier())); // we must have an index since we've limited the // scan to include only indexed columns assert idx != null; if (LOG.isTraceEnabled()) { LOG.trace("About to add kv: [" + keyValue + "] with id " + id); } idx.addKeyValue(keyValue, id); } catch (Exception e) { LOG.error("Failed to add " + keyValue + " to the index", e); } } id++; } } while (moreRows); stopWatch.stop(); LOG.info("Filled indices for region: '" + region.getRegionNameAsString() + "' with " + id + " entries in " + stopWatch.toString()); return newKeys; } finally { scanner.close(); } }
From source file:org.apache.spark.simr.Simr.java
public void startWorker() throws IOException { StopWatch sw = new StopWatch(); sw.start();/*from w w w . j a v a2 s . c o m*/ UrlCoresTuple uc = getMasterURL(); sw.stop(); if (uc == null) { log.warn(String.format("getMasterURL timed out in startWorker after "), sw.toString()); return; } int uniqueId = context.getTaskAttemptID().getTaskID().getId(); int maxCores = uc.cores; String masterUrl = uc.url; String[] exList = new String[] { masterUrl, Integer.toString(uniqueId), getLocalIP(), Integer.toString(maxCores) }; redirectOutput("worker" + uniqueId); org.apache.spark.executor.CoarseGrainedExecutorBackend.main(exList); }
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(); /*/*from w w w . j ava 2 s .c o m*/ * 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); /*//from w w w . j a va 2s .co 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 ww w .ja va 2s . c o m * 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.cesecore.audit.log.SecurityEventsLoggerSessionBeanTest.java
@Test public void test04SecureMultipleLog() throws Exception { log.trace(">test03SecureMultipleLog"); final int THREADS = 50; final int WORKERS = 400; final int TIMEOUT_MS = 30000; final ThreadPoolExecutor workers = (ThreadPoolExecutor) Executors.newFixedThreadPool(THREADS); final StopWatch time = new StopWatch(); time.start();/*from w w w. j a v a 2 s . c o m*/ for (int i = 0; i < WORKERS; i++) { workers.execute(new Runnable() { // NOPMD: this is a test, not a JEE application @Override public void run() { try { securityEventsLogger.log(roleMgmgToken, EventTypes.AUTHENTICATION, EventStatus.SUCCESS, ModuleTypes.SECURITY_AUDIT, ServiceTypes.CORE); } catch (AuthorizationDeniedException e) { fail("should be authorized"); } } }); } while (workers.getCompletedTaskCount() < WORKERS && time.getTime() < TIMEOUT_MS) { Thread.sleep(250); } time.stop(); final long completedTaskCount = workers.getCompletedTaskCount(); log.info("securityEventsLogger.log: " + completedTaskCount + " completed in " + time.toString() + " using " + THREADS + " threads."); workers.shutdown(); for (final String logDeviceId : securityEventsAuditor.getQuerySupportingLogDevices()) { final AuditLogValidationReport report = securityEventsAuditor.verifyLogsIntegrity(roleMgmgToken, new Date(), logDeviceId); assertNotNull(report); final StringBuilder strBuilder = new StringBuilder(); for (final AuditLogReportElem error : report.errors()) { strBuilder.append(String.format("invalid sequence: %d %d\n", error.getFirst(), error.getSecond())); for (final String reason : error.getReasons()) { strBuilder.append(String.format("Reason: %s\n", reason)); } } assertTrue("validation report: " + strBuilder.toString(), (report.warnings().size() == 1 || report.warnings().size() == 0) && report.errors().size() == 0); } log.trace("<test03SecureMultipleLog"); }
From source file:org.deeplearning4j.iterativereduce.runtime.yarn.client.Client.java
/** * TODO: consider the scenarios where we dont get enough containers * - we need to re-submit the job till we get the containers alloc'd * // w w w.jav a 2 s. c o m */ @Override public int run(String[] args) throws Exception { //System.out.println("IR: Client.run() [start]"); if (args.length < 1) LOG.info("No configuration file specified, using default (" + ConfigFields.DEFAULT_CONFIG_FILE + ")"); long startTime = System.currentTimeMillis(); String configFile = (args.length < 1) ? ConfigFields.DEFAULT_CONFIG_FILE : args[0]; Properties props = new Properties(); Configuration conf = getConf(); try { FileInputStream fis = new FileInputStream(configFile); props.load(fis); } catch (FileNotFoundException ex) { throw ex; // TODO: be nice } catch (IOException ex) { throw ex; // TODO: be nice } // Make sure we have some bare minimums ConfigFields.validateConfig(props); if (LOG.isDebugEnabled()) { LOG.debug("Loaded configuration: "); for (Map.Entry<Object, Object> entry : props.entrySet()) { LOG.debug(entry.getKey() + "=" + entry.getValue()); } } // TODO: make sure input file(s), libs, etc. actually exist! // Ensure our input path exists Path p = new Path(props.getProperty(ConfigFields.APP_INPUT_PATH)); FileSystem fs = FileSystem.get(conf); if (!fs.exists(p)) throw new FileNotFoundException("Input path not found: " + p.toString() + " (in " + fs.getUri() + ")"); LOG.info("Using input path: " + p.toString()); // Connect ResourceManagerHandler rmHandler = new ResourceManagerHandler(conf, null); rmHandler.getClientResourceManager(); // Create an Application request/ID ApplicationId appId = rmHandler.getApplicationId(); // Our AppId String appName = props.getProperty(ConfigFields.APP_NAME, ConfigFields.DEFAULT_APP_NAME).replace(' ', '_'); LOG.info("Got an application, id=" + appId + ", appName=" + appName); // Copy resources to [HD]FS LOG.debug("Copying resources to filesystem"); Utils.copyLocalResourcesToFs(props, conf, appId, appName); // Local resources Utils.copyLocalResourceToFs(configFile, ConfigFields.APP_CONFIG_FILE, conf, appId, appName); // Config file try { Utils.copyLocalResourceToFs("log4j.properties", "log4j.properties", conf, appId, appName); // Log4j } catch (FileNotFoundException ex) { LOG.warn("log4j.properties file not found"); } // Create our context List<String> commands = Utils.getMasterCommand(conf, props); Map<String, LocalResource> localResources = Utils.getLocalResourcesForApplication(conf, appId, appName, props, LocalResourceVisibility.APPLICATION); // Submit app rmHandler.submitApplication(appId, appName, Utils.getEnvironment(conf, props), localResources, commands, Integer.parseInt(props.getProperty(ConfigFields.YARN_MEMORY, "512"))); /* * TODO: * - look at updating this code region to make sure job is submitted! * */ StopWatch watch = new StopWatch(); watch.start(); // Wait for app to complete while (true) { Thread.sleep(2000); ApplicationReport report = rmHandler.getApplicationReport(appId); LOG.info("IterativeReduce report: " + " appId=" + appId.getId() + ", state: " + report.getYarnApplicationState().toString() + ", Running Time: " + watch.toString()); //report.getDiagnostics() if (YarnApplicationState.FINISHED == report.getYarnApplicationState()) { LOG.info("Application finished in " + (System.currentTimeMillis() - startTime) + "ms"); if (FinalApplicationStatus.SUCCEEDED == report.getFinalApplicationStatus()) { LOG.info("Application completed succesfully."); return 0; } else { LOG.info("Application completed with en error: " + report.getDiagnostics()); return -1; } } else if (YarnApplicationState.FAILED == report.getYarnApplicationState() || YarnApplicationState.KILLED == report.getYarnApplicationState()) { LOG.info("Application completed with a failed or killed state: " + report.getDiagnostics()); return -1; } } }
From source file:org.jasypt.digest.PooledStandardStringDigesterThreadedTest.java
public static void main(String[] args) { try {// w ww . j a v a 2s . c o m final int numThreads = Integer.valueOf(args[0]).intValue(); final int numIters = Integer.valueOf(args[1]).intValue(); final int poolSize = Integer.valueOf(args[2]).intValue(); PooledStandardStringDigesterThreadedTest test = new PooledStandardStringDigesterThreadedTest(numThreads, numIters, poolSize); System.out.println("Starting test. NumThreads: " + numThreads + " NumIters: " + numIters + " PoolSize: " + poolSize); StopWatch sw = new StopWatch(); sw.start(); test.testThreadedDigest(); sw.stop(); System.out.println("Test finished in: " + sw.toString()); } catch (Exception e) { e.printStackTrace(); } }
From source file:org.jasypt.digest.StandardStringDigesterThreadedTest.java
public static void main(String[] args) { try {/* w w w .j ava 2s. c o m*/ StandardStringDigesterThreadedTest test = new StandardStringDigesterThreadedTest(); System.out.println("Starting test"); StopWatch sw = new StopWatch(); sw.start(); test.testThreadedDigest(); sw.stop(); System.out.println("Test finished in: " + sw.toString()); } catch (Exception e) { e.printStackTrace(); } }