List of usage examples for org.apache.commons.lang.time StopWatch StopWatch
public StopWatch()
Constructor.
From source file:org.apache.eagle.storage.jdbc.TestJdbcStorage.java
/** * TODO: Investigate why writing performance becomes slower as records count increases * * 1) Wrote 100000 records in about 18820 ms for empty table * 2) Wrote 100000 records in about 35056 ms when 1M records in table * * @throws IOException/*from www .j ava2 s . c om*/ */ // @Test public void testWriterPerformance() throws IOException { StopWatch stopWatch = new StopWatch(); stopWatch.start(); List<TestTimeSeriesAPIEntity> entityList = new ArrayList<TestTimeSeriesAPIEntity>(); int i = 0; while (i++ < 100000) { entityList.add(newInstance()); if (entityList.size() >= 1000) { ModifyResult<String> result = storage.create(entityList, entityDefinition); Assert.assertNotNull(result); entityList.clear(); } } stopWatch.stop(); LOG.info("Wrote 100000 records in " + stopWatch.getTime() + " ms"); }
From source file:org.apache.geronimo.mavenplugins.geronimo.server.StartServerMojo.java
protected void doExecute() throws Exception { if (install) { installAssembly();/*from w w w . j a va 2 s . c o m*/ } else { log.info("Skipping assembly installation"); if (!geronimoHome.exists()) { throw new MojoExecutionException("Missing pre-installed assembly directory: " + geronimoHome); } } log.info("Starting Geronimo server..."); // Setup the JVM to start the server with final Java java = (Java) createTask("java"); java.setClassname("org.apache.geronimo.cli.daemon.DaemonCLI"); Path path = java.createClasspath(); File libDir = new File(geronimoHome, "lib"); FileSet fileSet = new FileSet(); fileSet.setDir(libDir); path.addFileset(fileSet); java.setDir(geronimoHome); java.setFailonerror(true); java.setFork(true); if (javaVirtualMachine != null) { if (!javaVirtualMachine.exists()) { throw new MojoExecutionException("Java virtual machine is not valid: " + javaVirtualMachine); } log.info("Using Java virtual machine: " + javaVirtualMachine); java.setJvm(javaVirtualMachine.getCanonicalPath()); } if (timeout > 0) { java.setTimeout(new Long(timeout * 1000)); } if (maximumMemory != null) { java.setMaxmemory(maximumMemory); } if (maxPermSize != null) { java.createJvmarg().setValue("-XX:MaxPermSize=" + maxPermSize); } // Load the Java programming language agent for JPA File javaAgentJar = new File(geronimoHome, "lib/agent/transformer.jar"); if (javaAgentJar.exists()) { java.createJvmarg().setValue("-javaagent:" + javaAgentJar.getCanonicalPath()); } // Propagate some properties from Maven to the server if enabled if (propagateGeronimoProperties) { Properties props = System.getProperties(); Iterator iter = props.keySet().iterator(); while (iter.hasNext()) { String name = (String) iter.next(); String value = System.getProperty(name); if (name.equals("geronimo.bootstrap.logging.enabled")) { // Skip this property, never propagate it } else if (name.startsWith("org.apache.geronimo") || name.startsWith("geronimo")) { if (log.isDebugEnabled()) { log.debug("Propagating: " + name + "=" + value); } setSystemProperty(java, name, value); } } } // Apply option sets if (options != null && (optionSets == null || optionSets.length == 0)) { throw new MojoExecutionException("At least one optionSet must be defined to select one using options"); } else if (options == null) { options = "default"; } if (optionSets != null && optionSets.length != 0) { OptionSet[] sets = selectOptionSets(); for (int i = 0; i < sets.length; i++) { if (log.isDebugEnabled()) { log.debug("Selected option set: " + sets[i]); } else { log.info("Selected option set: " + sets[i].getId()); } String[] options = sets[i].getOptions(); if (options != null) { for (int j = 0; j < options.length; j++) { java.createJvmarg().setValue(options[j]); } } Properties props = sets[i].getProperties(); if (props != null) { Iterator iter = props.keySet().iterator(); while (iter.hasNext()) { String name = (String) iter.next(); String value = props.getProperty(name); setSystemProperty(java, name, value); } } } } // Set the properties which we pass to the JVM from the startup script setSystemProperty(java, "org.apache.geronimo.home.dir", geronimoHome); setSystemProperty(java, "karaf.home", geronimoHome); setSystemProperty(java, "karaf.base", geronimoHome); // Use relative path setSystemProperty(java, "java.io.tmpdir", "var/temp"); setSystemProperty(java, "java.endorsed.dirs", prefixSystemPath("java.endorsed.dirs", new File(geronimoHome, "lib/endorsed"))); setSystemProperty(java, "java.ext.dirs", prefixSystemPath("java.ext.dirs", new File(geronimoHome, "lib/ext"))); // set console properties setSystemProperty(java, "karaf.startLocalConsole", "false"); setSystemProperty(java, "karaf.startRemoteShell", "true"); if (quiet) { java.createArg().setValue("--quiet"); } else { java.createArg().setValue("--long"); } if (verbose) { java.createArg().setValue("--verbose"); } if (veryverbose) { java.createArg().setValue("--veryverbose"); } if (startModules != null) { if (startModules.length == 0) { throw new MojoExecutionException("At least one module name must be configured with startModule"); } log.info("Overriding the set of modules to be started"); java.createArg().setValue("--override"); for (int i = 0; i < startModules.length; i++) { java.createArg().setValue(startModules[i]); } } // // TODO: Check if this really does capture STDERR or not! // if (logOutput) { File file = getLogFile(); FileUtils.forceMkdir(file.getParentFile()); log.info("Redirecting output to: " + file); java.setOutput(file); } // Holds any exception that was thrown during startup final ObjectHolder errorHolder = new ObjectHolder(); StopWatch watch = new StopWatch(); watch.start(); // Start the server int a seperate thread Thread t = new Thread("Geronimo Server Runner") { public void run() { try { java.execute(); } catch (Exception e) { errorHolder.set(e); // // NOTE: Don't log here, as when the JVM exists an exception will get thrown by Ant // but that should be fine. // } } }; t.start(); log.info("Waiting for Geronimo server..."); // Setup a callback to time out verification final ObjectHolder verifyTimedOut = new ObjectHolder(); TimerTask timeoutTask = new TimerTask() { public void run() { verifyTimedOut.set(Boolean.TRUE); } }; if (verifyTimeout > 0) { if (log.isDebugEnabled()) { log.debug("Starting verify timeout task; triggers in: " + verifyTimeout + " seconds"); } timer.schedule(timeoutTask, verifyTimeout * 1000); } // Verify server started ServerProxy server = new ServerProxy(hostname, port, username, password); boolean started = false; while (!started) { if (verifyTimedOut.isSet()) { throw new MojoExecutionException("Unable to verify if the server was started in the given time (" + verifyTimeout + " seconds)"); } if (errorHolder.isSet()) { throw new MojoExecutionException("Failed to start Geronimo server", (Throwable) errorHolder.get()); } started = server.isFullyStarted(); if (!started) { Throwable error = server.getLastError(); if ((error != null) && (log.isDebugEnabled())) { log.debug("Server query failed; ignoring", error); } Thread.sleep(5 * 1000); } } server.closeConnection(); // Stop the timer, server should be up now timeoutTask.cancel(); log.info("Geronimo server started in " + watch); if (!background) { log.info("Waiting for Geronimo server to shutdown..."); t.join(); } }
From source file:org.apache.geronimo.shell.geronimo.ProcessLauncher.java
public void launch() throws Exception { assert name != null; Runnable runner = new Inner(); Thread t = new Thread(runner, name + " Runner"); out.println("Launching " + name + "..."); //System.console().flush(); StopWatch watch = new StopWatch(); watch.start();/*from w w w. ja va 2 s .c om*/ t.start(); if (verifier()) { Timer timer = new Timer(name + " Timer", true); TimerTask timeoutTask = new TimingTimerTask(); if (timeout > 0) { timer.schedule(timeoutTask, timeout * 1000); } boolean started = false; log.debug("Waiting for " + name + " ..."); while (!started) { if (timedOut) { throw new Exception("Unable to verify if " + name + " was started in the given time (" + timeout + " seconds)"); } if (error != null) { throw new Exception("Failed to start: " + name, error); } if (verifier()) { started = true; } else { Thread.sleep(verifyWaitDelay); } } timeoutTask.cancel(); } out.println(name + " started in " + watch); //System.console().flush(); if (!background) { log.debug("Waiting for " + name + " to shutdown..."); t.join(); log.debug(name + " has shutdown"); } }
From source file:org.apache.hadoop.hbase.ipc.TestCellBlockBuilder.java
private static void timerTests(final CellBlockBuilder builder, final int count, final int size, final Codec codec, final CompressionCodec compressor) throws IOException { final int cycles = 1000; StopWatch timer = new StopWatch(); timer.start();// ww w.j a v a2 s.c om for (int i = 0; i < cycles; i++) { timerTest(builder, timer, count, size, codec, compressor, false); } timer.stop(); LOG.info("Codec=" + codec + ", compression=" + compressor + ", sized=" + false + ", count=" + count + ", size=" + size + ", + took=" + timer.getTime() + "ms"); timer.reset(); timer.start(); for (int i = 0; i < cycles; i++) { timerTest(builder, timer, count, size, codec, compressor, true); } timer.stop(); LOG.info("Codec=" + codec + ", compression=" + compressor + ", sized=" + true + ", count=" + count + ", size=" + size + ", + took=" + timer.getTime() + "ms"); }
From source file:org.apache.hadoop.hbase.ipc.TestIPCUtil.java
private static void timerTests(final IPCUtil util, final int count, final int size, final Codec codec, final CompressionCodec compressor) throws IOException { final int cycles = 1000; StopWatch timer = new StopWatch(); timer.start();//from w w w . j a v a2 s . c o m for (int i = 0; i < cycles; i++) { timerTest(util, timer, count, size, codec, compressor, false); } timer.stop(); LOG.info("Codec=" + codec + ", compression=" + compressor + ", sized=" + false + ", count=" + count + ", size=" + size + ", + took=" + timer.getTime() + "ms"); timer.reset(); timer.start(); for (int i = 0; i < cycles; i++) { timerTest(util, timer, count, size, codec, compressor, true); } timer.stop(); LOG.info("Codec=" + codec + ", compression=" + compressor + ", sized=" + true + ", count=" + count + ", size=" + size + ", + took=" + timer.getTime() + "ms"); }
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/*ww w. ja v a2 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.hadoop.hbase.tool.Canary.java
private static void sniffRegion(final HBaseAdmin admin, final Sink sink, HRegionInfo region, HTable table) throws Exception { HTableDescriptor tableDesc = table.getTableDescriptor(); byte[] startKey = null; Get get = null;/*from w w w . j ava2 s . co m*/ Scan scan = null; ResultScanner rs = null; StopWatch stopWatch = new StopWatch(); for (HColumnDescriptor column : tableDesc.getColumnFamilies()) { stopWatch.reset(); startKey = region.getStartKey(); // Can't do a get on empty start row so do a Scan of first element if any instead. if (startKey.length > 0) { get = new Get(startKey); get.addFamily(column.getName()); } else { scan = new Scan(); scan.setCaching(1); scan.addFamily(column.getName()); scan.setMaxResultSize(1L); } try { if (startKey.length > 0) { stopWatch.start(); table.get(get); stopWatch.stop(); sink.publishReadTiming(region, column, stopWatch.getTime()); } else { stopWatch.start(); rs = table.getScanner(scan); stopWatch.stop(); sink.publishReadTiming(region, column, stopWatch.getTime()); } } catch (Exception e) { sink.publishReadFailure(region, column, e); } finally { if (rs != null) { rs.close(); } scan = null; get = null; startKey = null; } } }
From source file:org.apache.james.cli.ServerCmd.java
/** * Main method to initialize the class./*from w ww. jav a2 s .c om*/ * * @param args Command-line arguments. */ public static void main(String[] args) { try { StopWatch stopWatch = new StopWatch(); stopWatch.start(); CommandLine cmd = parseCommandLine(args); CmdType cmdType = new ServerCmd(new JmxServerProbe(cmd.getOptionValue(HOST_OPT_LONG), getPort(cmd))) .executeCommandLine(cmd); stopWatch.split(); print(new String[] { Joiner.on(' ').join(cmdType.getCommand(), "command executed sucessfully in", stopWatch.getSplitTime(), "ms.") }, System.out); stopWatch.stop(); System.exit(0); } catch (JamesCliException e) { failWithMessage(e.getMessage()); } catch (ParseException e) { failWithMessage("Error parsing command line : " + e.getMessage()); } catch (IOException ioe) { failWithMessage("Error connecting to remote JMX agent : " + ioe.getMessage()); } catch (Exception e) { failWithMessage("Error while executing command:" + e.getMessage()); } }
From source file:org.apache.ojb.broker.QueryTest.java
/** * Run a query range test.//from ww w. j av a 2s . c om */ public void testQueryRangeMassTest() { String name = "testQueryRangeMassTest_" + System.currentTimeMillis(); int objCount = 2000; broker.beginTransaction(); for (int i = 0; i < objCount; i++) { Gourmet a = new Gourmet(); a.setName(name); broker.store(a); } broker.commitTransaction(); Criteria crit = new Criteria(); crit.addEqualTo("name", name); QueryByCriteria q = QueryFactory.newQuery(Gourmet.class, crit); q.setStartAtIndex(100); q.setEndAtIndex(109); StopWatch watch = new StopWatch(); watch.start(); Collection c = broker.getCollectionByQuery(q); watch.stop(); System.out.println("# Query 10 of " + objCount + " objects take " + watch.getTime() + " ms"); assertNotNull(c); List result = new ArrayList(c); assertEquals(10, result.size()); crit = new Criteria(); crit.addEqualTo("name", name); q = QueryFactory.newQuery(Gourmet.class, crit); watch.reset(); watch.start(); c = broker.getCollectionByQuery(q); watch.stop(); System.out.println("# Query all " + objCount + " objects take " + watch.getTime() + " ms"); assertNotNull(c); result = new ArrayList(c); assertEquals(objCount, result.size()); broker.beginTransaction(); for (int i = 0; i < result.size(); i++) { broker.delete(result.get(i)); } broker.commitTransaction(); c = broker.getCollectionByQuery(q); assertNotNull(c); result = new ArrayList(c); assertEquals(0, result.size()); }
From source file:org.apache.phoenix.logging.PerformanceLog.java
private StopWatch getStopWatch() { if (stopWatch == null) { stopWatch = new StopWatch(); } return stopWatch; }