List of usage examples for com.google.common.base Stopwatch start
public Stopwatch start()
From source file:com.Grande.GSM.BACCWS_WAR.WS.REST.EOS.BACCAdminEndpoint.java
@Path("/AllowedDevices") @GET//from w ww . j a va 2 s . com public String fetchAllowedDevices() { // <editor-fold defaultstate="collapsed" desc="****** Method vars ******"> final Stopwatch timer = new Stopwatch(); final QueryResponse qRes = new QueryResponse(); String strResponse = null; List lstResult = null; // start the execution timer timer.start(); // </editor-fold> try { qRes.vSetNode(java.net.InetAddress.getLocalHost().getHostName()); lstResult = this.bacEJB.lstFetchAllowedDeviceTypes(); qRes.vSetSuccessFlag(true); qRes.vSquashResult(lstResult); } catch (Exception e) { // <editor-fold defaultstate="collapsed" desc="****** Handle failures ******"> qRes.vSetSuccessFlag(false); // handle NPE differently since getMessage() is null if (e instanceof NullPointerException) { qRes.vSetMessage("NPE occured when serializing result to JSON! " + "File: " + e.getStackTrace()[0].getFileName() + ", " + "Method: " + e.getStackTrace()[0].getMethodName() + ", " + "Line: " + e.getStackTrace()[0].getLineNumber()); } else { qRes.vSetMessage(e.getMessage()); } SimpleLogging.vLogException(this.strThreadId, e); // </editor-fold> } finally { // <editor-fold defaultstate="collapsed" desc="****** Stop timer, convert response to JSON ******"> timer.stop(); qRes.vSetRoundTrip(String.valueOf(timer.elapsedTime(TimeUnit.SECONDS)) + "." + String.valueOf(timer.elapsedTime(TimeUnit.MILLISECONDS))); strResponse = this.trnBN.strQueryResponseToJSON(qRes); SimpleLogging.vLogEvent(this.strThreadId + "|" + qRes.strGetRoundTripInSeconds() + "s", "retrieved " + qRes.intGetDataCount() + " records"); // </editor-fold> } return strResponse; }
From source file:org.apache.hadoop.hbase.ScanPerformanceEvaluation.java
public void testScan() throws IOException { Stopwatch tableOpenTimer = new Stopwatch(); Stopwatch scanOpenTimer = new Stopwatch(); Stopwatch scanTimer = new Stopwatch(); tableOpenTimer.start(); HTable table = new HTable(getConf(), TableName.valueOf(tablename)); tableOpenTimer.stop();/*www. j a v a 2 s . co m*/ Scan scan = getScan(); scanOpenTimer.start(); ResultScanner scanner = table.getScanner(scan); scanOpenTimer.stop(); long numRows = 0; long numCells = 0; scanTimer.start(); while (true) { Result result = scanner.next(); if (result == null) { break; } numRows++; numCells += result.rawCells().length; } scanTimer.stop(); scanner.close(); table.close(); ScanMetrics metrics = ProtobufUtil.toScanMetrics(scan.getAttribute(Scan.SCAN_ATTRIBUTES_METRICS_DATA)); long totalBytes = metrics.countOfBytesInResults.get(); double throughput = (double) totalBytes / scanTimer.elapsedTime(TimeUnit.SECONDS); double throughputRows = (double) numRows / scanTimer.elapsedTime(TimeUnit.SECONDS); double throughputCells = (double) numCells / scanTimer.elapsedTime(TimeUnit.SECONDS); System.out.println("HBase scan: "); System.out.println("total time to open table: " + tableOpenTimer.elapsedMillis() + " ms"); System.out.println("total time to open scanner: " + scanOpenTimer.elapsedMillis() + " ms"); System.out.println("total time to scan: " + scanTimer.elapsedMillis() + " ms"); System.out.println("Scan metrics:\n" + metrics.getMetricsMap()); System.out.println( "total bytes: " + totalBytes + " bytes (" + StringUtils.humanReadableInt(totalBytes) + ")"); System.out.println("throughput : " + StringUtils.humanReadableInt((long) throughput) + "B/s"); System.out.println("total rows : " + numRows); System.out.println("throughput : " + StringUtils.humanReadableInt((long) throughputRows) + " rows/s"); System.out.println("total cells : " + numCells); System.out.println("throughput : " + StringUtils.humanReadableInt((long) throughputCells) + " cells/s"); }
From source file:org.opendaylight.controller.clustering.it.provider.CarProvider.java
@Override public Future<RpcResult<Void>> stressTest(StressTestInput input) { final int inputRate; final long inputCount; // If rate is not provided, or given as zero, then just return. if ((input.getRate() == null) || (input.getRate() == 0)) { log.info("Exiting stress test as no rate is given."); return Futures.immediateFuture( RpcResultBuilder.<Void>failed().withError(ErrorType.PROTOCOL, "invalid rate").build()); } else {/*from w w w. j a v a 2s . c om*/ inputRate = input.getRate(); } if (input.getCount() != null) { inputCount = input.getCount(); } else { inputCount = 0; } log.info("Stress test starting : rate: {} count: {}", inputRate, inputCount); stopThread(); // clear counters succcessCounter.set(0); failureCounter.set(0); WriteTransaction tx = dataProvider.newWriteOnlyTransaction(); InstanceIdentifier<Cars> carsId = InstanceIdentifier.<Cars>builder(Cars.class).build(); tx.merge(LogicalDatastoreType.CONFIGURATION, carsId, new CarsBuilder().build()); try { tx.submit().checkedGet(5, TimeUnit.SECONDS); } catch (TransactionCommitFailedException | TimeoutException e) { log.error("Put Cars failed", e); return Futures.immediateFuture(RpcResultBuilder.<Void>success().build()); } stopThread = false; final long sleep = TimeUnit.NANOSECONDS.convert(1000, TimeUnit.MILLISECONDS) / inputRate; final Stopwatch sw = Stopwatch.createUnstarted(); testThread = new Thread() { @Override public void run() { sw.start(); AtomicLong count = new AtomicLong(); while (!stopThread) { long id = count.incrementAndGet(); WriteTransaction tx = dataProvider.newWriteOnlyTransaction(); CarEntry car = new CarEntryBuilder().setId(new CarId("car" + id)).build(); tx.put(LogicalDatastoreType.CONFIGURATION, InstanceIdentifier.<Cars>builder(Cars.class) .child(CarEntry.class, car.getKey()).build(), car); CheckedFuture<Void, TransactionCommitFailedException> future = tx.submit(); Futures.addCallback(future, new FutureCallback<Void>() { @Override public void onSuccess(final Void result) { // Transaction succeeded succcessCounter.getAndIncrement(); } @Override public void onFailure(final Throwable t) { // Transaction failed failureCounter.getAndIncrement(); LOG.error("Put Cars failed", t); } }); try { TimeUnit.NANOSECONDS.sleep(sleep); } catch (InterruptedException e) { break; } if ((count.get() % 1000) == 0) { log.info("Cars created {}, time: {}", count.get(), sw.elapsed(TimeUnit.SECONDS)); } // Check if a count is specified in input and we have created that many cars. if ((inputCount != 0) && (count.get() >= inputCount)) { stopThread = true; } } log.info("Stress test thread stopping after creating {} cars.", count.get()); } }; testThread.start(); return Futures.immediateFuture(RpcResultBuilder.<Void>success().build()); }
From source file:org.n52.youngs.control.impl.SingleThreadBulkRunner.java
@Override public Report load(final Sink sink) { this.sink = sink; Objects.nonNull(source);//ww w .j a v a 2s . c om Objects.nonNull(mapper); Objects.nonNull(this.sink); log.info("Starting harvest from {} to {} with {}", source, this.sink, mapper); Report report = new ReportImpl(); try { boolean prepareSink = sink.prepare(mapper.getMapper()); if (!prepareSink) { String msg = "The sink could not be prepared. Stopping load, please check the logs."; log.error(msg); report.addMessage(msg); return report; } } catch (SinkError e) { log.error("Problem preparing sink", e); report.addMessage(String.format("Problem preparing sink: %s", e.getMessage())); return report; } final Stopwatch timer = Stopwatch.createStarted(); long pageStart = startPosition; long count = source.getRecordCount(); final long limit = Math.min(recordsLimit + startPosition, count); final Stopwatch sourceTimer = Stopwatch.createUnstarted(); final Stopwatch mappingTimer = Stopwatch.createUnstarted(); final Stopwatch sinkTimer = Stopwatch.createUnstarted(); final Stopwatch currentBulkTimer = Stopwatch.createUnstarted(); double bulkTimeAvg = 0d; long runNumber = 0; while (pageStart <= limit) { currentBulkTimer.start(); long recordsLeft = limit - pageStart + 1; long size = Math.min(recordsLeft, bulkSize); if (size <= 0) { break; } log.info("### [{}] Requesting {} records from {} starting at {}, last requested record will be {} ###", runNumber, size, source.getEndpoint(), pageStart, limit); try { sourceTimer.start(); Collection<SourceRecord> records = source.getRecords(pageStart, size, report); sourceTimer.stop(); log.debug("Mapping {} retrieved records.", records.size()); mappingTimer.start(); List<SinkRecord> mappedRecords = records.stream().map(record -> { try { return mapper.map(record); } catch (MappingError e) { report.addFailedRecord(record.toString(), "Problem during mapping: " + e.getMessage()); return null; } }).filter(Objects::nonNull).collect(Collectors.toList()); mappingTimer.stop(); log.debug("Storing {} mapped records.", mappedRecords.size()); if (!testRun) { sinkTimer.start(); mappedRecords.forEach(record -> { try { boolean result = sink.store(record); if (result) { report.addSuccessfulRecord(record.getId()); } else { report.addFailedRecord(record.getId(), "see sink log"); } } catch (SinkError e) { report.addFailedRecord(record.toString(), "Problem during mapping: " + e.getMessage()); } }); sinkTimer.stop(); } else { log.info("TESTRUN, created documents are:\n{}", Arrays.toString(mappedRecords.toArray())); } } catch (RuntimeException e) { if (sourceTimer.isRunning()) { sourceTimer.stop(); } if (mappingTimer.isRunning()) { mappingTimer.stop(); } if (sinkTimer.isRunning()) { sinkTimer.stop(); } String msg = String.format("Problem processing records %s to %s: %s", pageStart, pageStart + size, e.getMessage()); log.error(msg, e); report.addMessage(msg); } pageStart += bulkSize; currentBulkTimer.stop(); bulkTimeAvg = ((bulkTimeAvg * runNumber) + currentBulkTimer.elapsed(TimeUnit.SECONDS)) / (runNumber + 1); updateAndLog(runNumber, (runNumber + 1) * bulkSize, currentBulkTimer.elapsed(TimeUnit.SECONDS), bulkTimeAvg); currentBulkTimer.reset(); runNumber++; } timer.stop(); log.info("Completed harvesting for {} ({} failed) of {} records in {} minutes", report.getNumberOfRecordsAdded(), report.getNumberOfRecordsFailed(), source.getRecordCount(), timer.elapsed(TimeUnit.MINUTES)); log.info("Time spent (minutes): source={}, mapping={}, sink={}", sourceTimer.elapsed(TimeUnit.MINUTES), mappingTimer.elapsed(TimeUnit.MINUTES), sinkTimer.elapsed(TimeUnit.MINUTES)); return report; }
From source file:org.apache.drill.exec.physical.impl.TopN.TopNBatch.java
private void purge() throws SchemaChangeException { Stopwatch watch = new Stopwatch(); watch.start(); VectorContainer c = priorityQueue.getHyperBatch(); VectorContainer newContainer = new VectorContainer(oContext); SelectionVector4 selectionVector4 = priorityQueue.getHeapSv4(); SimpleRecordBatch batch = new SimpleRecordBatch(c, selectionVector4, context); SimpleRecordBatch newBatch = new SimpleRecordBatch(newContainer, null, context); if (copier == null) { copier = RemovingRecordBatch.getGenerated4Copier(batch, context, oContext.getAllocator(), newContainer, newBatch, null);//ww w.j av a2s.c om } else { for (VectorWrapper<?> i : batch) { ValueVector v = TypeHelper.getNewVector(i.getField(), oContext.getAllocator()); newContainer.add(v); } copier.setupRemover(context, batch, newBatch); } SortRecordBatchBuilder builder = new SortRecordBatchBuilder(oContext.getAllocator(), MAX_SORT_BYTES); try { do { int count = selectionVector4.getCount(); int copiedRecords = copier.copyRecords(0, count); assert copiedRecords == count; for (VectorWrapper<?> v : newContainer) { ValueVector.Mutator m = v.getValueVector().getMutator(); m.setValueCount(count); } newContainer.buildSchema(BatchSchema.SelectionVectorMode.NONE); newContainer.setRecordCount(count); builder.add(newBatch); } while (selectionVector4.next()); selectionVector4.clear(); c.clear(); VectorContainer newQueue = new VectorContainer(); builder.canonicalize(); builder.build(context, newQueue); priorityQueue.resetQueue(newQueue, builder.getSv4().createNewWrapperCurrent()); builder.getSv4().clear(); selectionVector4.clear(); } finally { builder.close(); } logger.debug("Took {} us to purge", watch.elapsed(TimeUnit.MICROSECONDS)); }
From source file:uk.ac.open.kmi.iserve.sal.manager.impl.ServiceManagerIndexRdf.java
/** * This method will be called when the server is initialised. * If necessary it should take care of updating any indexes on boot time. *//*from w w w . j a v a2 s . com*/ private void initialise() { Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); populateCache(); stopwatch.stop(); log.info("Cache populated. Time taken {}", stopwatch); }
From source file:cosmos.mapred.MediawikiQueries.java
public void groupBy(Store id, Column colToFetch, Map<Column, Long> columnCounts, long totalResults) throws Exception { Stopwatch sw = new Stopwatch(); sw.start(); final CloseableIterable<Entry<RecordValue<?>, Long>> results = this.sorts.groupResults(id, colToFetch); TreeMap<RecordValue<?>, Long> counts = Maps.newTreeMap(); for (Entry<RecordValue<?>, Long> entry : results) { counts.put(entry.getKey(), entry.getValue()); }//from ww w . j ava2s .co m results.close(); sw.stop(); System.out.println(Thread.currentThread().getName() + ": " + colToFetch + " - Took " + sw.toString() + " to group results"); logTiming(totalResults, sw.elapsed(TimeUnit.MILLISECONDS), "groupBy:" + colToFetch); // System.out.println(counts); final CloseableIterable<MultimapRecord> verifyResults = this.sorts.fetch(id, Index.define(colToFetch)); TreeMap<RecordValue<?>, Long> records = Maps.newTreeMap(); for (MultimapRecord r : verifyResults) { if (r.containsKey(colToFetch)) { for (RecordValue<?> val : r.get(colToFetch)) { if (records.containsKey(val)) { records.put(val, records.get(val) + 1); } else { records.put(val, 1l); } } } } verifyResults.close(); if (counts.size() != records.size()) { System.out.println(Thread.currentThread().getName() + ": " + colToFetch + " - Expected " + records.size() + " groups but found " + counts.size()); System.exit(1); } Set<RecordValue<?>> countKeys = counts.keySet(), recordKeys = records.keySet(); for (RecordValue<?> k : countKeys) { if (!recordKeys.contains(k)) { System.out.println(Thread.currentThread().getName() + ": " + colToFetch + " - Expected to have count for " + k); System.exit(1); } Long actual = counts.get(k), expected = records.get(k); if (!actual.equals(expected)) { System.out.println(Thread.currentThread().getName() + ": " + colToFetch + " - Expected " + expected + " value(s) but found " + actual + " value(s) for " + k.value()); System.exit(1); } } }
From source file:uk.ac.open.kmi.iserve.sal.manager.impl.ServiceManagerIndexRdf.java
private void indexService(Service service) { Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); List<Operation> operations = service.getOperations(); Set<URI> svcOps = new HashSet<URI>(); for (Operation operation : operations) { svcOps.add(operation.getUri());// www.j a va 2s .c om indexOperation(operation); } // Set the svcOp map this.svcOpMap.put(service.getUri(), svcOps); // Index the modelReferences indexModelReferences(service); stopwatch.stop(); log.info("Service - {} - indexed. Time taken {}", service.getUri(), stopwatch); }
From source file:co.cask.tigon.data.util.hbase.HBaseTableUtil.java
/** * Create a hbase table if it does not exist. Deals with race conditions when two clients concurrently attempt to * create the table./* ww w . ja v a 2s .co m*/ * @param admin the hbase admin * @param tableName the name of the table * @param tableDescriptor hbase table descriptor for the new table * @param timeout Maximum time to wait for table creation. * @param timeoutUnit The TimeUnit for timeout. */ public void createTableIfNotExists(HBaseAdmin admin, byte[] tableName, HTableDescriptor tableDescriptor, byte[][] splitKeys, long timeout, TimeUnit timeoutUnit) throws IOException { if (admin.tableExists(tableName)) { return; } setDefaultConfiguration(tableDescriptor, admin.getConfiguration()); String tableNameString = Bytes.toString(tableName); try { LOG.info("Creating table '{}'", tableNameString); // HBaseAdmin.createTable can handle null splitKeys. admin.createTable(tableDescriptor, splitKeys); LOG.info("Table created '{}'", tableNameString); return; } catch (TableExistsException e) { // table may exist because someone else is creating it at the same // time. But it may not be available yet, and opening it might fail. LOG.info("Failed to create table '{}'. {}.", tableNameString, e.getMessage(), e); } // Wait for table to materialize try { Stopwatch stopwatch = new Stopwatch(); stopwatch.start(); long sleepTime = timeoutUnit.toNanos(timeout) / 10; sleepTime = sleepTime <= 0 ? 1 : sleepTime; do { if (admin.tableExists(tableName)) { LOG.info("Table '{}' exists now. Assuming that another process concurrently created it.", tableName); return; } else { TimeUnit.NANOSECONDS.sleep(sleepTime); } } while (stopwatch.elapsedTime(timeoutUnit) < timeout); } catch (InterruptedException e) { LOG.warn("Sleeping thread interrupted."); } LOG.error("Table '{}' does not exist after waiting {} ms. Giving up.", tableName, MAX_CREATE_TABLE_WAIT); }
From source file:graph.features.cpp.OpenCPP.java
private OpenCPPSolution<Box<T>> bestSolution(final UndirectedGraph<Box<T>> boxedGraph, final T startingMazeNode) { OpenCPPSolution<Box<T>> bestSolution = new OpenCPPSolution<Box<T>>(null, null, null, null, 2 * this.getLowerBoundCost() * 2); final Stopwatch stopwatch = new Stopwatch(); final DegreeInterface<T> degreeInterface = this.getGraph().fetch(DegreeFeature.class).up(); //final int i = 0; for (final T oddVertice : degreeInterface.getNodesWithOddDegree().keySet()) { stopwatch.start(); final UndirectedGraph<Box<T>> virtualGraph = this.buildVirtualGraph(boxedGraph, startingMazeNode, oddVertice);/*from w w w. j a v a 2 s . c o m*/ //final ClosedCPP<Box<T>> cppSolver = ClosedCPP.from(virtualGraph); final ClosedCPPInterface<Box<T>> closedCPPInterface = virtualGraph.fetch(ClosedCPPFeature.class).up(); final ClosedCPPSolution<Box<T>> cppSolution = closedCPPInterface.solve(); if (cppSolution.getUpperBoundCost() < bestSolution.getUpperBoundCost()) { bestSolution = new OpenCPPSolution<Box<T>>(new Box<T>(oddVertice), virtualGraph, cppSolution.getTraversalByEdge(), cppSolution.getLowerBoundCost(), cppSolution.getUpperBoundCost()); } /* System.out.println(); System.out.println(++i + "/" + this.oddVertices.size() + " : " + stopwatch.elapsedTime(TimeUnit.MILLISECONDS) + " " + TimeUnit.MILLISECONDS); System.out.println(oddVertice + " -> " + cppSolver.getUpperBoundCost() + "$"); System.out.println(); */ stopwatch.reset(); } return bestSolution; }