Beispiel #1
0
        public void threadStartMethod()
        {
            while (keepRunning)
            {
                switch (systemState)
                {
                case NodeExecutionState.WaitForStart:
                    // check if nodes are ready to start and start them when everyone is ready
                    if (nodesToWaitWithStartingFor.Count() == 0)
                    {
                        Console.WriteLine(TAG + " All nodes ready. Transitioning into run phase.");
                        broadcastUpdatedExecutionState(NodeExecutionState.DoStartInputGeneration);

                        if (settings.duration == 0)
                        {
                            Console.WriteLine(TAG + "running indefinitely from now on, DirectorNodeService is terminating.");
                            return;
                        }

                        systemState = NodeExecutionState.Running;
                        stopwatch.Start();
                    }
                    else
                    {
                        Console.WriteLine(TAG + "Waiting for node(s) " + string.Join(",", nodesToWaitWithStartingFor.Select(x => x.ToString())) + " to signal they are ready to start.");
                        Thread.Sleep(1000);
                    }
                    break;

                case NodeExecutionState.Running:
                    // check the timer and send "stop input generation" requests once the timer is over
                    if ((stopwatch.ElapsedMilliseconds - this.durationMS) > 0)
                    {
                        broadcastUpdatedExecutionState(NodeExecutionState.DoStopInputGeneration);
                        systemState = NodeExecutionState.ProcessingRemainder;
                        Console.WriteLine(TAG + "Requested to stop input event generation on all nodes. Now waiting for all nodes to finish processing their event queues.");
                    }

                    break;

                case NodeExecutionState.ProcessingRemainder:
                    // wait until all message queues are empty, then possibly count messages and send "terminate" requests
                    var nowMS = stopwatch.ElapsedMilliseconds;

                    if (lastReadyToTerminateSignalTime.Values.ToList().All(timestamp => timestamp != -1 && nowMS - timestamp < 1000))
                    {
                        Console.WriteLine(TAG + "Done. All nodes signaled their queues are empty within the last second. Requesting to terminate query processing on all nodes.");
                        broadcastUpdatedExecutionState(NodeExecutionState.DoSendExperimentDataAndTerminate);


                        // gathering experiment run data
                        Console.WriteLine(TAG + "Waiting for all nodes to send their ExperimentRunData");

                        while (experimentRunDataByNodeName.Values.ToList().Contains(null))
                        {
                            while (!experimentRunMessageQueue.Data.IsEmpty)
                            {
                                ExperimentRunNodeDataMessage m = null;
                                if (experimentRunMessageQueue.Data.TryDequeue(out m))
                                {
                                    experimentRunDataByNodeName[m.sendingNode] = m.nodeData;
                                    Console.WriteLine(TAG + "Received experiment data from node " + m.sendingNode);
                                }
                            }

                            Thread.Sleep(100);
                        }

                        // all experiment data was received
                        Console.WriteLine(TAG + "ExperimentRunData was received from all nodes. Printing the result and terminating.");

                        long totalSentEvents              = 0;
                        long totalGeneratedComplexEvents  = 0;
                        long totalGeneratedPrimtiveEvents = 0;
                        long totalDroppedComplexEvents    = 0;

                        foreach (var item in experimentRunDataByNodeName)
                        {
                            totalSentEvents              += item.Value.receivedEventCount;
                            totalGeneratedComplexEvents  += item.Value.locallyGeneratedComplexEventCount;
                            totalGeneratedPrimtiveEvents += item.Value.locallyGeneratedPrimitiveEventCount;
                            totalDroppedComplexEvents    += item.Value.locallyDroppedComplexEvents;
                        }

                        Console.WriteLine("");
                        Console.WriteLine("Total number of generated complex events:  " + totalGeneratedComplexEvents);
                        Console.WriteLine("Total number of generated primitive events:  " + totalGeneratedPrimtiveEvents);
                        Console.WriteLine("Total number of events sent over network:  " + totalSentEvents);
                        Console.WriteLine("Total number of dropped complex events: " + totalDroppedComplexEvents);

                        localNodeCanTerminate = true;
                        return;
                    }
                    else
                    {
                        Thread.Sleep(100);
                    }

                    break;
                }
            }
        }
Beispiel #2
0
 void ReceiveExperimentRunData(ExperimentRunNodeDataMessage message)
 {
     experimentRunMessageQueue.Data.Enqueue(message);
 }