static void OnMsgEvent(int msgSeqNum, SendingBytes bytes) { if (!active) { return; } TimestampHelper.GetTicks(ref marks[counter].SendFinish); }
static void acceptor_BytesReceived(ReceivedBytes args) { if (!active) { return; } TimestampHelper.GetTicks(ref marks[counter].RecvStart); }
static void InboundApplicationMsgEvent(object sender, InboundApplicationMsgEventArgs args) { if (!active) { return; } TimestampHelper.GetTicks(ref marks[counter].RecvFinish); ++counter; ready.Set(); }
private static void Main(string[] args) { Process.GetCurrentProcess().PriorityClass = ProcessPriorityClass.RealTime; try { EngineSettings settings = new EngineSettings(); settings.SendLogoutOnInvalidLogon = true; settings.ResendingQueueSize = 0; settings.Dialect = "LatencyFixDictionary.xml"; settings.ValidateRequiredFields = false; settings.ValidateUnknownFields = false; settings.ValidateUnknownMessages = false; Engine.Init(settings); Dialect dialect = new Dialect("LatencyDictionaryId"); string rawMessage = "8=FIX.4.2\0019=3\00135=D\00149=OnixS\00156=CME\00134=01\00152=20120709-10:10:54\00111=90001008\001109=ClientID\00121=1\00155=ABC\00154=1\00138=100\00140=1\00160=20120709-10:10:54\00110=000\001"; rawMessage = rawMessage.Replace("\001", string.Empty + (char)0x01); // Please note that a Serialized Message is used here to facilitate the best possible latency. SerializedMessage order = new SerializedMessage(rawMessage); const int listenPort = 4501; #if DEBUG const int NumberOfMessages = 1000; #else const int NumberOfMessages = 50000; #endif marks = new SessionTimeMarks[NumberOfMessages]; const string senderCompId = "Acceptor"; const string targetCompId = "Initiator"; Session acceptor = new Session(senderCompId, targetCompId, dialect, false, SessionStorageType.MemoryBasedStorage); acceptor.InboundApplicationMsgEvent += new InboundApplicationMsgEventHandler(InboundApplicationMsgEvent); acceptor.BytesReceived += new BytesReceivedEventHandler(acceptor_BytesReceived); acceptor.ReuseIncomingMessage = true; acceptor.LogonAsAcceptor(); Session initiator = new Session(targetCompId, senderCompId, dialect, false, SessionStorageType.MemoryBasedStorage); initiator.MessageSending += new MessageSendingEventHandler(OnMsgEvent); initiator.ReuseIncomingMessage = true; initiator.LogonAsInitiator("localhost", listenPort, 30); active = true; SerializedFieldRef clientIDRef = order.Find(FIXForge.NET.FIX.FIX42.Tags.ClientID); if (clientIDRef == null) { throw new Exception("clientID field is not found"); } SerializedFieldKey clientIDKey = order.AllocateKey(clientIDRef); const string shortClientId = "ClientID"; const string LongClientId = "ClientIDClientIDClientIDClientID"; for (int i = 0; i < NumberOfMessages; ++i) { ready.WaitOne(); TimestampHelper.GetTicks(ref marks[counter].SendStart); order.Set(clientIDKey, i % 2 == 0 ? shortClientId : LongClientId); initiator.Send(order); } ready.WaitOne(); active = false; acceptor.Logout(); initiator.Logout(); acceptor.Dispose(); initiator.Dispose(); ReportSessionTimeMarksStatistics("Latency", marks, NumberOfMessages); Engine.Instance.Shutdown(); } catch (Exception ex) { Console.WriteLine("Exception: " + ex); } Console.WriteLine("Press <enter> for exit."); Console.ReadLine(); }