/// <summary> /// Process object that represents running runner script.</summary> public ProActiveRuntimeExecutor(CommonStartInfo commonStartInfo, int rank) { this.commonStartInfo = commonStartInfo; this.rank = rank; if (this.rank == 0) { // Init the next usable ProActive Port specified by the configuration nextUsableProActivePort = commonStartInfo.configuration.config.portRange.first; } // Init the current and increment the next usable port this.currentProActivePort = nextUsableProActivePort++; this.LOGGER = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType + "" + rank); // The logger needs to be customized programmatically to log stout/stderr into a separate file this.processLogger = LogManager.GetLogger("Executor" + rank + "ProcessLogger"); Logger customLogger = this.processLogger.Logger as log4net.Repository.Hierarchy.Logger; if (customLogger != null) { customLogger.Additivity = false; customLogger.AddAppender(createRollingFileAppender(rank) /*, commonStartInfo.logsDirectory */); } // The restart timer is only created it will not start until Timer.Change() method is called this.restartTimer = new Timer(new TimerCallback(internalRestart), null, System.Threading.Timeout.Infinite, System.Threading.Timeout.Infinite); this.restartBarrierDateTime = DateTime.MaxValue; this.callersState = new Dictionary <ApplicationType, Int32>(); this.rootProcess = null; // Create a new job object for limits this.jobObject = new JobObject(Constants.JOB_OBJECT_NAME + rank); this.jobObject.Events.OnNewProcess += new jobEventHandler <NewProcessEventArgs>(Events_OnNewProcess); // If memory management is enabled ushort memoryLimit = commonStartInfo.configuration.config.memoryLimit; if (memoryLimit != 0) { // Add user defined memory limitations this.jobObject.Limits.JobMemoryLimit = new IntPtr(memoryLimit * 1024 * 1024); LOGGER.Info("A memory limitation of " + memoryLimit + " Mbytes is set for the ProActive Runtime process (and its children)"); // Add event handler to keep track of job events this.jobObject.Events.OnJobMemoryLimit += new jobEventHandler <JobMemoryLimitEventArgs>(Events_OnJobMemoryLimit); } // Apply priority this.jobObject.Limits.PriorityClass = commonStartInfo.configuration.config.processPriority; // Children process will not be able to escape from job this.jobObject.Limits.CanChildProcessBreakAway = false; // Create new instance of the cpu limiter this.cpuLimiter = new CPULimiter(); }
// For test purpose static void Main0(string[] args) { Process[] par = Process.GetProcessesByName("ProcessLauncher"); CPULimiter cpuLimiter = new CPULimiter(); cpuLimiter.addProcessToWatchList(par[0]); cpuLimiter.setNewMaxCpuUsage(10); // Wait a little System.Threading.Thread.Sleep(20000); cpuLimiter.addProcessToWatchList(par[1]); System.Threading.Thread.Sleep(10000); cpuLimiter.setNewMaxCpuUsage(20); System.Threading.Thread.Sleep(10000); // Clear the watch list cpuLimiter.clearWatchList(); // processes should be at 100% !each! during 10 secs System.Threading.Thread.Sleep(10000); // add the processes again cpuLimiter.addProcessToWatchList(par[0]); cpuLimiter.addProcessToWatchList(par[1]); // should be limited to 20% System.Threading.Thread.Sleep(10000); cpuLimiter.clearWatchList(); Console.ReadLine(); }