Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
08/19/10 13:30:56 (14 years ago)
Author:
cneumuel
Message:

Split up "State" to "JobState" and "SlaveState" (#1159)

Location:
branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/Core.cs

    r4263 r4264  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using HeuristicLab.Hive.Slave.ExecutionEngine;
     24using System.IO;
     25using System.Threading;
     26using HeuristicLab.Core;
     27using HeuristicLab.Hive.Contracts;
     28using HeuristicLab.Hive.Contracts.BusinessObjects;
     29using HeuristicLab.Hive.Contracts.ResponseObjects;
    2730using HeuristicLab.Hive.Slave.Common;
    28 using System.Threading;
    29 using System.Reflection;
    30 using System.Diagnostics;
    31 using System.Security.Permissions;
    32 using System.Security.Policy;
    33 using System.Security;
    3431using HeuristicLab.Hive.Slave.Communication;
    35 using HeuristicLab.Hive.Contracts.BusinessObjects;
    36 using HeuristicLab.Hive.Contracts;
    37 using System.Runtime.Remoting.Messaging;
    38 using HeuristicLab.PluginInfrastructure;
    39 using System.ServiceModel;
    40 using System.ServiceModel.Description;
     32using HeuristicLab.Hive.Slave.Communication.ServerService;
    4133using HeuristicLab.Hive.Slave.Core.ClientConsoleService;
    4234using HeuristicLab.Hive.Slave.Core.ConfigurationManager;
    43 using HeuristicLab.Hive.Slave.Communication.ServerService;
    44 using HeuristicLab.Hive.JobBase;
    4535using HeuristicLab.Hive.Slave.Core.JobStorage;
     36using HeuristicLab.Hive.Slave.ExecutionEngine;
    4637using HeuristicLab.Tracing;
    47 using HeuristicLab.Core;
    48 using System.IO;
    49 using HeuristicLab.Hive.Contracts.ResponseObjects;
    5038
    5139namespace HeuristicLab.Hive.Slave.Core {
     
    10290
    10391      //Initialize the heartbeat
    104       beat = new Heartbeat { Interval = 10000 };
     92      beat = new Heartbeat { Interval = new TimeSpan(0, 0, 10) };
    10593      beat.StartHeartbeat();
    10694
     
    171159          Logger.Info("Uptime Limit reached, storing jobs and sending them back");
    172160
    173           //check if there are running jobs
    174           if (engines.Count > 0) {
    175             //make sure there is no more fetching of jobs while the snapshots get processed
    176             CurrentlyFetching = true;
    177             //request a snapshot of each running job
    178             foreach (KeyValuePair<Guid, Executor> kvp in engines) {
    179               kvp.Value.RequestSnapshot();
    180             }
    181 
    182           } else {
    183             //Disconnect afterwards
    184             WcfService.Instance.Disconnect();
    185           }
     161          ShutdownRunningJobsAndSubmitSnapshots();
    186162          break;
    187163
     
    209185          WcfService.Instance.Logout(ConfigManager.Instance.GetClientInfo().Id);
    210186          break;
     187      }
     188    }
     189
     190    private void ShutdownRunningJobsAndSubmitSnapshots() {
     191      //check if there are running jobs
     192      if (engines.Count > 0) {
     193        //make sure there is no more fetching of jobs while the snapshots get processed
     194        CurrentlyFetching = true;
     195        //request a snapshot of each running job
     196        foreach (KeyValuePair<Guid, Executor> kvp in engines) {
     197          kvp.Value.RequestSnapshot();
     198        }
     199
    211200      }
    212201    }
  • branches/3.3-HiveMigration/sources/HeuristicLab.Hive/HeuristicLab.Hive.Slave.Core/3.3/Heartbeat.cs

    r4254 r4264  
    3333using HeuristicLab.Hive.Slave.Communication.ServerService;
    3434using HeuristicLab.Tracing;
     35using System.Threading;
    3536//using BO = HeuristicLab.Hive.Contracts.BusinessObjects;
    3637
     
    4344    private bool offline;
    4445
    45     public double Interval { get; set; }
    46     private Timer heartbeatTimer = null;
     46    public TimeSpan Interval { get; set; }
     47
     48    private Thread heartBeatThread;
    4749
    4850    private static object locker = new object();
    4951
    5052    public Heartbeat() {
    51       Interval = 100;
     53      Interval = new TimeSpan(0,0,10);
    5254    }
    5355
    54     public Heartbeat(double interval) {
     56    public Heartbeat(TimeSpan interval) {
    5557      Interval = interval;
    5658    }
     
    5860    private WcfService wcfService;
    5961
     62    private bool abortThreadPending;
     63
    6064    /// <summary>
    6165    /// Starts the Heartbeat signal.
    6266    /// </summary>
    6367    public void StartHeartbeat() {
    64       heartbeatTimer = new System.Timers.Timer();
    65       heartbeatTimer.Interval = this.Interval;
    66       heartbeatTimer.AutoReset = true;
    67       heartbeatTimer.Elapsed += new ElapsedEventHandler(heartbeatTimer_Elapsed);
    6868      wcfService = WcfService.Instance;
    6969      wcfService.ProcessHeartBeatCompleted += new EventHandler<ProcessHeartBeatCompletedEventArgs>(wcfService_ProcessHeartBeatCompleted);
    70       heartbeatTimer.Start();
     70      abortThreadPending = false;
     71      heartBeatThread = GetHeartBeatThread();
     72      heartBeatThread.Start();
    7173    }
    7274
    73     /// <summary>
    74     /// This Method is called every time the timer ticks
    75     /// </summary>
    76     /// <param name="sender"></param>
    77     /// <param name="e"></param>
    78     void heartbeatTimer_Elapsed(object sender, ElapsedEventArgs e) {
    79       lock (locker) {
    80         // check if cwfService is disconnected for any reason (should happen at first heartbeat)
    81         // [chn] TODO: Client should always send heartbeats. when calendar disallows he should tell the server he does not want to compute anything
    82         if (wcfService.ConnState == NetworkEnum.WcfConnState.Disconnected &&
    83           (!UptimeManager.Instance.CalendarAvailable || UptimeManager.Instance.IsOnline())) {
    84           wcfService.Connect();
    85         }
    86         if (wcfService.ConnState == NetworkEnum.WcfConnState.Connected) {
    87           wcfService.LoginSync(ConfigManager.Instance.GetClientInfo());
    88         }
    89 
    90         ClientDto info = ConfigManager.Instance.GetClientInfo();
    91 
    92         PerformanceCounter counter = new PerformanceCounter("Memory", "Available Bytes", true);
    93         int mb = (int)(counter.NextValue() / 1024 / 1024);
    94 
    95         HeartBeatData heartBeatData = new HeartBeatData {
    96           SlaveId = info.Id,
    97           FreeCores = info.NrOfCores - ConfigManager.Instance.GetUsedCores(),
    98           FreeMemory = mb,
    99           JobProgress = ConfigManager.Instance.GetProgressOfAllJobs()
    100         };
    101 
    102         DateTime lastFullHour = DateTime.Parse(DateTime.Now.Hour.ToString() + ":00");
    103         TimeSpan span = DateTime.Now - lastFullHour;
    104         if (span.TotalSeconds < (Interval / 1000)) {
    105           if (UptimeManager.Instance.IsOnline() && UptimeManager.Instance.CalendarAvailable) {
    106             //That's quiet simple: Just reconnect and you're good for new jobs
    107             if (wcfService.ConnState != NetworkEnum.WcfConnState.Loggedin) {
    108               Logger.Info("Client goes online according to timetable");
     75    private Thread GetHeartBeatThread() {
     76      return new Thread(() => {
     77        while (!abortThreadPending) {
     78          lock (locker) {
     79            // check if cwfService is disconnected for any reason (should happen at first heartbeat)
     80            // [chn] TODO: Client should always send heartbeats. when calendar disallows he should tell the server he does not want to compute anything
     81            if (wcfService.ConnState == NetworkEnum.WcfConnState.Disconnected) {
    10982              wcfService.Connect();
    11083            }
    111           } else {
    112             //We have quit a lot of work to do here: snapshot all jobs, submit them back, then disconnect and then pray to god that nothing goes wrong
    113             MessageQueue.GetInstance().AddMessage(MessageContainer.MessageType.UptimeLimitDisconnect);
    114           }
    115         }
    116         if (wcfService.ConnState == NetworkEnum.WcfConnState.Failed) {
    117           wcfService.Connect();
    118         } else if (wcfService.ConnState == NetworkEnum.WcfConnState.Loggedin) {
    119           Logger.Debug("Sending Heartbeat: " + heartBeatData);
    120           wcfService.ProcessHeartBeatAsync(heartBeatData);
    121         }
    122       }
     84
     85            if (wcfService.ConnState == NetworkEnum.WcfConnState.Loggedin) {
     86
     87              // client is allowed to calculate stuff
     88              ClientDto info = ConfigManager.Instance.GetClientInfo();
     89             
     90              HeartBeatData heartBeatData = new HeartBeatData {
     91                SlaveId = info.Id,
     92                FreeCores = info.NrOfCores - ConfigManager.Instance.GetUsedCores(),
     93                FreeMemory = GetFreeMemory(),
     94                JobProgress = ConfigManager.Instance.GetProgressOfAllJobs(),
     95                IsAllowedToCalculate = UptimeManager.Instance.IsOnline() && UptimeManager.Instance.CalendarAvailable
     96              };
     97
     98              if (!heartBeatData.IsAllowedToCalculate) {
     99                // stop all running jobs and send snapshots to server
     100                MessageQueue.GetInstance().AddMessage(MessageContainer.MessageType.UptimeLimitDisconnect);
     101              }
     102
     103              Logger.Debug("Sending Heartbeat: " + heartBeatData);
     104              wcfService.ProcessHeartBeatAsync(heartBeatData);
     105            }
     106
     107          } // lock
     108          Thread.Sleep(Interval);
     109        } // while
     110        abortThreadPending = false;
     111      });
     112    }
     113
     114    private int GetFreeMemory() {
     115      PerformanceCounter counter = new PerformanceCounter("Memory", "Available Bytes", true);
     116      int mb = (int)(counter.NextValue() / 1024 / 1024);
     117      return mb;
    123118    }
    124119
     
    129124
    130125    public void StopHeartBeat() {
    131       heartbeatTimer.Dispose();
     126      abortThreadPending = true;
    132127    }
    133128  }
Note: See TracChangeset for help on using the changeset viewer.