예제 #1
0
        public WorkloadResponse GetWorkloadResponse(WorkloadRequest clientRFWRequestBody)
        {
            CheckForBelowOneParameters(clientRFWRequestBody);
            WorkloadResponse       serverRFD           = new WorkloadResponse();
            List <Models.Workload> workloadList        = new List <Models.Workload>(GetBenchmarkType(clientRFWRequestBody.BenchmarkType));
            List <double>          allColumnValuesList = new List <double>(GetAllWorkloadColumnValues(clientRFWRequestBody.WorkloadMetric, workloadList));
            List <Batch>           allBatchesList      = new List <Batch>(GetAllBatches(clientRFWRequestBody.BatchUnit, allColumnValuesList));

            int startIndex = clientRFWRequestBody.BatchID - 1;
            int endIndex   = 0;

            if ((startIndex + clientRFWRequestBody.BatchSize) <= allBatchesList.Count())
            {
                endIndex = startIndex + clientRFWRequestBody.BatchSize;
            }
            else
            {
                endIndex = allBatchesList.Count();
            }

            for (int i = startIndex; i < endIndex; i++)
            {
                serverRFD.Batches.Add(allBatchesList[i]);
            }

            serverRFD.RFDID       = clientRFWRequestBody.RFWID;
            serverRFD.LastBatchID = endIndex;

            return(serverRFD);
        }
예제 #2
0
        public WorkloadResponse GetRequestBody(WorkloadRequest content)
        {
            int numberBatch = 0;
            //Compute batch start id
            int startID = content.BatchUnit * content.BatchId;
            WorkloadResponse response = new WorkloadResponse();

            response.Rfw = content.Rfw;
            List <CommunicationServer.Models.Workload> wkldList = new List <CommunicationServer.Models.Workload>();

            //choose which file to read from
            if (content.BenchMark == WorkloadRequest.Types.BenchMarkType.Dvdtest)
            {
                wkldList = Data.DVDTest;
            }
            else if (content.BenchMark == WorkloadRequest.Types.BenchMarkType.Dvdtrain)
            {
                wkldList = Data.DVDTrain;
            }
            else if (content.BenchMark == WorkloadRequest.Types.BenchMarkType.NdbenchTest)
            {
                wkldList = Data.NDBTest;
            }
            else if (content.BenchMark == WorkloadRequest.Types.BenchMarkType.NdbenchTrain)
            {
                wkldList = Data.NDBTrain;
            }
            else
            {
                response.LastBatchId = "Error: Benchmark does not exist";
                return(response);
            }

            //avoid division by 0
            if (content.BatchUnit != 0)
            {
                decimal tmp = ListCount(ref wkldList) / content.BatchUnit;
                //round total number of batch
                numberBatch = (int)Math.Ceiling(tmp);
            }


            if (content.BatchId > numberBatch)
            {
                response.LastBatchId = "Error: BatchId exceeds number of Batch";
                return(response);
            }

            int start = startID;
            //Verify if batchsize ends
            int end = content.BatchId + content.BatchSize;

            int last = end;

            for (int j = content.BatchId; j < end; j++)
            {
                Batch batch = new Batch()
                {
                    BatchId = j
                };
                if (numberBatch == j)
                {
                    for (int i = start; i < wkldList.Count; i++)
                    {
                        batch.Values.Add(VerifyMetric(wkldList[i], content.Metric));
                    }
                    last   = numberBatch + 1;
                    start += content.BatchUnit;
                    response.Batches.Add(batch);
                    break;
                }
                else
                {
                    for (int i = start; i < start + content.BatchUnit; i++)
                    {
                        batch.Values.Add(VerifyMetric(wkldList[i], content.Metric));
                    }
                }
                start += content.BatchUnit;
                response.Batches.Add(batch);
            }
            response.LastBatchId = (last - 1).ToString();

            return(response);
        }
