Exemplo n.º 1
0
        protected override void execute(CommandData argument)
        {
            IPart req = new PartStruct()
                        .Add("cmd", "performance")
                        .Add("data", new PartStruct()
                             .Add("clients", data.GetSelectedClients()));
            JSONParser replyData = new JSONParser(data.server.SendMessageAsync(req.ToJSON()).Result);

            Console.WriteLine(replyData.ToJSON());
            IPart ok    = replyData["ok"];
            IPart error = null;

            foreach (IPart enemy in ok)
            {
                Console.WriteLine(enemy.ByPath("name").GetValue <string>());
                if (enemy.ByPathSave("result.exception", out error))
                {
                    Console.WriteLine("\t{0}", error.GetValue <string>());
                }
                else
                {
                    Console.WriteLine("\tsearch:\t{0}", enemy.ByPath("result.search").GetValue <double>());
                    Console.WriteLine("\tsort:\t{0}", enemy.ByPath("result.sort").GetValue <double>());
                    Console.WriteLine("\tbinary search:\t{0}", enemy.ByPath("result.binary search").GetValue <double>());
                }
            }

            //{"ok":[{"name":"testIOTClient2 in groupe test Group", "result":{"search":0.0758679085520745, "sort":0.42851164921216, "binary search":0.149432267030568}}]}
        }
Exemplo n.º 2
0
        //{cmd:clients, data:{name, groupe}}
        protected override void execute(CommandData argument)
        {
            IPart reqData = new PartStruct();
            IPart req     = new PartStruct()
                            .Add("cmd", "clients")
                            .Add("data", reqData);

            if (argument.IsKey('n'))
            {
                reqData.Add("name", argument.GetKeyValue <String>('n'));
            }
            if (argument.IsKey('g'))
            {
                reqData.Add("groupe", argument.GetKeyValue <String>('g'));
            }

            JSONParser replyData = new JSONParser(data.server.SendMessageAsync(req.ToJSON()).Result);

            data.selected.Clear();

            Console.WriteLine("{0} client(s) have found", replyData.Data.Count);
            foreach (IPart part in replyData.Data)
            {
                data.selected.Add(new Client(part.ByPath("address").GetValue <string>(),
                                             part.ByPath("name").GetValue <string>(),
                                             part.ByPath("groupe").GetValue <string>(),
                                             part.ByPath("id").GetValue <string>()
                                             ));
            }
        }
Exemplo n.º 3
0
        /*
         *  run load test with selected random distribution
         *  use as:
         *  LoadTest -r type_of_random_distribution
         *      normal -m double_num -d double_num
         *      gamma -a double_num -l double_num
         *      erlang -m uint_num, -l double_num
         *      pareto -x double_num -a double_num
         */

        //request {"cmd":"load", data: {"data_count": 1000, "distribution": "normal", "m": 0, "d": 1, "clients":[]}}
        protected override void execute(CommandData argument)
        {
            uint   count             = argument.GetKeyValue <UInt32>('c');
            string distribution_type = argument.GetKeyValue <string>('r');
            IPart  dataToRequest     = new PartStruct();

            if (distribution_type == "normal")
            {
                dataToRequest.Add("m", argument.GetKeyValue <double>('m'));
                dataToRequest.Add("d", argument.GetKeyValue <double>('d'));
            }
            else if (distribution_type == "gamma")
            {
                dataToRequest.Add("a", argument.GetKeyValue <double>('a'));
                dataToRequest.Add("l", argument.GetKeyValue <double>('l'));
            }
            else if (distribution_type == "erlang")
            {
                dataToRequest.Add("m", argument.GetKeyValue <uint>('m'));
                dataToRequest.Add("l", argument.GetKeyValue <double>('l'));
            }
            else if (distribution_type == "pareto")
            {
                dataToRequest.Add("x", argument.GetKeyValue <double>('x'));
                dataToRequest.Add("a", argument.GetKeyValue <double>('a'));
            }
            else
            {
                throw new Exception("wrong distribution type");
            }
            dataToRequest
            .Add("distribution", distribution_type)
            .Add("data_count", count)
            .Add("clients", data.GetSelectedClients());

            IPart request = new PartStruct()
                            .Add("cmd", "load")
                            .Add("data", dataToRequest);

            JSONParser replyData = new JSONParser(data.server.SendMessageAsync(request.ToJSON()).Result);
            IPart      ok        = replyData["ok"];
            IPart      error     = null;

            foreach (IPart enemy in ok)
            {
                Console.WriteLine(enemy.ByPath("name").GetValue <string>());
                if (enemy.ByPathSave("result.exception", out error))
                {
                    Console.WriteLine("\t{0}", error.GetValue <string>());
                }
                else
                {
                    Console.WriteLine("\tjitter:\t{0}", enemy.ByPath("result.jitter").GetValue <string>());
                    Console.WriteLine("\tdelay:\t{0}", enemy.ByPath("result.delay").GetValue <string>());
                    Console.WriteLine("\tspeed:\t{0}", enemy.ByPath("result.speed").GetValue <string>());
                    Console.WriteLine("\tmissed:\t{0}", enemy.ByPath("result.missed").GetValue <string>());
                }
            }
            //Console.WriteLine(replyData.ToJSON());
        }
