protected WireParselet parselet() { return (methodName, v) -> { v.skipValue(); if (counter < ignore) return; final MessageHistory history = MessageHistory.get(); if (history == null) return; processMessage(methodName, history); if (history.timings() > 0) { long firstTiming = history.timing(0); if (measurementWindowNanos > 0) { long windowCount = firstTiming / measurementWindowNanos; if (windowCount > lastWindowCount) { windowPassed(); lastWindowCount = windowCount; } if (firstTimeStampNanos == 0) firstTimeStampNanos = firstTiming; } } }; }
@Nullable public static MessageHistory readHistory(final DocumentContext dc, MessageHistory history) { final Wire wire = dc.wire(); if (wire == null) return null; Object parent = wire.parent(); wire.parent(null); try { final Bytes<?> bytes = wire.bytes(); final byte code = bytes.readByte(bytes.readPosition()); history.reset(); return code == (byte) FIELD_NUMBER ? readHistoryFromBytes(wire, history) : readHistoryFromWire(wire, history); } finally { wire.parent(parent); } }
protected void processMessage(CharSequence methodName, MessageHistory history) { CharSequence extraHistoId = histosByMethod ? ("_" + methodName) : ""; long lastTime = 0; // if the tailer has recordHistory(true) then the MessageHistory will be // written with a single timing and nothing else. This is then carried through int firstWriteOffset = history.timings() - (history.sources() * 2); if (!(firstWriteOffset == 0 || firstWriteOffset == 1)) // don't know how this can happen, but there is at least one CQ that exhibits it return; for (int sourceIndex = 0; sourceIndex < history.sources(); sourceIndex++) { String histoId = Integer.toString(history.sourceId(sourceIndex)) + extraHistoId; Histogram histo = histos.computeIfAbsent(histoId, s -> histogram()); long receivedByThisComponent = history.timing((2 * sourceIndex) + firstWriteOffset); long processedByThisComponent = history.timing((2 * sourceIndex) + firstWriteOffset + 1); histo.sample(processedByThisComponent - receivedByThisComponent); if (lastTime == 0 && firstWriteOffset > 0) { Histogram histo1 = histos.computeIfAbsent("startTo" + histoId, s -> histogram()); histo1.sample(receivedByThisComponent - history.timing(0)); } else if (lastTime != 0) { Histogram histo1 = histos.computeIfAbsent(Integer.toString(history.sourceId(sourceIndex - 1)) + "to" + histoId, s -> histogram()); // here we are comparing System.nanoTime across processes. YMMV histo1.sample(receivedByThisComponent - lastTime); } lastTime = processedByThisComponent; } if (history.sources() > 1) { Histogram histoE2E = histos.computeIfAbsent("endToEnd", s -> histogram()); histoE2E.sample(history.timing(history.timings() - 1) - history.timing(0)); } }
private void doTest(boolean recordHistoryFirst) { VanillaMessageHistory veh = new VanillaMessageHistory(); veh.addSourceDetails(true); MessageHistory.set(veh); .get(); DummyListener dummy = msg -> { MessageHistory history = MessageHistory.get(); Assert.assertEquals(1, history.sources()); Assert.assertEquals(1 + extraTiming, history.timings()); writer.say(msg); }; .get(); DummyListener dummy = msg -> { MessageHistory history = MessageHistory.get(); Assert.assertEquals(2, history.sources()); Assert.assertEquals(3 + extraTiming, history.timings()); writer.say(msg); };
continue; int i = veh.sources() - 1; if (i < 0) continue; if (veh.sourceId(i) != this.sourceId()) continue; long sourceIndex = veh.sourceIndex(i); if (!moveToIndexInternal(sourceIndex)) { final String errorMessage = String.format(
public static void main(String[] args) { SingleChronicleQueue outQueue = SingleChronicleQueueBuilder.binary("target/" + "monitor") .rollCycle(RollCycles.TEST_SECONDLY).build(); ExcerptAppender outQueueAppender = outQueue.acquireAppender(); HeartbeatListener heartbeatWriter = outQueueAppender.methodWriterBuilder(HeartbeatListener.class).methodWriterListener((m, a) -> validateAll(a)).recordHistory(true).build(); Monitor.addPeriodicUpdateSource(10, () -> currentTimeMillis -> { outQueueAppender.pretouch(); }); long lastHB = 0; while (true) { if (System.currentTimeMillis() - lastHB > 1) { // write a hb to the queue MessageHistory.get().reset(); Heartbeat heartBeat = new Heartbeat(UUID.randomUUID().toString()); heartbeatWriter.heartbeat(heartBeat); lastHB = System.currentTimeMillis(); } } }
read.marshallable(MessageHistory.get()); return true;
@Before public void setUp() throws Exception { inputQueueDir = DirectoryUtils.tempDir(testName.getMethodName()); outputQueueDir = DirectoryUtils.tempDir(testName.getMethodName()); final VanillaMessageHistory messageHistory = new VanillaMessageHistory(); messageHistory.addSourceDetails(true); MessageHistory.set(messageHistory); }
continue; int i = veh.sources() - 1; if (i < 0) continue; if (veh.sourceId(i) != this.sourceId()) continue; long sourceIndex = veh.sourceIndex(i); if (!moveToIndexInternal(sourceIndex)) { final String errorMessage = String.format(
protected void processMessage(CharSequence methodName, MessageHistory history) { CharSequence extraHistoId = histosByMethod ? ("_" + methodName) : ""; long lastTime = 0; // if the tailer has recordHistory(true) then the MessageHistory will be // written with a single timing and nothing else. This is then carried through int firstWriteOffset = history.timings() - (history.sources() * 2); if (!(firstWriteOffset == 0 || firstWriteOffset == 1)) // don't know how this can happen, but there is at least one CQ that exhibits it return; for (int sourceIndex = 0; sourceIndex < history.sources(); sourceIndex++) { String histoId = Integer.toString(history.sourceId(sourceIndex)) + extraHistoId; Histogram histo = histos.computeIfAbsent(histoId, s -> histogram()); long receivedByThisComponent = history.timing((2 * sourceIndex) + firstWriteOffset); long processedByThisComponent = history.timing((2 * sourceIndex) + firstWriteOffset + 1); histo.sample(processedByThisComponent - receivedByThisComponent); if (lastTime == 0 && firstWriteOffset > 0) { Histogram histo1 = histos.computeIfAbsent("startTo" + histoId, s -> histogram()); histo1.sample(receivedByThisComponent - history.timing(0)); } else if (lastTime != 0) { Histogram histo1 = histos.computeIfAbsent(Integer.toString(history.sourceId(sourceIndex - 1)) + "to" + histoId, s -> histogram()); // here we are comparing System.nanoTime across processes. YMMV histo1.sample(receivedByThisComponent - lastTime); } lastTime = processedByThisComponent; } if (history.sources() > 1) { Histogram histoE2E = histos.computeIfAbsent("endToEnd", s -> histogram()); histoE2E.sample(history.timing(history.timings() - 1) - history.timing(0)); } }
protected WireParselet parselet() { return (methodName, v) -> { v.skipValue(); if (counter < ignore) return; final MessageHistory history = MessageHistory.get(); if (history == null) return; processMessage(methodName, history); if (history.timings() > 0) { long firstTiming = history.timing(0); if (measurementWindowNanos > 0) { long windowCount = firstTiming / measurementWindowNanos; if (windowCount > lastWindowCount) { windowPassed(); lastWindowCount = windowCount; } if (firstTimeStampNanos == 0) firstTimeStampNanos = firstTiming; } } }; }
@Nullable public static MessageHistory readHistory(final DocumentContext dc, MessageHistory history) { final Wire wire = dc.wire(); if (wire == null) return null; Object parent = wire.parent(); wire.parent(null); try { final Bytes<?> bytes = wire.bytes(); final byte code = bytes.readByte(bytes.readPosition()); history.reset(); return code == (byte) FIELD_NUMBER ? readHistoryFromBytes(wire, history) : readHistoryFromWire(wire, history); } finally { wire.parent(parent); } }