private void checkForStruggleWorkers() { while (true) { Thread.Sleep(TIME_TO_WAIT_FOR_WORKER_TO_COMPLETE_JOB); foreach (OverseenWorker worker in manager.ListWorkers) { // check if the other nodes are not slow if (worker.Assignment != null) { logger.Log("WORKER W" + worker.WorkerId + " IS A STRAGGLER"); foreach (OverseenWorker otherWorker in manager.ListWorkers) { if (otherWorker.Assignment == null) { logger.Log("Assigning work to: W" + otherWorker.WorkerId); otherWorker.Assignment = worker.Assignment; if (otherWorker.Assignment != null) { otherWorker.Assignment.WorkerId = otherWorker.WorkerId; int workerControllerId = (otherWorker.WorkerId + 1) % (manager.Count + 1); if (workerControllerId == 0) { workerControllerId = 1; } // Gets the service for the worker, but checks if that worker is himself WorkerService otherWorkerService = null; if (otherWorker.WorkerId == id) { AsyncSetWorkerSubmitContext submit = new AsyncSetWorkerSubmitContext(this.LoadSubmitContext); submit.BeginInvoke(clientURL, mapClass, code, otherWorker.Assignment.Jobs, workerControllerId, null, null); } else { otherWorkerService = otherWorker.Service; otherWorkerService.LoadSubmitContext(clientURL, this.mapClass, this.code, otherWorker.Assignment.Jobs, workerControllerId); } // No need to loop back again since someone else did the job worker.Assignment = null; return; } } } } } return; } }
/// <summary> /// This method is responsible for obtaining the list /// of available workers and deliver to each one their /// piece of the job list. /// The clientURL is passed so that it is /// transferred to each one, so they know who to /// deliver it to when they're done. /// Alongside the clientURL, the name of the mapper class /// and the code (in bytes) containing said class is also passed, /// so it can be loaded by the worker at run-time. /// </summary> /// <param name="clientURL"></param> /// <param name="mapClass"></param> /// <param name="code"></param> public void SubmitJob(string clientURL, string mapClass, byte[] code) { if (code == null) { return; } this.mapClass = mapClass; this.code = code; logger.Log("Submit BEGIN"); // Calculate what each worker is going to do IList <JobAssignment> listJobAssignments = assignJobs(); // Call each worker to process their job foreach (JobAssignment jobAssignment in listJobAssignments) { int workerId = jobAssignment.WorkerId; logger.Log("Submitting job to W" + workerId); checkForFrozenCommunication(); int workerControllerId = (workerId + 1) % (manager.Count + 1); if (workerControllerId == 0) { workerControllerId = 1; } logger.Log(" Woker: " + workerId + " Will be controlled by: " + workerControllerId); if (workerId == -1 || workerId == id) // Checks if assignment is for himself { AsyncSetWorkerSubmitContext submit = new AsyncSetWorkerSubmitContext(this.LoadSubmitContext); submit.BeginInvoke(clientURL, mapClass, code, jobAssignment.Jobs, workerControllerId, null, null); } else { try { WorkerService worker = manager.GetOverseenWorker(workerId).Service; worker.LoadSubmitContext(clientURL, mapClass, code, jobAssignment.Jobs, workerControllerId); } catch (Exception) { continue; } } } }
private void checkForStruggleWorkers() { while (true) { Thread.Sleep(TIME_TO_WAIT_FOR_WORKER_TO_COMPLETE_JOB); foreach (OverseenWorker worker in manager.ListWorkers) { // check if the other nodes are not slow if (worker.Assignment != null) { logger.Log("WORKER W" + worker.WorkerId + " IS A STRAGGLER"); foreach (OverseenWorker otherWorker in manager.ListWorkers) { if (otherWorker.Assignment == null) { logger.Log("Assigning work to: W" + otherWorker.WorkerId); otherWorker.Assignment = worker.Assignment; if (otherWorker.Assignment != null) { otherWorker.Assignment.WorkerId = otherWorker.WorkerId; int workerControllerId = (otherWorker.WorkerId + 1) % (manager.Count + 1); if (workerControllerId == 0) workerControllerId = 1; // Gets the service for the worker, but checks if that worker is himself WorkerService otherWorkerService = null; if (otherWorker.WorkerId == id) { AsyncSetWorkerSubmitContext submit = new AsyncSetWorkerSubmitContext(this.LoadSubmitContext); submit.BeginInvoke(clientURL, mapClass, code, otherWorker.Assignment.Jobs, workerControllerId, null, null); } else { otherWorkerService = otherWorker.Service; otherWorkerService.LoadSubmitContext(clientURL, this.mapClass, this.code, otherWorker.Assignment.Jobs, workerControllerId); } // No need to loop back again since someone else did the job worker.Assignment = null; return; } } } } } return; } }
/// <summary> /// This method is responsible for obtaining the list /// of available workers and deliver to each one their /// piece of the job list. /// The clientURL is passed so that it is /// transferred to each one, so they know who to /// deliver it to when they're done. /// Alongside the clientURL, the name of the mapper class /// and the code (in bytes) containing said class is also passed, /// so it can be loaded by the worker at run-time. /// </summary> /// <param name="clientURL"></param> /// <param name="mapClass"></param> /// <param name="code"></param> public void SubmitJob(string clientURL, string mapClass, byte[] code) { if (code == null) { return; } this.mapClass = mapClass; this.code = code; logger.Log("Submit BEGIN"); // Calculate what each worker is going to do IList<JobAssignment> listJobAssignments = assignJobs(); // Call each worker to process their job foreach (JobAssignment jobAssignment in listJobAssignments) { int workerId = jobAssignment.WorkerId; logger.Log("Submitting job to W" + workerId); checkForFrozenCommunication(); int workerControllerId = (workerId + 1) % (manager.Count + 1); if (workerControllerId == 0) workerControllerId = 1; logger.Log(" Woker: " + workerId + " Will be controlled by: " + workerControllerId); if (workerId == -1 || workerId == id) { // Checks if assignment is for himself AsyncSetWorkerSubmitContext submit = new AsyncSetWorkerSubmitContext(this.LoadSubmitContext); submit.BeginInvoke(clientURL, mapClass, code, jobAssignment.Jobs, workerControllerId, null, null); } else { try { WorkerService worker = manager.GetOverseenWorker(workerId).Service; worker.LoadSubmitContext(clientURL, mapClass, code, jobAssignment.Jobs, workerControllerId); } catch (Exception) { continue; } } } }