Пример #1
0
        /// <summary>
        /// Enqueues the event.
        /// </summary>
        /// <param name="mdEvent">The md event.</param>
        protected void EnqueueEvent(Object sender, MarketData mdEvent)
        {
            long nsTop = PerformanceObserver.NanoTime;

            executor.Execute(
                delegate {
                if (mdEvent != null)
                {
                    long ns = PerformanceObserver.NanoTime;
                    cepProvider.SendEvent(mdEvent);
                    long nsDone   = PerformanceObserver.NanoTime;
                    long msDelta  = (nsDone - mdEvent.Time) / 1000000;
                    long nsDelta1 = nsDone - ns;
                    long nsDelta2 = nsDone - nsTop;
                    //Console.WriteLine("D1:{0,10},\tD2:{1,15},\tMS:{2,6},\tQD:{3}", nsDelta1, nsDelta2, msDelta, e.QueueDepth);
                    StatsHolder.Engine.Update(nsDelta1);
                    StatsHolder.Server.Update(nsDelta2);
                    StatsHolder.EndToEnd.Update(msDelta);
                }
            });

            //stats
            countForStatSec++;
            if (Environment.TickCount - lastThroughputTick > statSec * 1E3)
            {
                countForStatSecLast = countForStatSec;
                countForStatSec     = 0;
                lastThroughputTick  = Environment.TickCount;
            }
        }
Пример #2
0
        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);
                }
            }
        }