Changeset 1500


Ignore:
Timestamp:
04/03/09 12:47:47 (12 years ago)
Author:
msteinbi
Message:

Scheduler checks for free cores now (#507)

Location:
trunk/sources
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Hive.Contracts/BusinessObjects/Client.cs

    r1498 r1500  
    4141    public int Memory { get; set; }
    4242    [DataMember]
     43    public int FreeMemory { get; set; }
     44    [DataMember]
    4345    public DateTime Login { get; set; }
    4446    [DataMember]
  • trunk/sources/HeuristicLab.Hive.Server.Core/ClientCommunicator.cs

    r1490 r1500  
    216216
    217217        ResponseHB response = new ResponseHB();
     218        response.ActionRequest = new List<MessageContainer>();
     219
     220        ClientInfo client = clientAdapter.GetById(hbData.ClientId);
    218221
    219222        // check if the client is logged in
    220         response.ActionRequest = new List<MessageContainer>();
    221         if (clientAdapter.GetById(hbData.ClientId).State == State.offline ||
    222             clientAdapter.GetById(hbData.ClientId).State == State.nullState) {
     223        if (client.State == State.offline || client.State == State.nullState) {
    223224          response.Success = false;
    224225          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_USER_NOT_LOGGED_IN;
     
    226227          return response;
    227228        }
     229
     230        client.NrOfFreeCores = hbData.FreeCores;
     231        client.FreeMemory = hbData.FreeMemory;
    228232
    229233        // save timestamp of this heartbeat
     
    245249          response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.NoMessage));
    246250
    247         if (hbData.JobProgress != null) {
    248           List<Job> jobsOfClient = new List<Job>(jobAdapter.GetActiveJobsOf(clientAdapter.GetById(hbData.ClientId)));
    249           if (jobsOfClient == null || jobsOfClient.Count == 0) {
    250             response.Success = false;
    251             response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
    252             return response;
    253           }
    254 
    255           foreach (KeyValuePair<Guid, double> jobProgress in hbData.JobProgress) {
    256             Job curJob = jobAdapter.GetById(jobProgress.Key);
    257             if (curJob.Client == null || curJob.Client.Id != hbData.ClientId) {
    258               response.Success = false;
    259               response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
    260             } else if (curJob.State == State.finished) {
    261               // another client has finished this job allready
    262               // the client can abort it
    263               response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, curJob.Id));
    264             } else {
    265               // save job progress
    266               curJob.Percentage = jobProgress.Value;
    267               jobAdapter.Update(curJob);
    268             }
    269           }
    270         }
     251        processJobProcess(hbData, jobAdapter, clientAdapter, response);
     252        clientAdapter.Update(client);
     253
    271254        tx.Commit();
    272255        return response;
     
    280263        if (session != null)
    281264          session.EndSession();
     265      }
     266    }
     267
     268    /// <summary>
     269    /// Process the Job progress sent by a client
     270    /// </summary>
     271    /// <param name="hbData"></param>
     272    /// <param name="jobAdapter"></param>
     273    /// <param name="clientAdapter"></param>
     274    /// <param name="response"></param>
     275    private void processJobProcess(HeartBeatData hbData, IJobAdapter jobAdapter, IClientAdapter clientAdapter, ResponseHB response) {
     276      if (hbData.JobProgress != null) {
     277        List<Job> jobsOfClient = new List<Job>(jobAdapter.GetActiveJobsOf(clientAdapter.GetById(hbData.ClientId)));
     278        if (jobsOfClient == null || jobsOfClient.Count == 0) {
     279          response.Success = false;
     280          response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
     281          return;
     282        }
     283
     284        foreach (KeyValuePair<Guid, double> jobProgress in hbData.JobProgress) {
     285          Job curJob = jobAdapter.GetById(jobProgress.Key);
     286          if (curJob.Client == null || curJob.Client.Id != hbData.ClientId) {
     287            response.Success = false;
     288            response.StatusMessage = ApplicationConstants.RESPONSE_COMMUNICATOR_JOB_IS_NOT_BEEING_CALCULATED;
     289          } else if (curJob.State == State.finished) {
     290            // another client has finished this job allready
     291            // the client can abort it
     292            response.ActionRequest.Add(new MessageContainer(MessageContainer.MessageType.AbortJob, curJob.Id));
     293          } else {
     294            // save job progress
     295            curJob.Percentage = jobProgress.Value;
     296            jobAdapter.Update(curJob);
     297          }
     298        }
    282299      }
    283300    }
  • trunk/sources/HeuristicLab.Hive.Server.Scheduler/DefaultScheduler.cs

    r1468 r1500  
    3030          session.GetDataAdapter<Job, IJobAdapter>();
    3131
    32         List<Job> allOfflineJobs = new List<Job>(jobAdapter.GetJobsByState(State.offline));
    33         return (allOfflineJobs.Count > 0);
     32        List<Job> allOfflineJobsForClient = new List<Job>(jobAdapter.FindJobs(State.offline, hbData.FreeCores, hbData.FreeMemory));
     33        return (allOfflineJobsForClient != null && allOfflineJobsForClient.Count > 0);
    3434      }
    3535      finally {
     
    5252        jobLock.WaitOne();
    5353
    54         LinkedList<Job> allOfflineJobs = new LinkedList<Job>(jobAdapter.GetJobsByState(State.offline));
     54        ClientInfo client = clientAdapter.GetById(clientId);
     55        LinkedList<Job> allOfflineJobsForClient = new LinkedList<Job>(jobAdapter.FindJobs(State.offline, client.NrOfFreeCores, client.FreeMemory ));
    5556
    56         Job job2Calculate = null;
    57         if (allOfflineJobs != null && allOfflineJobs.Count > 0) {
    58           job2Calculate = allOfflineJobs.First.Value;
    59           job2Calculate.State = State.calculating;
    60           job2Calculate.Client = clientAdapter.GetById(clientId);
    61           job2Calculate.Client.State = State.calculating;
     57        Job jobToCalculate = null;
     58        if (allOfflineJobsForClient != null && allOfflineJobsForClient.Count > 0) {
     59          jobToCalculate = allOfflineJobsForClient.First.Value;
     60          jobToCalculate.State = State.calculating;
     61          jobToCalculate.Client = client;
     62          jobToCalculate.Client.State = State.calculating;
    6263
    63           job2Calculate.DateCalculated = DateTime.Now;
    64           jobAdapter.Update(job2Calculate);
     64          jobToCalculate.DateCalculated = DateTime.Now;
     65          jobAdapter.Update(jobToCalculate);
    6566        }
    6667        jobLock.ReleaseMutex();
    6768        /// End Critical section ///
    6869
    69         return job2Calculate;
     70        return jobToCalculate;
    7071      }
    7172      finally {
Note: See TracChangeset for help on using the changeset viewer.