Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HiveStatistics/sources/HeuristicLab.Clients.Hive.Slave.MultiSlavesRunner/3.3/Program.cs @ 10429

Last change on this file since 10429 was 9373, checked in by pfleck, 12 years ago

#2030
Added MultiSlaveRunner for starting multiple Slave Cores on a single Machine.
Mocked GUID generation for slaves to random GUID.
Deactivated PerformanceCounter measurements from ConfigManager to avoid shared resource locks.

File size: 2.8 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.Diagnostics;
25using System.Threading;
26using System.Threading.Tasks;
27using HeuristicLab.Clients.Hive.SlaveCore.MultiSlavesRunner.Properties;
28
29namespace HeuristicLab.Clients.Hive.SlaveCore.MultiSlavesRunner {
30  public class Program {
31    static void Main(string[] args) {
32      EventLog eventLog = null;
33      try {
34        if (!System.Diagnostics.EventLog.SourceExists("HLHive")) {
35          System.Diagnostics.EventLog.CreateEventSource("HLHive", "HiveSlave");
36        }
37        eventLog = new EventLog();
38        eventLog.Source = "HLHive";
39        eventLog.Log = "HiveSlave";
40      }
41      catch (Exception) { }
42
43      var cores = new List<Core>();
44
45      Parallel.For(0, Settings.Default.NumberOfSlaves, i => {
46        string appName = "Hive Slave #" + i;
47        AppDomain applicationDomain = AppDomain.CreateDomain(appName);
48        var coreType = typeof(Core);
49        Console.WriteLine("Create core #" + i);
50        var core = (Core)applicationDomain.CreateInstanceAndUnwrap(coreType.Assembly.FullName, coreType.FullName);
51        core.ServiceEventLog = eventLog;
52        cores.Add(core);
53      });
54
55      Parallel.For(0, cores.Count, i => {
56        var core = cores[i];
57        var coreThread = new Thread(core.Start) {
58          IsBackground = true
59        };
60        Console.WriteLine("Start core #" + i);
61        coreThread.Start();
62      });
63
64      Console.WriteLine("Waiting for cores to start...");
65      Thread.Sleep(10000);
66
67      //mock a slave client
68      SlaveCommListener listener = new SlaveCommListener();
69      listener.Open();
70
71      Console.WriteLine("Press a key to quit");
72      Console.ReadLine();
73
74      //Environment.Exit(0); // quick shutdown ...
75
76      listener.Close();
77
78      foreach (var core in cores) {
79        try {
80          core.Shutdown();
81        }
82        catch (Exception) { }
83      }
84
85      Console.ReadLine();
86    }
87  }
88}
Note: See TracBrowser for help on using the repository browser.