public int intValue() { return Math.round(floatValue()); }
@Override public String getTPSAsString() { return tps.toString(); }
private float calcTPS() { lock.lock(); try { long now = getNanoTime() / FROM_NANOS; long interval = now - start.get(); if (interval >= period) { calcTPS(interval); start.set(now); } return tps; } finally { lock.unlock(); } }
public void test1000TPSAutoUpdate() throws Exception { TPS tps = new TPS(true); for (int i=0; i<1000; i++) tps.tick(); Thread.sleep (1050L); // java.util.Timer is not accurate assertEquals("Expected 1000 TPS", 1000, tps.intValue()); assertEquals("Still expecting 1000 TPS on a second call", 1000, tps.intValue()); Thread.sleep (1000L); assertTrue ("Average should be aprox 0.5 but it's " + tps.getAvg(), tps.getAvg() >= 0.5); assertEquals( "TPS should be zero but it's "+tps.intValue() + " (" + tps.floatValue() + ")", 0, tps.intValue() ); assertEquals ("Peak has to be 1000", 1000, tps.getPeak()); tps.stop(); } public void test1000TPSManualUpdate() throws Exception {
public void test1000TPSManualUpdate() throws Exception { TPS tps = new TPS(); for (int i=0; i<1000; i++) tps.tick(); Thread.sleep (1050L); assertTrue("Expected aprox 1000 TPS but was "+ tps.intValue(), tps.intValue() >= 900); assertTrue("Still expecting aprox 1000 TPS on a second call", tps.intValue() >= 900); Thread.sleep (1050L); assertEquals( "TPS should be zero but it's "+tps.intValue() + " (" + tps.floatValue() + ")", 0, tps.intValue() ); } }
System.out.println ("\n--- pack/unpack performance test ---\n"); Profiler prof = new Profiler(); TPS tps = new TPS(true); for (int i=0; i<COUNT; i++) { pack (baseMsg, p); tps.tick(); prof.checkPoint ("PACK " + tps.toString()); tps = new TPS(true); for (int i=0; i<COUNT; i++) { unpack (buf, p); tps.tick(); prof.checkPoint ("UNPACK " + tps.toString()); tps = new TPS(true); for (int i=0; i<COUNT; i++) { pack (baseMsg, p); unpack (buf, p); tps.tick(); prof.checkPoint ("PACK/UNPACK " + tps.toString()); tps = new TPS(true); for (int i=0; i<COUNT; i++) { updatePackAndUnpack(baseMsg, p); tps.tick(); prof.checkPoint ("UPDATE/PACK/UNPACK " + tps.toString());
public void run() { TPS tps = new TPS(); try (BinLogWriter bl = new BinLogWriter(dir)) { for (int i = 1; i <= 10000; i++) { long l = cnt.incrementAndGet(); if (i % 5000 == 0) { bl.cutover(); } bl.add(ISOUtil.zeropad(l, 12).getBytes()); tps.tick(); } tps.dump(System.out, ""); } catch (Throwable e) { e.printStackTrace(System.err); } }
@Override public float getTPSAvg() { return tps.getAvg(); }
@Override public int getTPSPeak() { return tps.getPeak(); }
@Override public void stopService () { NameRegistrar.unregister(getName()); if (loadMonitorExecutor != null) loadMonitorExecutor.shutdown(); Thread[] tt = threads.toArray(new Thread[threads.size()]); if (iisp != isp) for (Object o=iisp.inp(queue); o != null; o=iisp.inp(queue)) isp.out(queue, o); // push back to replicated space for (Thread t : tt) iisp.out(queue, Boolean.FALSE, 60 * 1000); for (Thread thread : tt) { try { thread.join (60*1000); threads.remove(thread); } catch (InterruptedException e) { getLog().warn ("Session " + thread.getName() +" does not respond - attempting to interrupt"); thread.interrupt(); } } tps.stop(); for (Destroyable destroyable : destroyables) { try { destroyable.destroy(); } catch (Throwable t) { getLog().warn (t); } } } public void queue (Serializable context) {
public float floatValue() { return autoupdate ? tps : calcTPS(); }
public void dump(PrintStream p, String indent) { p.println(indent + "<tps" + (autoupdate ? " auto='true'>" : ">") + this.toString() + "</tps>"); }
@Override public void dump (PrintStream ps, String indent) { ps.printf ("%sin-transit=%d/%d, head=%d, tail=%d, paused=%d, outstanding=%d, active-sessions=%d/%d%s%n", indent, getActiveTransactions(), getInTransit(), head, tail, pausedCounter.get(), getOutstandingTransactions(), getActiveSessions(), maxSessions, (tps != null ? ", " + tps.toString() : "") ); if (metrics != null) { metrics.dump(ps, indent); } }