public static void Run(LoggingLib lib, LogFileType logFileType, Action <long, int> logAction)
        {
            int numberOfRuns    = Parameters.NumberOfRuns + 1;
            int logsCountPerRun = Parameters.NumberOfLogsPerParallelRun;

            string testCaseName = $"{lib} -> {ThreadingType.MultiThreaded} -> {logFileType}";

            Console.WriteLine();
            Console.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine($"'{testCaseName}' case STARTED. Number of runs: '{numberOfRuns - 1}', logs per run: '{logsCountPerRun}'");

            long sumOfAllRunsElapsedMs = 0;

            TestCaseStopWatch.Reset();
            TestCaseStopWatch.Start();

            Parallel.For((long)1, numberOfRuns, index =>
            {
                LocalSingleRunStopwatch.Value.Reset();
                LocalSingleRunStopwatch.Value.Start();

                Task task = Task.Factory.StartNew(() =>
                {
                    for (int j = 1; j <= logsCountPerRun; j++)
                    {
                        logAction(index, j);
                    }
                });

                task.Wait();

                LocalSingleRunStopwatch.Value.Stop();

                string runNumber = index < 10 ? $"0{index}" : index.ToString();

                int singleRunTimeInMs = Convert.ToInt32(LocalSingleRunStopwatch.Value.Elapsed.TotalMilliseconds);
                Console.WriteLine($"Run #{runNumber} completed in: {singleRunTimeInMs} ms");

                Interlocked.Add(ref sumOfAllRunsElapsedMs, singleRunTimeInMs);
            });

            TestCaseStopWatch.Stop();

            int totalNumberOfLogsWritten = lib == LoggingLib.NoLoggingLib ? 0 : (numberOfRuns - 1) * logsCountPerRun;

            int totalRunTimeInMs = Convert.ToInt32(TestCaseStopWatch.Elapsed.TotalMilliseconds);

            Console.WriteLine($"'{testCaseName}' case FINISHED. Total logs written: '{totalNumberOfLogsWritten}', whole test case run time: {totalRunTimeInMs} ms, sum of all parallel runs time: {sumOfAllRunsElapsedMs} ms");
        }
        public static void Run(LoggingLib lib, LogFileType logFileType, Action <int, int> logAction)
        {
            int numberOfRuns    = Parameters.NumberOfRuns;
            int logsCountPerRun = Parameters.NumberOfLogsPerSyncRun;

            string testCaseName = $"{lib} -> {ThreadingType.SingleThreaded} -> {logFileType}";

            Console.WriteLine();
            Console.WriteLine("-------------------------------------------------------------------------------------------------------------------------------------------------");
            Console.WriteLine($"'{testCaseName}' case STARTED. Number of runs: '{numberOfRuns}', logs per run: '{logsCountPerRun}'");

            long sumOfAllRunsElapsedMs = 0;

            TestCaseStopWatch.Reset();
            TestCaseStopWatch.Start();

            for (int i = 1; i <= numberOfRuns; i++)
            {
                SingleRunStopWatch.Reset();
                SingleRunStopWatch.Start();

                for (int j = 1; j <= logsCountPerRun; j++)
                {
                    logAction(i, j);
                }

                SingleRunStopWatch.Stop();

                string runNumber = i < 10 ? $"0{i}" : i.ToString();

                int singleRunTimeInMs = Convert.ToInt32(SingleRunStopWatch.Elapsed.TotalMilliseconds);
                Console.WriteLine($"Run #{runNumber} completed in: {singleRunTimeInMs} ms");
                sumOfAllRunsElapsedMs += singleRunTimeInMs;
            }

            TestCaseStopWatch.Stop();

            int totalNumberOfLogsWritten = lib == LoggingLib.NoLoggingLib ? 0 : numberOfRuns * logsCountPerRun;

            int totalRunTimeInMs = Convert.ToInt32(TestCaseStopWatch.Elapsed.TotalMilliseconds);

            Console.WriteLine($"'{testCaseName}' case FINISHED. Total logs written: '{totalNumberOfLogsWritten}', whole test case run time: {totalRunTimeInMs} ms, sum of all single runs time: {sumOfAllRunsElapsedMs} ms");
        }
Exemplo n.º 3
0
        void Init()
        {
            LoggingLib.Connect();
            LoggingLib.SendMessage(string.Format("This is a message from router (ID: {0})", id));

            // Console setup and initial printouts
            Console.Title = id;
            Log.PrintAsciiTitle(id);
            Log.WriteLine(true, "Ports: Wirecloud({0}, {1}), NMS({2}, {3})",
                          wirecloudLocalPort, wirecloudRemotePort,
                          mgmtLocalPort, connectionControllerPort);
            Log.WriteLine(true, "Interfaces: " + string.Join(", ", routerInterfaceDefs.Select(def => def.Key + ": " + def.Value + "Mb/s").ToArray()));
            Log.WriteLine(true, "======");

            try
            {
                Log.WriteLine("Starting router... ");
                Log.ResetTimer();

                // Those objects create and start threads upon construction
                LRM = new LinkResourceManager(
                    id,
                    autonomicSystemId,
                    subnetworkId,
                    connectionControllerPort,
                    routingControllerPort,
                    mgmtLocalPort,
                    routerInterfaceDefs
                    );
                transportFunction = new TransportFunction(
                    sendIntervalMillis,
                    wirecloudLocalPort,
                    wirecloudRemotePort,
                    routerInterfaceDefs
                    );

                // Pass callbacks to components
                LRM.sendMgmtMessage = SendManagementMsg;
                LRM.sendPeerMessage = transportFunction.SendPeerMessage;
                transportFunction.handleMgmtPackets = LRM.HandleManagementPacket;

                // Launch rotuer management thread
                managementThread = new Thread(ReceiveManagementMsg);
                managementThread.Start();

#if DEBUG
                // Launch debug thread
                //debugTimer = new Timer((object state) =>
                // {
                //     Log.WriteLine("[DEBUG] Free resources on iface {0}: {1}", 1, 0);
                // }, null, 5000, 1000);
#endif
            }
            catch (ThreadStartException tse)
            {
                Log.WriteLine("failed:");
                Console.WriteLine(tse);
            }

            /*
             * Initialize routing table - in case the path is an empty
             * string or the file does not exist, an empty table will
             * be created.
             */
            try
            {
                transportFunction.ParseRoutingTable(routingTablePath);
            }
            catch (FileNotFoundException) // ParseRoutingTable throws FileNotFoundException if file is not found (duh!)
            {
                Log.WriteLine("[ERROR] Failed to load routing table from file (file not found)");
            }

            // Launch
            //StartPollingNMS(58000);

            // This method incorporates an infinite loop, so this
            // thread shall never exit.
            KeyboardControl();
        }