Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1888_OaaS/HeuristicLab.Services.Optimization.Controller/Logging/TableStorageTraceListener.cs @ 17869

Last change on this file since 17869 was 9508, checked in by fschoepp, 11 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: 2.8 KB
Line 
1using System;
2using System.Collections.Generic;
3using System.Linq;
4using System.Text;
5using System.Diagnostics;
6using Microsoft.WindowsAzure.StorageClient;
7using Microsoft.WindowsAzure;
8using System.Threading;
9
10namespace HeuristicLab.Services.Optimization.ControllerService.Logging {
11  public class TableStorageTraceEntry : TableServiceEntity {
12    public TableStorageTraceEntry(string message) {
13      this.PartitionKey = "Trace";
14      this.RowKey = Guid.NewGuid().ToString();
15      this.Message = message;
16    }
17
18    public string Message { get; set; }
19  };
20
21  public class TableStorageTraceListener : TraceListener {
22
23    private string traceTable;
24
25    public string TraceTable {
26      get {
27        if (traceTable == null) {
28          traceTable = CloudConfigurationManager.GetSetting("TraceTable");
29        }
30        return traceTable;
31      }
32    }
33
34    private bool traceEnabled = false;
35    private DateTime? lastChecked = null;
36    public bool TraceEnabled {
37      get {
38        if (!lastChecked.HasValue || (DateTime.Now - lastChecked.Value).TotalSeconds > 20) {
39          lastChecked = DateTime.Now;
40          traceEnabled = CloudConfigurationManager.GetSetting("TraceTableEnabled") != null && CloudConfigurationManager.GetSetting("TraceTableEnabled").ToLower() == "true";
41        }
42        return traceEnabled;
43      }
44    }
45
46    private CloudStorageAccount account;
47    private TableServiceContext context;
48    private CloudTableClient client;
49    private ThreadLocal<bool> doLog = new ThreadLocal<bool>();
50
51    public TableServiceContext Context {
52      get {
53        if (account == null) {
54          account = CloudStorageAccount.Parse(CloudConfigurationManager.GetSetting("StorageConnectionString"));
55          client = account.CreateCloudTableClient();
56          context = client.GetDataServiceContext();         
57        }
58        client.CreateTableIfNotExist(TraceTable);
59        return context;
60      }
61    }
62
63
64    public override void Write(string message) {
65      if (!doLog.IsValueCreated) {
66        doLog.Value = true;
67      }
68
69      // prevent stack overflows
70      if (!doLog.Value) {
71        return;
72      }
73
74      doLog.Value = false;
75      if (TraceEnabled) {
76        Context.AddObject(TraceTable, new TableStorageTraceEntry(message));
77        Context.SaveChangesWithRetries();
78      }
79      doLog.Value = true;
80    }
81
82    public override void WriteLine(string message) {
83      Write(message + "\n");
84    }
85
86    public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data) {
87      Write(data.ToString());
88    }
89
90    public override void TraceEvent(TraceEventCache eventCache, string source, TraceEventType eventType, int id, string message) {
91      Write(message);
92    }
93  }
94}
Note: See TracBrowser for help on using the repository browser.