public void ProcessMessage(TestMessage message) { currentMessageSize = message.Size; messageEntityId = message.entityId; messageSequenceNumber = message.seqNum; if (messageEntityId >= numPublishers || messageEntityId < 0) { Console.Error.WriteLine( "ProcessMessage: message content no valid. message.entity_id out of bounds"); return; } // Check for test initialization messages if (currentMessageSize == Perftest.INITIALIZE_SIZE) { writer.Send(message, false); writer.Flush(); return; } else if (currentMessageSize == Perftest.FINISHED_SIZE) { /* * PERFTEST-97 * We check the entity_id of the publisher to see if it has * already send a FINISHED_SIZE message. If he has we ignore * any new one. Else, we add it to a vector. Once that * vector contains all the ids of the publishers the * subscriber is suppose to know, that means that all the * publishers have finished sending data samples, so it is * time to finish the subscriber. */ if (finishedPublishers.Contains(messageEntityId)) { return; } if (endTest) { return; } finishedPublishers.Add(messageEntityId); if (finishedPublishers.Count >= numPublishers) { PrintSummaryThroughput(message, true); endTest = true; } return; } // Send back a packet if this is a ping if ((message.latencyPing == subId) || (useCft && message.latencyPing != -1)) { writer.Send(message, false); writer.Flush(); } // // Always check if need to reset internals // if (currentMessageSize == Perftest.LENGTH_CHANGED_SIZE) // { // PrintSummaryThroughput(message); // changeSize = true; // return; // } if (currentMessageSize != lastDataLength) { packetsReceived = 0; bytesReceived = 0; missingPackets = 0; for (int i = 0; i < numPublishers; i++) { lastSeqNum[i] = 0; } beginTime = Perftest.GetTimeUsec(); printer.SetDataSize(currentMessageSize + (int)Perftest.OVERHEAD_BYTES); printer.PrintThroughputHeader(); } lastDataLength = currentMessageSize; ++packetsReceived; bytesReceived += (ulong)(currentMessageSize + (int)Perftest.OVERHEAD_BYTES); // detect missing packets if (!useCft) { if (lastSeqNum[messageEntityId] == 0) { lastSeqNum[messageEntityId] = messageSequenceNumber; } else if (messageSequenceNumber != ++lastSeqNum[messageEntityId]) { // only track if skipped, might have restarted pub if (messageSequenceNumber > lastSeqNum[messageEntityId]) { missingPackets += messageSequenceNumber - lastSeqNum[messageEntityId]; } lastSeqNum[messageEntityId] = messageSequenceNumber; } } }
public void ProcessMessage(TestMessage message) { ulong now, sentTime; long sec; ulong usec; uint latency; double latencyAve; double latencyStd; now = Perftest.GetTimeUsec(); // If message.Size == Perftest.INITIALIZE_SIZE, the message is bein initialized and // there's nothing to process if (message.Size == Perftest.INITIALIZE_SIZE || message.Size == Perftest.FINISHED_SIZE) { return; } else if (message.Size == Perftest.LENGTH_CHANGED_SIZE) { Console.Error.WriteLine( "[Error]: Received command to change size," + "this is not supported in C#"); PrintSummaryLatency(); return; } sec = message.timestampSec; usec = message.timestampUsec; sentTime = ((ulong)sec << 32) | usec; if (now >= sentTime) { latency = (uint)(now - sentTime); // keep track of one-way latency latency /= 2; } else { Console.Error.WriteLine( $"Clock skew suspected: received time {now} usec, sent time {sentTime} usec"); ++clockSkewCount; return; } // store value for percentile calculations if (latencyHistory != null) { if (count >= (ulong)NumLatency) { // Console.Error.WriteLine( // "Too many latency pongs received. Do you have more " // + "than 1 app with -pidMultiPubTest = 0 or -sidMultiSubTest = 0? count: " // + count + " NumLatency: " + NumLatency + "\n"); return; } else { latencyHistory[count] = latency; } } if (latencyMin == Perftest.LATENCY_RESET_VALUE) { latencyMin = latency; latencyMax = latency; } else { if (latency < latencyMin) { latencyMin = latency; } else if (latency > latencyMax) { latencyMax = latency; } } ++count; latencySum += latency; latencySumSquare += (ulong)latency * (ulong)latency; // if data sized changed if (lastDataLength != message.Size) { lastDataLength = message.Size; if (lastDataLength != 0) { printer.SetDataSize(lastDataLength + (int)Perftest.OVERHEAD_BYTES); printer.PrintLatencyHeader(); } } else { double outputCpu = 0.0; if (parameters.Cpu) { outputCpu = cpu.GetCpuInstant(); } if (!parameters.NoPrintIntervals) { latencyAve = (double)latencySum / (double)count; latencyStd = System.Math.Sqrt( ((double)latencySumSquare / (double)count) - (latencyAve * latencyAve)); printer.PrintLatencyInterval( latency, latencyAve, latencyStd, latencyMin, latencyMax, outputCpu); } } writer?.NotifyPingResponse(); }