示例#1
0
        static void Main(string[] args)
        {
            int port = 8083;

            if (args.Length > 0)
            {
                port = int.Parse(args[0]);
            }
            string          localUrl   = string.Format("http://localhost:{0}/CommService", port);
            string          remoteUrl  = "http://localhost:8080/CommService";
            ReadClient      readClient = new ReadClient(localUrl, remoteUrl);
            ClientExtension fun        = new ClientExtension();

            readClient.addAct("keyQuery", fun.keyQuery());
            readClient.addAct("childrenQuery", fun.keysQuery());
            readClient.addAct("timeQuery", fun.keysQuery());
            readClient.addAct("specPatternQuery", fun.keysQuery());
            readClient.addAct("stringQuery", fun.keysQuery());
            if (readClient.readXmlFile("XMLFile1.xml"))
            {
                readClient.sendMessages();
            }
            Utilities.waitForUser();
            readClient.shutDown();
            Console.Write("\n\n");
        }
        static void Main(string[] args)
        {
            HiResTimer   timer    = new HiResTimer();
            Message      msg      = new Message();
            MessageMaker msgMaker = new MessageMaker();

            Console.Write("\nStarting Test Executive");
            Console.Write("\n=============================\n");
            Console.Title = "Read Client";
            ReadClient readClient = new ReadClient();

            if (args.Length == 2)
            {
                readClient.numMsg = Convert.ToInt32(args[1]);
            }
            readClient.processCommandLine(args);
            string   localPort = Util.urlPort(readClient.localUrl);
            string   localAddr = Util.urlAddress(readClient.localUrl);
            Receiver rcvr      = new Receiver(localPort, localAddr, timer);

            if (rcvr.StartService())
            {
                rcvr.doService(rcvr.defaultServiceAction());
            }
            Sender    sndr     = new Sender(readClient.localUrl); // Sender needs localUrl for start message
            XDocument xmlInput = readClient.GetInputFromXml();
            var       results  = xmlInput.Descendants("element");

            Console.Write("\n  sender's url is {0}", readClient.localUrl);
            Console.Write("\n  attempting to connect to {0}\n", readClient.remoteUrl);
            readClient.sendMessageToServer(results, timer, msgMaker, sndr, rcvr);
            //Wait until all messages from server are received.
            while (rcvr.count < readClient.numMsg)
            {
                sndr.SendReaderLatency(rcvr.totalExecutionTime / rcvr.count);
            }
            msg.content = "done";
            msg.fromUrl = readClient.localUrl;
            msg.toUrl   = readClient.remoteUrl;
            sndr.sendMessage(msg);
            Util.waitForUser();
            sndr.SendReaderLatency(rcvr.totalExecutionTime / rcvr.count);
            rcvr.shutDown();
            sndr.shutdown();
        }
示例#3
0
 static void Main(string[] args)
 {
        HiResTimer hres = new HiResTimer(); //High Resolution Timer
     Console.Write("\nStarting CommService Read client");
     Console.Write("\n =============================\n");
     Console.Title = "Read Client";
     Message msg = new Message();
     ReadClient clnt = new ReadClient();
     clnt.processCommandLine(args);
     string localPort = Util.urlPort(clnt.localUrl);
     string localAddr = Util.urlAddress(clnt.localUrl);
     Receiver rcvr = new Receiver(localPort, localAddr);
     Action serviceAction = DefineServiceAction(hres, clnt, rcvr);
     if (rcvr.StartService())
         rcvr.doService(serviceAction);
     Sender sndr = new Sender(clnt.localUrl);  // Sender needs localUrl for start message         
     msg.fromUrl = clnt.localUrl;
     msg.toUrl = clnt.remoteUrl;
     Console.Write("Sender's url is {0}", msg.fromUrl);
     Console.Write("Attempting to connect to {0}\n", msg.toUrl);
     if (!sndr.Connect(msg.toUrl))
     {
         Console.Write("Could not connect in {0} attempts\n", sndr.MaxConnectAttempts);
         sndr.shutdown();
         rcvr.shutDown();
         return;
     }
     msg = PerformanceTest(hres, msg, clnt, sndr);
     // Wait for user to press a key to quit.
     Util.waitForUser();
     // shut down this client's Receiver and Sender by sending close messages
     rcvr.shutDown();
     sndr.shutdown();
     Console.Write("\n\n");
 }
