[9508] | 1 | using System;
|
---|
| 2 | using System.Collections.Generic;
|
---|
| 3 | using System.Diagnostics;
|
---|
| 4 | using System.Linq;
|
---|
| 5 | using System.Net;
|
---|
| 6 | using System.Threading;
|
---|
| 7 | using Microsoft.WindowsAzure;
|
---|
| 8 | using Microsoft.WindowsAzure.Diagnostics;
|
---|
| 9 | using Microsoft.WindowsAzure.ServiceRuntime;
|
---|
| 10 | using Microsoft.WindowsAzure.StorageClient;
|
---|
| 11 | using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
|
---|
| 12 | using Microsoft.Practices.EnterpriseLibrary.WindowsAzure.Autoscaling;
|
---|
| 13 | using HeuristicLab.Services.Optimization.Scaler.Hive;
|
---|
| 14 |
|
---|
| 15 | namespace 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 | }
|
---|