Пример #1
0
        /// <summary>
        /// Constructs a controller for a new computation.
        /// </summary>
        /// <param name="config">Controller configuration</param>
        public BaseController(Configuration config)
        {
            this.activated     = false;
            this.configuration = config;

            this.SerializationFormat = SerializationFactory.GetCodeGeneratorForVersion(config.SerializerVersion.First, config.SerializerVersion.Second);

            // set up an initial endpoint to try starting the server listening on. If endpoint is null
            // when we call the server constructor, it will choose one by picking an available port to listen on
            IPEndPoint endpoint = null;

            if (this.configuration.Endpoints != null)
            {
                endpoint = this.configuration.Endpoints[this.configuration.ProcessID];
            }

            // if we pass in a null endpoint the server will pick one and return it in the ref arg
            this.server        = new NaiadServer(ref endpoint);
            this.localEndpoint = endpoint;

            this.workerGroup = new BaseWorkerGroup(this, config.WorkerCount);

            this.workerGroup.Start();
            this.workerGroup.Activate();

            if (this.configuration.ReadEndpointsFromPPM || this.configuration.Processes > 1)
            {
                this.server.Start();

                if (this.configuration.ReadEndpointsFromPPM)
                {
                    int pId;
                    this.configuration.Endpoints = RegisterAndWaitForPPM(out pId);
                    this.configuration.ProcessID = pId;
                }

                if (this.configuration.Processes > 1)
                {
                    TcpNetworkChannel networkChannel = new TcpNetworkChannel(0, this, config);
                    this.networkChannel = networkChannel;

                    this.server.RegisterNetworkChannel(networkChannel);

                    this.server.AcceptPeerConnections();

                    this.networkChannel.WaitForAllConnections();

                    Logging.Info("Network channel activated");
                }
                else
                {
                    Logging.Info("Configured for single-process operation");
                }
            }

            this.defaultPlacement = new Placement.RoundRobin(this.configuration.Processes, this.workerGroup.Count);

#if DEBUG
            Logging.Progress("Warning: DEBUG build. Not for performance measurements.");
#endif

            if (this.workerGroup.Count < Environment.ProcessorCount)
            {
                Logging.Progress("Warning: Using fewer threads than available processors (use -t to set number of threads).");
            }

            Logging.Progress("Initializing {0} {1}", this.workerGroup.Count, this.workerGroup.Count == 1 ? "thread" : "threads");
            Logging.Progress("Server GC = {0}", System.Runtime.GCSettings.IsServerGC);
            Logging.Progress("GC settings latencymode={0}", System.Runtime.GCSettings.LatencyMode);
            Logging.Progress("Using CLR {0}", System.Environment.Version);

            NaiadTracing.Trace.ProcessInfo(this.configuration.ProcessID, System.Environment.MachineName);
            NaiadTracing.Trace.LockInfo(this.GlobalLock, "Controller lock");

            if (this.NetworkChannel != null)
            {
                this.NetworkChannel.StartMessageDelivery();
            }

            this.graphsManaged    = 0;
            this.baseComputations = new List <BaseComputation>();
        }