示例#4
0
 /// <summary>
 /// Define service action that needs to be handled for receiver requests at the client
 /// </summary>
 /// <param name="hres"></param>
 /// <param name="clnt"></param>
 /// <param name="rcvr"></param>
 /// <returns></returns>
 private static Action DefineServiceAction(HiResTimer hres, ReadClient clnt, Receiver rcvr)
 {
     return () =>
     {
         Message msg1 = null;
         while (true)
         {
             msg1 = rcvr.getMessage();
             if (msg1.content == "done")
             {
                 hres.Stop();
                 ulong lookUpTime = hres.ElapsedMicroseconds;
                 Message msg2 = new Message();
                 msg2.fromUrl = clnt.localUrl;
                 msg2.toUrl = clnt.wpfClientURL;
                 msg2.content = "LookupTime;" + lookUpTime + ";" + "CntMsg;" + (ulong)clnt.total + ";";
                 Sender wpfSender = new Sender(clnt.localUrl);
                 wpfSender.sendMessage(msg2);
                 Console.WriteLine("\n----------------------Overall Performance Statistics for Read Client-----------------------------\n");
                 Console.WriteLine("Number of messages processed is {0}", clnt.total);
                 Console.WriteLine("\nTotal Execution time for the messages to be processed at Client Side is {0} microsecs", clnt.ReadClientTime);
                 Console.WriteLine("\nAverage Execution time for the messages to be processed at Client Side is {0} microsecs", clnt.ReadClientTime / (ulong)clnt.total);
                 Console.WriteLine("\nTotal Execution time for the messages from Client-Server-Client {0} microsecs", lookUpTime);
                 Console.WriteLine("\nAverage Execution time for the messages from Client-Server-Client is {0} microsecs", lookUpTime / (ulong)clnt.total);
                 Console.WriteLine("\n----------------------Overall Performance Statistics for Read Client-----------------------------\n");
                 break;
             }
             else if (msg1.content == "connection start message")
                 Console.WriteLine("Connection start message receieved at client side");
             else
             {
                 XDocument docTemp = XDocument.Load(new StringReader(msg1.content));
                 string mid = docTemp.Descendants("OperationMessage").Elements("MessageID").Single().Value;
                 string op = docTemp.Descendants("OperationMessage").Elements("Operation").Single().Value;
                 string qt = docTemp.Descendants("OperationMessage").Elements("QueryType").Single().Value;
                 string resp = docTemp.Descendants("OperationMessage").Elements("Response").Single().Value;
                 Console.Write("\nMessage - MessageID:{0} received at the client", mid);
                 Console.Write("\nSender:{0}", msg1.fromUrl);
                 Console.Write("\nOperation :{0}", op);
                 Console.Write("\nQueryType :{0}", qt);
                 Console.Write("\nResponse :{0}", resp);
                 string oldDt = docTemp.Descendants("InsertTime").Select(i => i).Single().Value.ToString();
                 long microseconds = (DateTime.Now.Ticks - long.Parse(oldDt)) / 10;
                 Console.Write("\nExecution time for message(MessageID:{1}) is {0} microseconds\n", microseconds, mid);
             }
         }
         Util.waitForUser();
     };
 }
示例#5
0
 /// <summary>
 ///  GetByKeyCriteria criteria for the query type 
 /// </summary>
 /// <param name="hres"></param>
 /// <param name="msg"></param>
 /// <param name="clnt"></param>
 /// <param name="sndr"></param>
 /// <param name="timerH"></param>
 /// <param name="docTemp"></param>
 /// <param name="msgid"></param>
 private static void GetByKeyCriteria(HiResTimer hres, Message msg, ReadClient clnt, Sender sndr, HiResTimer timerH, out XDocument docTemp, out string msgid)
 {
     docTemp = XDocument.Load("Input.xml");
     clnt.RemoveOtherReads(ref docTemp, "GetKeyCriteria");
     clnt.RemoveOtherWrites(ref docTemp, "GetKeyCriteria");
     XElement k = docTemp.Descendants("OperationMessage").Where(d => d.Element("QueryType").Value == "GetKeyCriteria").Select(j => j).Single();
     clnt.numMsgs = int.Parse(k.Elements("Count").Single().Value);
     clnt.total += clnt.numMsgs;
     hres.Start();
     timerH.Start();//High resolution timer started       
     msgid = "";
     for (int i = 0; i < clnt.numMsgs; i++)
     {
         docTemp = XDocument.Load("Input.xml");
         clnt.RemoveOtherReads(ref docTemp, "GetKeyCriteria");
         clnt.RemoveOtherWrites(ref docTemp, "GetKeyCriteria");
         msgid = clnt.msgRand++.ToString();
         XElement y = null;
         y = docTemp.Descendants("OperationMessage").Where(d => d.Element("QueryType").Value == "GetKeyCriteria").Select(j => j).Single();
         y.Elements("MessageID").Single().Value = msgid;
         y.Elements("InsertTime").Single().Value = DateTime.Now.Ticks.ToString();
         msg.content = docTemp.ToString();
         msg.fromUrl = clnt.localUrl;
         msg.toUrl = clnt.remoteUrl;
         if (sndr.sendMessage(msg))
         {
             Console.Write("Sent message(Message ID {0}) to GetCriteria from key\n", msgid);
             Thread.Sleep(50);
         }
     }
 }
