Beispiel #1
0
        // par(io(1), cpu(1))  sleep 2s  mem(2)
        private async Task <object> Operation1()
        {
            var tasks = new List <Task <ExecutionResult> >();

            tasks.Add(IoHelper(1));

            var cpuWorkload = new CpuWorkload();

            tasks.Add(cpuWorkload.Run(1));

            await Task.WhenAll(tasks.ToArray());

            await Task.Delay(2000);

            var resultList = new Dictionary <string, ExecutionResult>();

            //resultList.Add("io", tasks[0].Result.Payload.Length);
            resultList.Add("cpu", tasks[1].Result);
            {
                var memoryWorkload = new MemoryWorkload();
                var resultMem      = await memoryWorkload.Run(2);

                resultList.Add("memory", resultMem);
            }

            return(resultList);
        }
Beispiel #2
0
        // io(1) sleep 1 cpu(3)
        private async Task <object> Operation5()
        {
            await IoHelper(1);

            await Task.Delay(1000);

            var cpuWorkload = new CpuWorkload();
            await cpuWorkload.Run(3);

            return("OK");
        }
Beispiel #3
0
        // mem(1) cpu(1)
        private async Task <object> Operation4()
        {
            var resultList     = new Dictionary <string, ExecutionResult>();
            var memoryWorkload = new MemoryWorkload();

            var resultMem = await memoryWorkload.Run(1);

            resultList.Add("memory", resultMem);

            var cpuWorkload = new CpuWorkload();
            await cpuWorkload.Run(1);


            return(resultList);
        }
        public async Task <JsonResult> Run(int time)
        {
            DateTime currentTime = System.DateTime.Now;
            Guid     id          = Guid.NewGuid();

            Console.WriteLine(id + ":Start." + Convert.ToString(currentTime));
            var task   = new CpuWorkload();
            var result = await task.Run(time);

            Console.WriteLine($"{id} :Done. {Convert.ToString(System.DateTime.Now)}");
            return(new JsonResult(
                       new {
                Status = "OK",
                CPULoad = result
            }
                       ));
        }