public override void ConsumeBuffered(WorkloadEvent evnt) { if (!(evnt is ExecutionWorkloadEvent)) { return; } if (evnt.Type != WorkloadEvent.EventType.RPCCompleted && evnt.Type != WorkloadEvent.EventType.BatchCompleted) { return; } ExecutionWorkloadEvent evt = (ExecutionWorkloadEvent)evnt; ReplayCommand command = new ReplayCommand() { CommandText = evt.Text, Database = evt.DatabaseName, ApplicationName = evt.ApplicationName }; int session_id = -1; session_id = (int)evt.SPID; ReplayWorker rw = null; if (ReplayWorkers.TryGetValue(session_id, out rw)) { rw.AppendCommand(command); } else { rw = new ReplayWorker() { ConnectionInfo = this.ConnectionInfo, ReplayIntervalSeconds = 0, StopOnError = false, Name = session_id.ToString() }; ReplayWorkers.TryAdd(session_id, rw); rw.AppendCommand(command); logger.Info(String.Format("Worker [{0}] - Starting", session_id)); } if (runner == null) { runner = new Thread(new ThreadStart( delegate { try { RunWorkers(); } catch (Exception e) { try { logger.Error(e, "Unhandled exception in TraceManager.RunWorkers"); } catch { Console.WriteLine(e.Message); } } } )); runner.IsBackground = true; runner.Start(); } if (sweeper == null) { sweeper = new Thread(new ThreadStart( delegate { try { RunSweeper(); } catch (Exception e) { try { logger.Error(e, "Unhandled exception in TraceManager.RunSweeper"); } catch { Console.WriteLine(e.Message); } } } )); sweeper.IsBackground = true; sweeper.Start(); } }
public override void ConsumeBuffered(WorkloadEvent evnt) { if (evnt is MessageWorkloadEvent) { MessageWorkloadEvent msgEvent = evnt as MessageWorkloadEvent; if (msgEvent.MsgType == MessageWorkloadEvent.MessageType.TotalEvents) { try { totalEventCount = (long)msgEvent.Value; } catch (Exception e) { logger.Error($"Unable to set the total number of events: {e.Message}"); } } } if (!(evnt is ExecutionWorkloadEvent)) { return; } if (evnt.Type != WorkloadEvent.EventType.RPCCompleted && evnt.Type != WorkloadEvent.EventType.BatchCompleted) { return; } eventCount++; if ((eventCount > 0) && (eventCount % WorkerStatsCommandCount == 0)) { string percentInfo = (totalEventCount > 0) ? "( " + ((eventCount * 100) / totalEventCount).ToString() + "% )" : ""; logger.Info($"{eventCount} events queued for replay {percentInfo}"); } if (startTime == DateTime.MinValue) { startTime = DateTime.Now; } ExecutionWorkloadEvent evt = (ExecutionWorkloadEvent)evnt; ReplayCommand command = new ReplayCommand() { CommandText = evt.Text, Database = evt.DatabaseName, ApplicationName = evt.ApplicationName, ReplayOffset = evt.ReplayOffset, EventSequence = evt.EventSequence }; int session_id = -1; session_id = (int)evt.SPID; ReplayWorker rw = null; if (ReplayWorkers.TryGetValue(session_id, out rw)) { // Ensure that the buffer does not get too big while (rw.QueueLength >= (BufferSize * .9)) { spin.SpinOnce(); } rw.AppendCommand(command); } else { rw = new ReplayWorker() { ConnectionInfo = this.ConnectionInfo, ReplayIntervalSeconds = 0, StopOnError = false, Name = session_id.ToString(), DisplayWorkerStats = this.DisplayWorkerStats, ConsumeResults = this.ConsumeResults, QueryTimeoutSeconds = this.QueryTimeoutSeconds, WorkerStatsCommandCount = this.WorkerStatsCommandCount, MimicApplicationName = this.MimicApplicationName, DatabaseMap = this.DatabaseMap, StartTime = startTime, FailRetryCount = this.FailRetryCount, TimeoutRetryCount = this.TimeoutRetryCount }; ReplayWorkers.TryAdd(session_id, rw); rw.AppendCommand(command); logger.Info($"Worker [{session_id}] - Starting"); } if (runner == null) { runner = new Thread(new ThreadStart( delegate { try { RunWorkers(); } catch (Exception e) { try { logger.Error(e, "Unhandled exception in ReplayConsumer.RunWorkers"); } catch { Console.WriteLine(e.Message); } } } )); runner.IsBackground = true; runner.Start(); } if (sweeper == null) { sweeper = new Thread(new ThreadStart( delegate { try { RunSweeper(); } catch (Exception e) { try { logger.Error(e, "Unhandled exception in TraceManager.RunSweeper"); } catch { Console.WriteLine(e.Message); } } } )); sweeper.IsBackground = true; sweeper.Start(); } }
public override void ConsumeBuffered(WorkloadEvent evnt) { if (!(evnt is ExecutionWorkloadEvent)) { return; } if (evnt.Type != WorkloadEvent.EventType.RPCCompleted && evnt.Type != WorkloadEvent.EventType.BatchCompleted) { return; } eventCount++; if ((eventCount > 0) && (eventCount % WorkerStatsCommandCount == 0)) { logger.Info($"{eventCount} events queued for replay"); } ExecutionWorkloadEvent evt = (ExecutionWorkloadEvent)evnt; ReplayCommand command = new ReplayCommand() { CommandText = evt.Text, Database = evt.DatabaseName, ApplicationName = evt.ApplicationName, BeforeSleepMilliseconds = evt.ReplaySleepMilliseconds }; int session_id = -1; session_id = (int)evt.SPID; ReplayWorker rw = null; if (ReplayWorkers.TryGetValue(session_id, out rw)) { // Ensure that the buffer does not get too big while (rw.QueueLength >= (BufferSize * .9)) { spin.SpinOnce(); } rw.AppendCommand(command); } else { rw = new ReplayWorker() { ConnectionInfo = this.ConnectionInfo, ReplayIntervalSeconds = 0, StopOnError = false, Name = session_id.ToString(), DisplayWorkerStats = this.DisplayWorkerStats, ConsumeResults = this.ConsumeResults, QueryTimeoutSeconds = this.QueryTimeoutSeconds, WorkerStatsCommandCount = this.WorkerStatsCommandCount, MimicApplicationName = this.MimicApplicationName }; ReplayWorkers.TryAdd(session_id, rw); rw.AppendCommand(command); logger.Info($"Worker [{session_id}] - Starting"); } if (runner == null) { runner = new Thread(new ThreadStart( delegate { try { RunWorkers(); } catch (Exception e) { try { logger.Error(e, "Unhandled exception in TraceManager.RunWorkers"); } catch { Console.WriteLine(e.Message); } } } )); runner.IsBackground = true; runner.Start(); } if (sweeper == null) { sweeper = new Thread(new ThreadStart( delegate { try { RunSweeper(); } catch (Exception e) { try { logger.Error(e, "Unhandled exception in TraceManager.RunSweeper"); } catch { Console.WriteLine(e.Message); } } } )); sweeper.IsBackground = true; sweeper.Start(); } }