示例#6
0
 /// <summary>
 /// GetByMetadataCriteria criteria for the query type
 /// </summary>
 /// <param name="msg"></param>
 /// <param name="clnt"></param>
 /// <param name="sndr"></param>
 /// <param name="msgid"></param>
 /// <returns></returns>
 private static XDocument GetByMetadataCriteria(Message msg, ReadClient clnt, Sender sndr, ref string msgid)
 {
     XDocument docTemp = XDocument.Load("Input.xml");
     clnt.RemoveOtherReads(ref docTemp, "GetByMetadataCriteria");
     clnt.RemoveOtherWrites(ref docTemp, "GetByMetadataCriteria");
     XElement l = docTemp.Descendants("OperationMessage").Where(d => d.Element("QueryType").Value == "GetByMetadataCriteria").Select(j => j).Single();
     clnt.numMsgs = int.Parse(l.Elements("Count").Single().Value);
     clnt.total += clnt.numMsgs;
     for (int i = 0; i < clnt.numMsgs; i++)
     {
         docTemp = XDocument.Load("Input.xml");
         clnt.RemoveOtherReads(ref docTemp, "GetByMetadataCriteria");
         clnt.RemoveOtherWrites(ref docTemp, "GetByMetadataCriteria");
         msgid = clnt.msgRand++.ToString();
         XElement y = null;//GetByMetadataCriteria query carried out     
         y = docTemp.Descendants("OperationMessage").Where(d => d.Element("QueryType").Value == "GetByMetadataCriteria").Select(j => j).Single();
         y.Elements("MessageID").Single().Value = msgid;
         y.Elements("InsertTime").Single().Value = DateTime.Now.Ticks.ToString();
         msg.content = docTemp.ToString();
         msg.fromUrl = clnt.localUrl;
         msg.toUrl = clnt.remoteUrl;
         if (sndr.sendMessage(msg))
         {
             Console.Write("Sent message(Message ID {0}) to GetByMetadataCriteria from key\n", msgid);
             Thread.Sleep(50);
         }
     }
     return docTemp;
 }
示例#7
0
 /// <summary>
 /// Performance testing by inserting queries
 /// </summary>
 /// <param name="hres"></param>
 /// <param name="msg"></param>
 /// <param name="clnt"></param>
 /// <param name="sndr"></param>
 /// <returns></returns>
 private static Message PerformanceTest(HiResTimer hres, Message msg, ReadClient clnt, Sender sndr)
 {
     XmlTextReader textReader = new XmlTextReader("Input.xml");
     HiResTimer timerH = new HiResTimer();
     if (File.Exists("Input.xml"))
     {
         XDocument docTemp;
         string msgid;
         //GetKeyCriteria
         GetByKeyCriteria(hres, msg, clnt, sndr, timerH, out docTemp, out msgid);
         //GetByMetadataCriteria
         docTemp = GetByMetadataCriteria(msg, clnt, sndr, ref msgid);
         //GetByTimeStampCriteria
         docTemp = GetByTimeStampCriteria(msg, clnt, sndr, ref msgid);
         docTemp = GetByKey(msg, clnt, sndr, ref msgid);                //GetByKey
         docTemp = GetChildren(msg, clnt, sndr, ref msgid);                //GetChildren
     }
     timerH.Stop();
     clnt.ReadClientTime = timerH.ElapsedMicroseconds;
     msg = new Message();
     msg.fromUrl = clnt.localUrl;
     msg.toUrl = clnt.remoteUrl;
     msg.content = "done";
     sndr.sendMessage(msg);
     return msg;
 }