/// <summary> /// Constructs a controller for a new computation. /// </summary> /// <param name="config">Controller configuration</param> public BaseController(Configuration config) { this.configuration = config; this.localEndpoint = config.Endpoints == null ? new IPEndPoint(IPAddress.Any, 2101) : config.Endpoints[this.ProcessID]; this.workerGroup = new BaseWorkerGroup(this, config.WorkerCount); this.workerGroup.Start(); this.workerGroup.Activate(); if (this.Processes > 1) { this.defaultPlacement = new RoundRobinPlacement(this.Processes, this.workerGroup.Count); this.networkChannel = new TcpNetworkChannel(0, this, config); this.EnsureServerRunning(); this.networkChannel.WaitForAllConnections(); Logging.Info("Network channel activated"); } else { this.defaultPlacement = new RoundRobinPlacement(1, 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); if (Configuration.CollectNetStats) { int sleepTime = 1000; Logging.Progress("Monitoring network stats on interface {0} every {1}ms", Configuration.NetStatsInterfaceName, sleepTime); StreamWriter sw = new StreamWriter(File.Create("stats.txt")); var st = new StateForStats(this, sw, sleepTime, this.localEndpoint.Address); //Thread statsThrd = new Thread(new ParameterizedThreadStart(st.MonitorMemFootprint)); Thread statsThrd = new Thread(new ParameterizedThreadStart(st.MonitorNetwork)); cancelStatsToken = new CancellationTokenSource(); statsThrd.Start(cancelStatsToken.Token); } if (this.NetworkChannel != null) { this.NetworkChannel.StartMessageDelivery(); } this.graphsManaged = 0; this.graphManagers = new List <BaseGraphManager>(); }
/// <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>(); }