Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1888_OaaS/HeuristicLab.Clients.Hive/3.3/TaskDownloader.cs @ 17181

Last change on this file since 17181 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: 4.1 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23using System.Collections.Generic;
24using System.Linq;
25using System.Threading;
26using HeuristicLab.Clients.Hive.Jobs;
27using HeuristicLab.Common;
28
29namespace HeuristicLab.Clients.Hive {
30  public class TaskDownloader : IDisposable {
31    private IEnumerable<Guid> taskIds;
32    private ConcurrentTaskDownloader<ItemTask> taskDownloader;
33    private IDictionary<Guid, HiveTask> results;
34    private bool exceptionOccured = false;
35    private Exception currentException;
36    private ReaderWriterLockSlim resultsLock = new ReaderWriterLockSlim();
37
38    public bool IsFinished {
39      get {
40        try {
41          resultsLock.EnterReadLock();
42          return results.Count == taskIds.Count();
43        }
44        finally { resultsLock.ExitReadLock(); }
45      }
46    }
47
48    public bool IsFaulted {
49      get {
50        return exceptionOccured;
51      }
52    }
53
54    public Exception Exception {
55      get {
56        return currentException;
57      }
58    }
59
60    public int FinishedCount {
61      get {
62        try {
63          resultsLock.EnterReadLock();
64          return results.Count;
65        }
66        finally { resultsLock.ExitReadLock(); }
67      }
68    }
69
70    public IDictionary<Guid, HiveTask> Results {
71      get {
72        try {
73          resultsLock.EnterReadLock();
74          return results;
75        }
76        finally { resultsLock.ExitReadLock(); }
77      }
78    }
79
80    public TaskDownloader(IEnumerable<Guid> jobIds, IHiveServiceLocator locator) {
81      this.taskIds = jobIds;
82      this.taskDownloader = new ConcurrentTaskDownloader<ItemTask>(Settings.Default.MaxParallelDownloads, Settings.Default.MaxParallelDownloads, locator);
83      this.taskDownloader.ExceptionOccured += new EventHandler<EventArgs<Exception>>(taskDownloader_ExceptionOccured);     
84      this.results = new Dictionary<Guid, HiveTask>();
85    }
86
87    public void StartAsync() {
88      foreach (Guid taskId in taskIds) {
89        taskDownloader.DownloadTaskDataAndTask(taskId,
90          (localJob, itemJob) => {
91            if (localJob != null && itemJob != null) {
92              HiveTask hiveTask;
93              if (itemJob is OptimizerTask) {
94                hiveTask = new OptimizerHiveTask((OptimizerTask)itemJob);
95              } else {
96                hiveTask = new HiveTask(itemJob, true);
97              }
98              hiveTask.Task = localJob;
99              try {
100                resultsLock.EnterWriteLock();
101                this.results.Add(localJob.Id, hiveTask);
102              }
103              finally { resultsLock.ExitWriteLock(); }
104            }
105          });
106      }
107    }
108
109    private void taskDownloader_ExceptionOccured(object sender, EventArgs<Exception> e) {
110      OnExceptionOccured(e.Value);
111    }
112
113    public event EventHandler<EventArgs<Exception>> ExceptionOccured;
114    private void OnExceptionOccured(Exception exception) {
115      this.exceptionOccured = true;
116      this.currentException = exception;
117      var handler = ExceptionOccured;
118      if (handler != null) handler(this, new EventArgs<Exception>(exception));
119    }
120
121    #region IDisposable Members
122    public void Dispose() {
123      taskDownloader.ExceptionOccured -= new EventHandler<EventArgs<Exception>>(taskDownloader_ExceptionOccured);
124      resultsLock.Dispose();
125      taskDownloader.Dispose();
126    }
127    #endregion
128  }
129}
Note: See TracBrowser for help on using the repository browser.