Free cookie consent management tool by TermsFeed Policy Generator

source: branches/OaaS/HeuristicLab.Services.Hive.Scaler/WorkerRole.cs @ 13834

Last change on this file since 13834 was 9508, checked in by fschoepp, 12 years ago

#1888:
HL:

  • Web projects requires different users to interact with hive. The singleton HiveServiceLocator.Instance doesn't allow different users at the same time, resulting in serialization during access of HiveClient methods.

The following changes have been introduced in favor of a parallel use of the HL libs:

  • HiveClient, TaskDownloader and ConcurrentTaskDownloader may now use a different IHiveServiceLocator than HiveServiceLocator.Instance (all methods have appropriate overloads now).
  • The default instance is still HiveServiceLocator.Instance.

Automated Scaling of Instances:

  • Added Scaler project to solution which represents a WorkerRole that scales the slave instances based on the global cpu utilization of all slaves.
  • Scaler is based on WASABi, rules can be adjusted in rulesstore.xml. Basic rule is: if < 45% global cpu utilization => remove an instance; if > 65% cpu => add an instance. Minimum boundary is 1 and maximum boundary is 8 slave instances.
  • Adjusted Slave project to automatically register itself to a SlaveGroup during WebRole startup (can be adjusted in service configuration).

Web-Frontend:

  • Added basic error messages to the dialogs when an ajax call fails.
  • Removed Styling.js from scripts.
File size: 3.6 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Diagnostics;
4using System.Linq;
5using System.Net;
6using System.Threading;
7using Microsoft.WindowsAzure;
8using Microsoft.WindowsAzure.Diagnostics;
9using Microsoft.WindowsAzure.ServiceRuntime;
10using Microsoft.WindowsAzure.StorageClient;
11using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
12using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.Autoscaling;
13using HeuristicLab.Services.Optimization.Scaler.Hive;
14
15namespace HeuristicLab.Services.Optimization.Scaler {
16  public class WorkerRole : RoleEntryPoint {
17    private const string WADConnectionString = "Microsoft.WindowsAzure.Plugins.Diagnostics.ConnectionString";
18
19    private Autoscaler autoscaler;
20
21    public override void Run() {
22      try {
23        // This is a sample worker implementation. Replace with your logic.
24        Trace.WriteLine("HeuristicLab.Services.Hive.Scaler entry point called", "Information");
25
26        var hiveGlobalUsageCounter = PerformanceCounterHelper.HiveGlobalUsage;
27        while (true) {
28          Thread.Sleep(10000);
29          Trace.WriteLine("Updating counters...", "Information");
30
31          // Get current hive usage and update performance counter
32          var usageInPercent = Convert.ToInt32(HiveHelper.GetGlobalUsage());
33          hiveGlobalUsageCounter.RawValue = usageInPercent;
34          Trace.WriteLine(string.Format("Hive global usage: {0}", hiveGlobalUsageCounter.RawValue));
35        }
36      }
37      catch (Exception ex) {
38        Trace.WriteLine(ex.ToString());
39      }
40    }
41
42    private void InitializeConfiguration() {
43      try {
44        DiagnosticMonitorConfiguration config = DiagnosticMonitor.GetDefaultInitialConfiguration();
45       
46        // enable diagnostics logging (=> WADDiagnosticsInfrastrucutre table)
47        config.DiagnosticInfrastructureLogs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
48        config.DiagnosticInfrastructureLogs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1d);
49
50        // enable trace logging (=> WADLogs)
51        config.Logs.ScheduledTransferLogLevelFilter = LogLevel.Verbose;
52        config.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1d);
53
54        // enable performance counter logging (=> WADPerformanceCounters table)
55        config.PerformanceCounters.ScheduledTransferPeriod = TimeSpan.FromMinutes(1d);
56        config.PerformanceCounters.BufferQuotaInMB = 128;
57        config.PerformanceCounters.DataSources.Add(
58           new PerformanceCounterConfiguration() {
59             // Add the global usage counter of hive
60             CounterSpecifier = PerformanceCounterHelper.HiveCounterGlobalUsage,
61             SampleRate = TimeSpan.FromSeconds(10d)
62           }
63        );
64        DiagnosticMonitor.Start(WADConnectionString, config);
65      }
66      catch (Exception ex) {
67        Trace.Write(ex.ToString());
68      }
69    }
70
71    public override bool OnStart() {
72      // Set the maximum number of concurrent connections
73      ServicePointManager.DefaultConnectionLimit = 12;
74
75      // Initializes all required performance counters for OaaS
76      PerformanceCounterHelper.InitializePerformanceCounters();
77
78      // Transfer performance counters to windows azure
79      InitializeConfiguration();
80
81      // Start auto scaler
82      autoscaler = EnterpriseLibraryContainer.Current.GetInstance<Autoscaler>();
83      autoscaler.Start();
84
85      // For information on handling configuration changes
86      // see the MSDN topic at http://go.microsoft.com/fwlink/?LinkId=166357.
87
88      return base.OnStart();
89    }
90  }
91}
Note: See TracBrowser for help on using the repository browser.