예제 #3
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Enter Server in format URL:Port");
            string serverURL = Console.ReadLine();
            var    channel   = GrpcChannel.ForAddress(serverURL);
            var    client    = new Workload.WorkloadClient(channel);

            while (true)
            {
                bool inputChecker = true;

                Console.WriteLine("Enter RFWID: ");
                int    num        = -1;
                string inputRFWID = Console.ReadLine();

                while (!int.TryParse(inputRFWID, out num))
                {
                    Console.WriteLine("The value must be an integer. Please re-enter RFWID:");
                    inputRFWID = Console.ReadLine();
                }
                Int32 rfwId = Convert.ToInt32(inputRFWID);

                string benchmark = "";

                while (inputChecker)
                {
                    Console.WriteLine("Enter BenchmarkType (DvdTesting = 0, DvdTraining = 1, NdBenchTesting = 2, NdBenchTraining = 3): ");
                    benchmark = Console.ReadLine();

                    if ((benchmark.Equals("0") || benchmark.Equals("1") || benchmark.Equals("2") || benchmark.Equals("3")))
                    {
                        inputChecker = false;
                    }
                }

                inputChecker = true;

                string workloadMetric = "";

                while (inputChecker)
                {
                    Console.WriteLine("Enter WorkloadMetric (Cpu = 0, NetworkIn = 1, NetworkOut = 2, Memory = 3): ");
                    workloadMetric = Console.ReadLine();

                    if ((workloadMetric.Equals("0") || workloadMetric.Equals("1") || workloadMetric.Equals("2") || workloadMetric.Equals("3")))
                    {
                        inputChecker = false;
                    }
                }

                inputChecker = true;

                Console.WriteLine("Enter BatchUnit: ");
                string inputBatchUnit = Console.ReadLine();
                while (!int.TryParse(inputBatchUnit, out num))
                {
                    Console.WriteLine("The value must be an integer. Please re-enter BatchUnit:");
                    inputBatchUnit = Console.ReadLine();
                }
                Int32 batchUnit = Convert.ToInt32(inputBatchUnit);

                Console.WriteLine("Enter BatchID: ");
                string inputBatchID = Console.ReadLine();
                while (!int.TryParse(inputBatchID, out num))
                {
                    Console.WriteLine("The value must be an integer. Please re-enter BatchID:");
                    inputBatchID = Console.ReadLine();
                }
                Int32 batchId = Convert.ToInt32(inputBatchID);

                Console.WriteLine("Enter BatchSize: ");
                string inputBatchSize = Console.ReadLine();

                while (!int.TryParse(inputBatchSize, out num))
                {
                    Console.WriteLine("The size of the batch must be an integer. Please re-enter the size of the batch:");
                    inputBatchSize = Console.ReadLine();
                }
                Int32 batchSize = Convert.ToInt32(inputBatchSize);

                WorkloadRequest workloadRequest = new WorkloadRequest();
                workloadRequest.RFWID          = rfwId;
                workloadRequest.BenchmarkType  = (WorkloadRequest.Types.BenchmarkType)Enum.Parse(typeof(WorkloadRequest.Types.BenchmarkType), benchmark);
                workloadRequest.WorkloadMetric = (WorkloadRequest.Types.WorkloadMetric)Enum.Parse(typeof(WorkloadRequest.Types.WorkloadMetric), workloadMetric);
                workloadRequest.BatchUnit      = batchUnit;
                workloadRequest.BatchID        = batchId;
                workloadRequest.BatchSize      = batchSize;

                WorkloadResponse workloadResponse = new WorkloadResponse();
                workloadResponse = await client.GetWorkloadAsync(workloadRequest);

                Console.WriteLine("Server Response:\n"
                                  + "\"rfdid\": " + workloadResponse.RFDID.ToString() + ",\n"
                                  + "\"lastbatchID\": " + workloadResponse.LastBatchID.ToString() + ",\n"
                                  + "\"batches\": [");

                for (int i = 0; i < workloadResponse.Batches.Count(); i++)
                {
                    Console.WriteLine("\t{\t\"batchID\": " + workloadResponse.Batches[i].BatchID + ",");
                    Console.WriteLine("\t\t\"requestedSamples\": [\n");
                    for (int j = 0; j < workloadResponse.Batches[i].RequestedSamples.Count(); j++)
                    {
                        if (j == workloadResponse.Batches[i].RequestedSamples.Count() - 1)
                        {
                            Console.WriteLine("\t\t\t" + workloadResponse.Batches[i].RequestedSamples[j] + "\n\t\t]\n\t},");
                        }
                        else
                        {
                            Console.WriteLine("\t\t\t" + workloadResponse.Batches[i].RequestedSamples[j] + ",");
                        }
                    }
                    if (i == workloadResponse.Batches.Count - 1)
                    {
                        Console.WriteLine("]");
                    }
                }

                Console.WriteLine("Press any key to continue OR press '9' to exit");
                string continueORQuit = Console.ReadLine();

                if (continueORQuit.Equals("9"))
                {
                    break;
                }
            }
        }