private void shortPool_ProcessNotHealthy(object sender, EventArgs e) { AgentProcess p = (AgentProcess)sender; // Check whether service timed out if (p.Runtime > p.MaxRuntime) { // Service timed out // Attempt to add the process to the long pool. // Increase timeout p.MaxRuntime = longPool.MaxPerProcessRuntime; if (!longPool.AddProcess(p)) { EPSEventLog.WriteEntry("Extended queue rejected process. Process will be terminated." + Environment.NewLine + p.ToString(), System.Diagnostics.EventLogEntryType.Warning); p.Stop(); // Stop the process if the long pool will not accept it. } else { // Must call RemoveProcess AFTER any possible process stopping, //because RemoveProcess unregisters events shortPool.RemoveProcess(p); EPSEventLog.WriteEntry("Process was moved to extended queue." + Environment.NewLine + p.ToString(), System.Diagnostics.EventLogEntryType.Warning); } } else { // Service exceeded memory limit EPSEventLog.WriteEntry("Process has exceeded maximum allowed memory. Process will be terminated." + Environment.NewLine + p.ToString(), System.Diagnostics.EventLogEntryType.Warning); p.Stop(); } }
private void monitorHealth() { try { while (keepRunning) { if (p.IsRunning && !p.IsHealthy) { p.Stop(); } Thread.Sleep(500); } // while(!workerProcess.HasExited && keepRunning) // { // uint workingSet = ProcUtils.GetProcessMemoryUsage(workerProcess.Id).WorkingSetSize; // if(workingSet>serviceMemMax) // { // EPSEventLog.WriteEntry("ServiceMemMaxMB="+serviceMemMaxMB.ToString()+Environment.NewLine+ // "Current Memory Usage (MB)="+(workingSet/Math.Pow(2d,20d)).ToString()+ // Environment.NewLine+"Shutting down process."+Environment.NewLine+ // "ServiceID="+this.ServiceID.ToString(), EventLogEntryType.Warning); // // workerProcess.Kill(); // return; // } // Thread.Sleep(5000); // } } catch (ThreadAbortException) {} catch (Exception exc) { EPSEventLog.WriteEntry("Error in monitorHealth() " + Environment.NewLine + exc.ToString(), EventLogEntryType.Error); } }
private void longPool_ProcessNotHealthy(object sender, EventArgs e) { // Stop unhealthy processes in long pool AgentProcess p = (AgentProcess)sender; // Check whether service timed out if (p.Runtime > p.MaxRuntime) { // Service timed out EPSEventLog.WriteEntry("Process timed out in extended queue. Process will be terminated." + Environment.NewLine + p.ToString(), System.Diagnostics.EventLogEntryType.Warning); p.Stop(); } else { // Service exceeded memory limit EPSEventLog.WriteEntry("Process has exceeded maximum allowed memory. Process will be terminated." + Environment.NewLine + p.ToString(), System.Diagnostics.EventLogEntryType.Warning); p.Stop(); } }