Exemplo n.º 4
0
        /*
         * requ	{"data_count": 1000, "distribution": "normal", "m": 0, "d": 1, "clients":[]}
         */
        public override void Execute(ClientData argument)
        {
            uint  count = argument.data["data_count"].GetValue <uint>();
            IPart hid   = argument.data["clients"];

            argument.data.Data.Remove("clients");

            Task <IPart>[] workers          = new Task <IPart> [hid.Count];
            Client[]       selected_clients = new Client[hid.Count];

            string req = new PartStruct()
                         .Add("cmd", "load")
                         .Add("data", argument.data.Data).ToJSON();
            int index = 0;

            foreach (IPart cli in hid)
            {
                Client currentClient = data.clients[cli.GetValue <string>()];
                selected_clients[index] = currentClient;
                workers[index]          = Task.Factory.StartNew(() => {
                    return(TestForSingleIotClient(currentClient, req, count));
                });
                index++;
            }

            IPart container     = new PartArray();
            IPart sendedMessage = new PartStruct().Add("ok", container);

            Task.WaitAll(workers);
            for (int i = 0; i < workers.Length; i++)
            {
                container.Add(new PartStruct().Add("name", selected_clients[i].ToString()).Add("result", workers[i].Result));
            }
            argument.client.SendMessageAsync(sendedMessage.ToJSON());
        }
Exemplo n.º 5
0
        //{cmd: StressTest data: {dataCount, clients:[]}}
        protected override void execute(CommandData argument)
        {
            uint count = argument.GetKeyValue <UInt32>('c');

            IPart req = new PartStruct()
                        .Add("cmd", "stress")
                        .Add("data", new PartStruct()
                             .Add("dataCount", count)
                             .Add("clients", data.GetSelectedClients())
                             );
            JSONParser replyData = new JSONParser(data.server.SendMessageAsync(req.ToJSON()).Result);
            IPart      ok        = replyData["ok"];
            IPart      error     = null;

            foreach (IPart enemy in ok)
            {
                Console.WriteLine(enemy.ByPath("name").GetValue <string>());
                if (enemy.ByPathSave("result.exception", out error))
                {
                    Console.WriteLine("\t{0}", error.GetValue <string>());
                }
                else
                {
                    Console.WriteLine("\tjitter:\t{0}", enemy.ByPath("result.jitter").GetValue <string>());
                    Console.WriteLine("\tdelay:\t{0}", enemy.ByPath("result.delay").GetValue <string>());
                    Console.WriteLine("\tspeed:\t{0}", enemy.ByPath("result.speed").GetValue <string>());
                    Console.WriteLine("\tmissed:\t{0}", enemy.ByPath("result.missed").GetValue <string>());
                }
            }
            //Console.WriteLine(replyData.ToJSON());
            //{"ok":[{"name":"testIOTClient2 in groupe test Group", "result":{"jitter":"2,45700712904944E-09 c", "delay":"4,95685781053388E-05 c", "speed":"82,6329936536718 Mbit/c", "missed":"33,244%"}}]}
        }
Exemplo n.º 6
0
        public static void Main(string[] args)
        {
            config      = JSONParser.ReadConfig(CONFIG_PATH); //чтение файла конфигурации с диска
            hardwareID  = Hardware.GetID();                   //идентификатор оборудования строися на основе mac адресов
            information = new PartStruct()                    //информация о клиенте отсылается серверу
                          .Add("name", config["name"])
                          .Add("groupe", config["group"])
                          .Add("id", hardwareID)
                          .Add("port", config["serverPort"]);

            receiver = ConfigureReceiver();
            commands = ConfigureCommands();
            rRServer = ConfigureServer();

            Console.ReadKey();
            //освобождение ресурсов и завершение программы
            receiver.Dispose();
            rRServer.Dispose();
        }