public async Task <ActionResult> Start()
        {
            int    batch_count = int.Parse(Request.Params["batchcount"]);
            int    batch_size  = int.Parse(Request.Params["batchsize"]);
            int    delay       = int.Parse(Request.Params["delay"]);
            int    runtime     = int.Parse(Request.Params["runtime"]);
            string url         = Request.Params["testurl"];

            // create an aggregator grain to track results from the load test
            IAggregatorGrain aggregator = AggregatorGrainFactory.GetGrain(0);

            // set this SimulationController class as an observer on the aggregator grain
            ISimulationObserver observer = await SimulationObserverFactory.CreateObjectReference(MvcApplication.GlobalObserver); // convert our class into a grain reference

            await aggregator.SetObserver(observer);                                                                              // then set ourselves up to receive notifications on ReportResults()

            // Instantiate the manager grains and start the simulations
            // Pause between each batch to ramp up load gradually
            for (int i = 0; i < batch_count; i++)
            {
                Console.WriteLine("Starting batch #{0}", i + 1);
                IManagerGrain manager = ManagerGrainFactory.GetGrain(i);

                await manager.SetAggregator(aggregator);                  // link in the aggregator

                await manager.StartSimulators(i *delay, batch_size, url); // start the simulation
            }

            return(RedirectToAction("index"));
        }
Пример #2
0
        public async Task StartSimulation(int batch_count, int batch_size, int delay, int runtime, string url)
        {
            // List of cities with coordinates
            var cities = new CityCoordinates();

            // create an aggregator grain to track results from the load test
            IAggregatorGrain aggregator = AggregatorGrainFactory.GetGrain(0);

            // Instantiate the manager grains and start the simulations

            List <Task> tasks = new List <Task>();

            for (int i = 0; i < batch_count; i++)
            {
                Console.WriteLine("Starting batch #{0}", i + 1);
                IManagerGrain manager = ManagerGrainFactory.GetGrain(i);

                all_managers.Add(manager);

                var city = cities.RandomCity();
                tasks.Add(manager.SetAggregator(aggregator));                                                  // link in the aggregator
                tasks.Add(manager.StartSimulators(i * delay, batch_size, url, city.Latitude, city.Longitude)); // start the simulation
            }

            await Task.WhenAll(tasks);
        }
Пример #3
0
        /// <summary>
        /// Start the simulation.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="manager"></param>
        /// <returns></returns>
        public Task StartSimulation(long id, string url, IManagerGrain manager)
        {
            _url     = url;
            _manager = manager;

            var rand = new Random();

            _reqtimer = RegisterTimer(SendRequest, null,
                                      TimeSpan.FromSeconds(rand.Next(MAX_DELAY)), TimeSpan.FromSeconds(PERIOD));
            _stattimer = RegisterTimer(ReportResults, null,
                                       TimeSpan.FromSeconds(REPORT_PERIOD), TimeSpan.FromSeconds(REPORT_PERIOD));

            return(TaskDone.Done);
        }
Пример #4
0
        const string URL      = "http://devicetracker.cloudapp.net:8080/api/devices/processmessage"; // Change to point to the web site under test

        /// <summary>
        /// Start the simulation via the controller grain.
        /// </summary>
        /// <returns></returns>
        public async Task Run()
        {
            OrleansClient.Initialize();

            // create an aggregator grain to track results from the load test
            IAggregatorGrain aggregator = AggregatorGrainFactory.GetGrain(0);

            // set this SimulationController class as an observer on the aggregator grain
            observer = await SimulationObserverFactory.CreateObjectReference(this); // convert our class into a grain reference

            await aggregator.SetObserver(observer);                                 // then set ourselves up to receive notifications on ReportResults()

            // Instantiate the manager grains and start the simulations
            // Pause between each batch to ramp up load gradually
            for (int i = 0; i < BATCH_COUNT; i++)
            {
                Console.WriteLine("Starting batch #{0}", i + 1);
                IManagerGrain manager = ManagerGrainFactory.GetGrain(i);
                managers.Add(manager);                                                // store grain reference

                await manager.SetAggregator(aggregator);                              // link in the aggregator

                await manager.StartSimulators(i *DELAY_STEPS *1000, BATCH_SIZE, URL); // start the sinulation
            }

            // Sleep for the duration of the test
            Console.WriteLine("Running test...");
            Thread.Sleep(RUN_TIME * 1000);  // low value just for test

            // Gradually stop simulators
            foreach (var i in managers)
            {
                Console.WriteLine("Stopping step #{0}", managers.IndexOf(i) + 1);
                await i.StopSimulators();

                Thread.Sleep(DELAY_STEPS * 1000);
            }
        }
Пример #5
0
        /// <summary>
        /// Start simulation at a given latitude/longitude coordinate.
        /// </summary>
        /// <param name="id"></param>
        /// <param name="url"></param>
        /// <param name="managerGrain"></param>
        /// <param name="latitude"></param>
        /// <param name="longitude"></param>
        /// <returns></returns>
        public Task StartSimulation(long id, string url, IManagerGrain managerGrain, double latitude, double longitude)
        {
            _url     = url;
            _manager = managerGrain;

            var rand = new Random((int)this.GetPrimaryKeyLong());

            // initialize simulation parameters
            cur_lat    = latitude + (rand.NextDouble() - 0.5) / 10.0;
            cur_long   = longitude + (rand.NextDouble() - 0.5) / 10.0;
            device_id  = Guid.NewGuid();
            lat_speed  = (rand.NextDouble() - 0.5) / 10.0;
            long_speed = (rand.NextDouble() - 0.5) / 10.0;

            _logger.Info("*** simulator " + this.GetPrimaryKeyLong() + " starting " + cur_lat + " " + cur_long + " " + device_id);

            // start the timers
            _reqtimer = RegisterTimer(SendRequest, null,
                                      TimeSpan.FromSeconds(rand.Next(MAX_DELAY)), TimeSpan.FromSeconds(PERIOD));
            _stattimer = RegisterTimer(ReportResults, null,
                                       TimeSpan.FromSeconds(REPORT_PERIOD), TimeSpan.FromSeconds(REPORT_PERIOD));

            return(TaskDone.Done);
        }
Пример #6
0
 /// <summary>
 /// Start the simulation.
 /// </summary>
 /// <param name="name"></param>
 /// <param name="manager"></param>
 /// <returns></returns>
 public Task StartSimulation(long id, string url, IManagerGrain manager)
 {
     return(StartSimulation(id, url, manager, 0, 0));
 }