public void Run() { Console.WriteLine("Event per s = {0}", simulationRate); int eventPer10Millis = (simulationRate / 100); Console.WriteLine("Event per 10ms = " + Math.Max(eventPer10Millis, 1)); MarketData[] market = new MarketData[Symbols.SYMBOLS.Length]; for (int i = 0; i < market.Length; i++) { market[i] = new MarketData(Symbols.SYMBOLS[i], Symbols.NextPrice(10), Symbols.NextVolume(10)); } try { int tickerIndex = 0; while (--iterationsLeft != 0) { long ms = _highResolutionTimeProvider.CurrentTime; for (int i = 0; i < eventPer10Millis; i++) { tickerIndex = tickerIndex % Symbols.SYMBOLS.Length; MarketData eventObj = market[tickerIndex++]; //note the cloning here, although we don't change volume or price MarketData simulatedEvent = (MarketData)eventObj.Clone(); executor.Execute( delegate { long ns = _highResolutionTimeProvider.CurrentTime; cepProvider.SendEvent(simulatedEvent); long nsDone = _highResolutionTimeProvider.CurrentTime; var statsInstance = StatsHolder.All; statsInstance.Engine.Update(nsDone - ns); statsInstance.Server.Update(nsDone - simulatedEvent.InTime); statsInstance.EndToEnd.Update((nsDone - simulatedEvent.Time) / 1000000); }); //stats countLast10s++; } var currentTime = _highResolutionTimeProvider.CurrentTime; if (currentTime - lastThroughputTick > statSec * 1E9) { //System.out.Println("Avg["+myID+"] " + countLast10s/10 + " active " + executor.GetPoolSize() + " pending " + executor.GetQueue().Count); countLast10sLast = countLast10s; countLast10s = 0; lastThroughputTick = currentTime; } // going to fast compared to target rate var deltaTime = currentTime - ms; if (deltaTime < 10000) { var slowDown = (int)Math.Max(1, 10000 - deltaTime); Thread.Sleep(slowDown); } } } catch (Exception e) { Console.WriteLine("Error receiving data from market. Did market disconnect?"); Console.WriteLine("Error message: {0}", e.Message); Console.WriteLine(e.StackTrace); } finally { lock (CLIENT_CONNECTIONS_LOCK) { CLIENT_CONNECTIONS.Remove(myID); } } }