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")); }
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); }
// create / update an event // the system doesn't really distinguish between the two, just to keep the logic simple // scenarios include changing the start or end date, changing the list of topics for that event, etc public async Task Update(string title, string type, string start, string end, TopicApiData[] topics) { string id = this.GetPrimaryKeyString(); // rmember - the grain key is the event id Console.WriteLine($"** EventGrain Update()for event id = {id}, with title {title}"); // update interal grain state State.title = title; State.type = type; State.start = start; State.end = end; State.topics = topics; State.feedback = new List <FeedbackGrainState>(); // lets clear all feedback, just to keep things simple Console.WriteLine($"** EventGrain Update() about to write WriteStateAsync"); await base.WriteStateAsync(); // update aggregator about this new event SummaryEventInfo eventInfo = new SummaryEventInfo(); eventInfo.id = id; eventInfo.title = title; eventInfo.start = start; eventInfo.end = end; IAggregatorGrain aggregator = GrainFactory.GetGrain <IAggregatorGrain>(Guid.Empty); // the aggregator grain is a singleton - Guid.Empty is convention to indicate this //await aggregator.DeleteAnEvent(id); await aggregator.AddAnEvent(eventInfo); return; }
private static async Task <string> PrintError(IAggregatorGrain aggregator, Message[] messages) { var sb = new StringBuilder(); sb.AppendLine("Expectation failed!"); sb.AppendLine($" -expected: {string.Join(',', messages.OrderBy(m => m.Id).Select(m => m.Id))}"); sb.AppendLine($" -sent : {string.Join(',', (await aggregator.GetAllSentMessages()).OrderBy(m => m.Id).Select(m => m.Id))}"); sb.AppendLine($" -received: {string.Join(',', (await aggregator.GetAllReceivedMessages()).OrderBy(m => m.Id).Select(m => m.Id))}"); return(sb.ToString()); }
public static async void InitializeOrleans() { // Create the Observer object MvcApplication.GlobalObserver = new SimulationObserver(); // Get a reference to the aggregator grain IAggregatorGrain aggregator = AggregatorGrainFactory.GetGrain(0); // Set 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() }
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); } }
static int REPORT_PERIOD = 10; // seconds public Task SetAggregator(IAggregatorGrain aggregator) { _aggregator = aggregator; return(TaskDone.Done); }
private static async Task <bool> AllMessagesSentAndDelivered(IAggregatorGrain aggregator, Message[] messages) => await aggregator.WereAllMessagesSent(messages.AsImmutable()) && await aggregator.WereAllSentAlsoDelivered();