public void LogFinishedSplit(string workerId, long totalSplits, long remainingSplits) { lock (LockLogFinished) { long splitId = remainingSplits; SplitInfo splitInfo = splitInfos[splitId]; if (splitInfo.DidFinished()) { //Logger.LogInfo("[" + workerId + " SLOW FINISHED " + splitId + "]"); return; } splitInfos[splitId].EndedSplit(); averageSplitTime = splitInfos[splitId].SplitTime() + 500; numSplits--; Logger.LogInfo("[" + workerId + " ENDED " + splitId + "] in " + splitInfos[splitId].SplitTime() + " ms. " + numSplits + " splits remaining"); } }
public SplitInfo FindSlowSplit() { foreach (KeyValuePair <string, long> keyValue in workersSplits) { string key = keyValue.Key; SplitInfo splitInfo = splitInfos[keyValue.Value]; if (averageSplitTime < long.MaxValue) { long waitTime = splitInfo.splitId == 0 ? 3 * averageSplitTime : 2 * averageSplitTime; if (!splitInfo.DidFinished() && splitInfo.SplitTime() > waitTime) { Logger.LogWarn("[SPLIT " + splitInfo.splitId + " SLOW] taking " + splitInfo.SplitTime() + " vs " + waitTime); return(splitInfo); } } } return(null); }
private void StartPrimaryJobTrackerProcess(string clientUrl, long fileSize, long numSplits, string mapperName, byte[] mapperCode) { currentJobTrackerUrl = this.myURL; serverRole = ServerRole.JOB_TRACKER; status = ExecutionState.WORKING; isPrimary = true; jtInformation = new JobTrackerInformation(this, numSplits); this.clientURL = clientUrl; this.fileSize = fileSize; client = (IClient)Activator.GetObject(typeof(IClient), clientURL); this.mapperName = mapperName; this.mapperCode = mapperCode; Thread trackWorkersThread = new Thread(() => { while (!jtInformation.DidFinishJob() && isPrimary && serverRole == ServerRole.JOB_TRACKER) { /* wait until if I am unfrozen and revert to Worker if needed */ if (WaitForUnfreezeAndCheckChanges()) { break; } /* --------------------------- */ Logger.LogInfo("[CHECKING SLOW WORKERS]"); SplitInfo slowSplit = jtInformation.FindSlowSplit(); if (slowSplit != null) { //Logger.LogWarn("There is a slow split - " + slowSplit.splitId); IWorker freeWorker = jtInformation.GetFirstFreeWorker(); if (freeWorker != null) { Logger.LogWarn("[SLOWWWWWWW SPLIT] RESENDING " + slowSplit.remainingSplits); ResendSplitToNextWorker(freeWorker, slowSplit.fileSize, slowSplit.totalSplits, slowSplit.remainingSplits); } } Thread.Sleep(4000); } serverRole = ServerRole.NONE; status = ExecutionState.WAITING; }); trackWorkersThread.Start(); Thread ConfigureSecondaryServerThread = new Thread(() => { //wait for an available backUrl, then pings it then sets up as primary Server while (isPrimary && serverRole == ServerRole.JOB_TRACKER && !jtInformation.DidFinishJob()) { if (backURL == myURL) { continue; } //Logger.LogInfo("Waiting for an available url to be the secondary JT"); secondaryJT = (IWorker)Activator.GetObject(typeof(IWorker), backURL); try { secondaryJT.PingJT(); backupSecondaryServerIfFailsUrl = secondaryJT.SetUpAsSecondaryServer(this.clientURL, this.myURL, fileSize, numSplits, mapperName, mapperCode); backupSecondaryServerIfFails = (IWorker)Activator.GetObject(typeof(IWorker), backupSecondaryServerIfFailsUrl); Logger.LogInfo("Success setting setup backupserver"); break; } catch (Exception) { Logger.LogInfo("There is still no backUrl available to become backup server"); } Thread.Sleep(1000); } }); ConfigureSecondaryServerThread.Start(); if (!primaryDidStartedJob && !firstRequest) { primaryDidStartedJob = true; ReceiveWork(clientUrl, fileSize, numSplits, mapperName, mapperCode); } firstRequest = false; }