// This method never throws - possible exception already handled inside. private bool GenerateMessageSafe() { bool quitLifeCycle = false; try { State = WorkerState.Busy; bool completed = GenerateMessageNetTimed(); WorkerStatistics.Send(); if (completed) { Tracer.Info("First worker {0} reports completion!", WorkerId); State = WorkerState.Completed; quitLifeCycle = true; } } catch (Exception ex) { ex.Trace().Swallow(); ProblemReport problemReport = new ProblemReport(WorkerId, WorkerStage.WorkerStep, ex); problemReport.SendProblemReport(ReportPipe); quitLifeCycle = true; // Worker which caused unhandled exception should quit rather than try to process more messages } return(quitLifeCycle); }
private void ProcessWorkerStatistics(WorkerStatistics workerStatistics) { PipelineSection pipelineSection = FindPipelineSection(workerStatistics.WorkerBadge.SectionName); if (pipelineSection == null) { return; } WorkerStatus workerStatus; bool found = pipelineSection.WorkerStatuses.TryGetValue(workerStatistics.WorkerBadge.WorkerId, out workerStatus); if (found) { workerStatus.WorkerStatistics = workerStatistics; } else { workerStatus = new WorkerStatus() { WorkerStatistics = workerStatistics }; pipelineSection.WorkerStatuses.Add(workerStatistics.WorkerBadge.WorkerId, workerStatus); } StatisticsAvailable = true; //Tracer.Trace("Worker {0} stat: processed {1} documents, NetTime {2:0.#} seconds, NetSpeed {3:0.##} docs/sec", // workerStatistics.WorkerId, // workerStatistics.ProcessedDocuments, // workerStatistics.WorkTimeNet.TotalSeconds, // workerStatistics.PersonalSpeedNet // ); }
protected void IncreaseProcessedDocumentsCount(int addedDocumentsCount) { if (WorkerStatistics != null) { WorkerStatistics.IncreaseProcessedDocumentsCount(addedDocumentsCount); } }
/// <summary> /// Inits this instance. /// </summary> /// <remarks></remarks> private void Init() { try { InputDataPipeReceiveTimeout = new TimeSpan(0, 0, 10); PauseSleep = new TimeSpan(0, 0, 0, 10); RoleType = new RoleType(Utils.RemoveSuffix(GetType().Name, "Worker")); Debug.Assert(WorkerId != null); PipelineType = WorkAssignment.WorkRequest.PipelineType; PipelineId = WorkAssignment.WorkRequest.PipelineId; BootParameters = WorkAssignment.WorkRequest.BootParameters; JobParameters = WorkAssignment.WorkRequest.JobParameters; ReportPipe = new Pipe(WorkAssignment.WorkRequest.ReportPipeName); ReportPipe.Open(); WorkerStatistics = new WorkerStatistics(WorkAssignment, Environment.MachineName, ReportPipe); ReportPipe.Before = WorkerStatistics.PauseNetTime; ReportPipe.After = WorkerStatistics.ResumeNetTime; SetupInputDataPipe(WorkAssignment.WorkRequest.InputDataPipeName); SetupOutputSections(WorkAssignment.WorkRequest.OutputSections); SetupLogPipe(WorkAssignment.WorkRequest.LogDataPipeName); } catch (Exception ex) { Tracer.Fatal("Unable to initialize worker {0}. Exception: {1}", WorkerId, ex); throw; } }
/// <summary> /// Sets the total document count. /// </summary> /// <param name="totalDocumentCount">The total document count.</param> private void SetTotalDocumentCount(int totalDocumentCount) { if (WorkerStatistics == null) { return; } WorkerStatistics.PunchInNet(); WorkerStatistics.SetTotalDocumentCount(totalDocumentCount); WorkerStatistics.PunchOutNet(); WorkerStatistics.Send(); }
private bool GenerateMessageGrossTimed() { bool quitLifeCycle; try { WorkerStatistics.PunchInGross(); quitLifeCycle = GenerateMessageSafe(); } finally { WorkerStatistics.PunchOutGross(); } return(quitLifeCycle); }
private bool ProcessMessageGrossTimed() { bool quitLifeCycle; try { WorkerStatistics.PunchInGross(); quitLifeCycle = this.ProcessMessageTrans(); } finally { WorkerStatistics.PunchOutGross(); } return(quitLifeCycle); }
private bool GenerateMessageNetTimed() { bool completed; try { //Tracer.Trace("First Worker {0} processing message", WorkerId); WorkerStatistics.PunchInNet(); completed = GenerateMessage(); //Tracer.Trace("First Worker {0} processed message", WorkerId); } finally { WorkerStatistics.PunchOutNet(); } return(completed); }
private void ProcessMessageNetTimed(PipeMessageEnvelope message) { //long envelopeSize = Utils.BinSizeOf(message); //long bodySize = Utils.BinSizeOf(message.Body); //Tracer.Trace("Worker {0} received message of the size {1}/{2}", WorkerId, envelopeSize, bodySize); try { //Tracer.Trace("Worker {0} processing message", WorkerId); WorkerStatistics.PunchInNet(); ProcessMessage(message); //Tracer.Trace("Worker {0} processed message", WorkerId); } finally { WorkerStatistics.PunchOutNet(); WorkerStatistics.RecordInputTraffic(message); } }
// We have two similar workflows here: // One is for the first worker - it starts with GenerateMessageGrossTimed() // Another is for the next workers - it starts with ProcessMessageGrossTimed() // GenerateMessageGrossTimed - measuring gross time (includes sending) spent producing messages. // GenerateMessageSafe - here exceptions are handled // GenerateMessageNetTimed - here we measure the time spent in the user method alone // ProcessMessageGrossTimed - measuring gross time (includes receiving and sending) spent processing messages. // ProcessMessageTrans - Create transaction for message receive, so that current message is still counted against the input queue // until we are fully done with it. // ProcessMessageSafe - here exceptions are handled. // ProcessMessageNoTrans - Prevent propagation of the ambient transaction used for remote transactional receive to concrete workers // ProcessMessage method. // ProcessMessageNetTimed - here we measure the time spent in the user method alone. private void RunWorker() { // This is worker life cycle while (true) { Command command = GetCommandFromManager(); if (command == Command.Cancel) { break; } if (command == Command.Pause) { State = WorkerState.Paused; Thread.Sleep(PauseSleep); continue; } Guid prevActivityId = Trace.CorrelationManager.ActivityId; Trace.CorrelationManager.ActivityId = Guid.NewGuid(); bool quitLifeCycle; if (null == InputDataPipe) { quitLifeCycle = GenerateMessageGrossTimed(); } else { quitLifeCycle = ProcessMessageGrossTimed(); } Trace.CorrelationManager.ActivityId = prevActivityId; if (quitLifeCycle) { break; } } // Last stat for worker WorkerStatistics.ForceSend(); }
private void ProcessReport(PipeMessageEnvelope envelope) { if (_reportPipeMessageCounter++ == 0) { _timeSinceTheFirstReportReceived.Start(); } object message = envelope.Body; WorkerStateChangedMessage workerStateChangedMessage = message as WorkerStateChangedMessage; if (workerStateChangedMessage != null) { ProcessWorkerStateChangeReports(workerStateChangedMessage); } WorkerStatistics workerStatistics = message as WorkerStatistics; if (workerStatistics != null) { ProcessWorkerStatistics(workerStatistics); } WorkerMessage workerMessage = message as WorkerMessage; if (workerMessage != null) { ProcessWorkerMessage(workerMessage); } ProblemReport problemReport = message as ProblemReport; if (problemReport != null) { ProcessProblemReport(problemReport); } }
// This method never throws - possible exception already handled inside. private bool ProcessMessageSafe() { bool quitLifeCycle = false; try { #if RECEIVE_WAITS PipeMessageEnvelope message = InputDataPipe.Receive(InputDataPipeReceiveTimeout); #else PipeMessageEnvelope message = InputDataPipe.Receive(_zeroWait); #endif if (null != message) { State = WorkerState.Busy; SlowDownPostbacks(message); ProcessMessageNoTrans(message); } else { State = WorkerState.Idle; #if RECEIVE_WAITS WorkerStatistics.RecordIdleTime(InputDataPipeReceiveTimeout); #else Thread.Sleep(InputDataPipeReceiveTimeout); #endif } WorkerStatistics.Send(); } catch (Exception ex) { ex.Trace().Swallow(); ProblemReport problemReport = new ProblemReport(WorkerId, WorkerStage.WorkerStep, ex); problemReport.SendProblemReport(ReportPipe); quitLifeCycle = true; // Worker which caused unhandled exception should quit rather than try to process more messages } return(quitLifeCycle); }
/// <summary> /// Inits this instance. /// </summary> /// <remarks></remarks> private void Init() { try { InputDataPipeReceiveTimeout = new TimeSpan(0, 0, 10); PauseSleep = new TimeSpan(0, 0, 0, 10); RoleType = new RoleType(Utils.RemoveSuffix(GetType().Name, "Worker")); Debug.Assert(WorkerId != null); PipelineType = WorkAssignment.WorkRequest.PipelineType; PipelineId = WorkAssignment.WorkRequest.PipelineId; BootParameters = WorkAssignment.WorkRequest.BootParameters; JobParameters = WorkAssignment.WorkRequest.JobParameters; ReportPipe = new Pipe(WorkAssignment.WorkRequest.ReportPipeName); ReportPipe.Open(); WorkerStatistics = new WorkerStatistics(WorkAssignment, Environment.MachineName, ReportPipe); ReportPipe.Before = WorkerStatistics.PauseNetTime; ReportPipe.After = WorkerStatistics.ResumeNetTime; SetupInputDataPipe(WorkAssignment.WorkRequest.InputDataPipeName); SetupOutputSections(WorkAssignment.WorkRequest.OutputSections); SetupLogPipe(WorkAssignment.WorkRequest.LogDataPipeName); } catch (Exception ex) { Tracer.Fatal("Unable to initialize worker {0}. Exception: {1}", WorkerId, ex); throw; } }