public override bool OnStart() { if (UseMessageBus) { // Set the maximum number of concurrent connections ServicePointManager.DefaultConnectionLimit = 12; // Create the queue if it does not exist already string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); if (!namespaceManager.QueueExists(QueueName)) { namespaceManager.CreateQueue(QueueName); } // Initialize the connection to Service Bus Queue QueueClient = QueueClient.CreateFromConnectionString(connectionString, QueueName); } else { } dataSource = new CalculatorDataSource("simulation"); IsStopped = false; return base.OnStart(); }
//======================== // This is used by the ProjectCalculator Worker Role // It fires off messages to the Azure queue // which will get picked up by the service (which also uses this class!) public void InitiateCalculation() { Project project = GetProject(_projectName); // Create a TaskAggregator, passing in the project CalculatorDataSource calculatorDataSource = new CalculatorDataSource("simulation"); // For each simulation run, queue a message to simulate the project estimation for (int i = 0; i < _iterationCount; i++) { calculatorDataSource.EnQueue(project); } }
public AggregationSummary GenerateSummary() { Project project = GetProject(_projectName); //------------------------------------------------------------------------------------------------- //// This stuff will get refactored out to when the calulation is submitted //// Create a random number generator //Distribution randomNumberGenerator = new FisherTippettDistribution(); //// Create a TaskAggregator, passing in the RNG and the project //TaskAggregator taskAggregator = new TaskAggregator(project, randomNumberGenerator, 100000); //// Invoke the TaskAggregator Aggregate method, returning a List<double> of numbers //List<double> aggregatedDurations = taskAggregator.Aggregate(); //------------------------------------------------------------------------------------------------- // Get the list of aggregated durations from Azure storage CalculatorDataSource dataSource = new CalculatorDataSource(_projectName); IEnumerable<ProjectCalculationEntry> entries = dataSource.GetEntries(_projectName); //foreach (ProjectCalculationEntry projectCalculationEntry in entries) //{ // aggregatedDurations.Add(projectCalculationEntry.Duration); //} List<double> aggregatedDurations = entries.Select(projectCalculationEntry => projectCalculationEntry.Duration).ToList(); // Calculate the mean and variance double mean = CalculateMean(aggregatedDurations); double variance = CalculateVariance(aggregatedDurations, mean); // Get the distribution of durations List<DistributionPoint> dataPoints = TransformToDistribuion(aggregatedDurations); // Create and return an AggregationSummary, passing in the List, mean, variance and task count and project name return new AggregationSummary { ProjectName = project.Name, DistributionPoints = dataPoints, MeanDuration = mean, Variance = variance, TaskCount = project.Tasks.Count }; }
public override void Run() { // This is a sample worker implementation. Replace with your logic. Trace.WriteLine("$projectname$ entry point called", "Information"); while (true) { //Thread.Sleep(200); // Make the simulation process a long running calculation ~200ms // (If it is too quick, you do not see the difference when adding new worker processes) //Trace.WriteLine("Working", "Information"); // Pick up a message from the "simulation" message queue. // Create a TaskAggregator and call GenerateAggregatedDuration // Save the simulation result (project name, run number, calculated duration) // to Azure table storage using (CalculatorDataSource dataSource = new CalculatorDataSource("simulation")) { Project project = dataSource.GetProjectFromQueueMessage(); if (project != null) { // Create a random number generator Distribution randomNumberGenerator = new FisherTippettDistribution(); // Create a TaskAggregator, passing in the RNG and the project TaskAggregator taskAggregator = new TaskAggregator(project, randomNumberGenerator); double aggregatedDuration = taskAggregator.GenerateAggregatedDuration(); dataSource.AddEntry( new ProjectCalculationEntry {Duration = aggregatedDuration, ProjectName = project.Name}, project.Name); } } // Don't bother sending back a "done" message } }
//======================== // This is used by the ProjectCalculator Worker Role // It fires off messages to the Azure queue // which will get picked up by the service (which also uses this class!) public void InitiateCalculation() { Project project = GetProject(_projectName); if (UseMessageBus) { // Create the queue if it does not exist already const string QueueName = "simulation"; string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); if (!namespaceManager.QueueExists(QueueName)) { namespaceManager.CreateQueue(QueueName); } // Initialize the connection to Service Bus Queue QueueClient queueClient = QueueClient.CreateFromConnectionString(connectionString, QueueName); // For each simulation run, queue a message to simulate the project estimation for (int i = 0; i < _iterationCount; i++) { BrokeredMessage message = new BrokeredMessage(project); queueClient.Send(message); } } else { // Create a TaskAggregator, passing in the project CalculatorDataSource calculatorDataSource = new CalculatorDataSource("simulation"); // For each simulation run, queue a message to simulate the project estimation for (int i = 0; i < _iterationCount; i++) { calculatorDataSource.EnQueue(project); } } }
private void InitiateCalculation(CalculationParameters calculationParameters) { CalculatorDataSource dataSource = new CalculatorDataSource("main"); dataSource.EnQueue(calculationParameters); }
//, TimeSpan timeSinceFirstRequest) private static bool IsCalculationReady(string projectName, int iterationCount) { // Go to the storage and find if all the simulation calculations have been returned //bool calculationIsReady = timeSinceFirstRequest.Seconds > 10; // HACK bool calculationIsReady = false; try { CalculatorDataSource dataSource = new CalculatorDataSource("simulation"); IEnumerable<ProjectCalculationEntry> entries = dataSource.GetEntries(projectName); int count = entries.Count(); calculationIsReady = count >= iterationCount; } catch { // do nothing } return calculationIsReady; }
private void InitiateCalculation(CalculationParameters calculationParameters) { if (UseMessageBus) { // Create the queue if it does not exist already const string QueueName = "main"; string connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString"); var namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString); if (!namespaceManager.QueueExists(QueueName)) { namespaceManager.CreateQueue(QueueName); } // Initialize the connection to Service Bus Queue QueueClient queueClient = QueueClient.CreateFromConnectionString(connectionString, QueueName); // For each simulation run, queue a message to simulate the project estimation BrokeredMessage message = new BrokeredMessage(calculationParameters); queueClient.Send(message); } else { CalculatorDataSource dataSource = new CalculatorDataSource("main"); dataSource.EnQueue(calculationParameters); } }