コード例 #1
0
        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;
                }
            }
        }
コード例 #2
0
        public void PrintSummaryThroughput(TestMessage message, bool endTest = false)
        {
            // store the info for this interval
            ulong now = Perftest.GetTimeUsec();

            if (intervalDataLength != lastDataLength)
            {
                if (!useCft)
                {
                    // detect missing packets
                    if (message.seqNum != lastSeqNum[message.entityId])
                    {
                        // only track if skipped, might have restarted pub
                        if (message.seqNum > lastSeqNum[message.entityId])
                        {
                            missingPackets +=
                                    message.seqNum -
                                    lastSeqNum[message.entityId];
                        }
                    }
                }

                intervalTime = now - beginTime;
                intervalPacketsReceived = packetsReceived;
                intervalBytesReceived = bytesReceived;
                intervalMissingPackets = missingPackets;
                intervalDataLength = lastDataLength;
                missingPacketsPercent = 0.0;

                // Calculations of missing package percent
                if (intervalPacketsReceived
                        + intervalMissingPackets != 0)
                {
                    missingPacketsPercent =
                            intervalMissingPackets
                            / (double)(intervalPacketsReceived
                                + intervalMissingPackets);
                }

                double outputCpu = 0.0;
                if (showCpu)
                {
                    outputCpu = cpu.GetCpuAverage();
                }
                printer.PrintThroughputSummary(
                        intervalDataLength + (int)Perftest.OVERHEAD_BYTES,
                        intervalPacketsReceived,
                        intervalTime,
                        intervalBytesReceived,
                        intervalMissingPackets,
                        missingPacketsPercent,
                        outputCpu);
            }
            else if (endTest)
            {
                Console.WriteLine(
                    "\nNo samples have been received by the Subscriber side,\n"
                    + "however 1 or more Publishers sent the finalization message.\n\n"
                    + "There are several reasons why this could happen:\n"
                    + "- If you are using large data, make sure to correctly adjust your\n"
                    + "  sendQueue, reliability protocol and flowController.\n"
                    + "- Make sure your -executionTime or -numIter in the Publisher side\n"
                    + "  are big enough.\n"
                    + "- Try sending at a slower rate -pubRate in the Publisher side.\n\n");
            }

            packetsReceived = 0;
            bytesReceived = 0;
            missingPackets = 0;
            // length changed only used in scan mode in which case
            // there is only 1 publisher with ID 0
            lastSeqNum[0] = 0;
            beginTime = now;
        }
コード例 #3
0
        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();
        }