Unindent
[?]
Aug 10, 2015, 9:26 AM
4I2HF4L3JOC6KPYLI2YTEVTHBRRYO5XKXOZ6VQ2SJKSQKAPNQXCQCDependencies
- [2]
YR2IM6Y5Temporarily disable machines after a connection failure - [3]
MHVIT4JYSplit hydra-queue-runner.cc more - [*]
HJOEIMLRRefactor
Change contents
- replacement in src/hydra-queue-runner/dispatcher.cc at line 34
auto sleepUntil = system_time::max();auto sleepUntil = doDispatch(); - replacement in src/hydra-queue-runner/dispatcher.cc at line 36
bool keepGoing;/* Sleep until we're woken up (either because a runnable buildis added, or because a build finishes). */{std::unique_lock<std::mutex> lock(dispatcherMutex);printMsg(lvlDebug, format("dispatcher sleeping for %1%s") %std::chrono::duration_cast<std::chrono::seconds>(sleepUntil - std::chrono::system_clock::now()).count());dispatcherWakeup.wait_until(lock, sleepUntil);nrDispatcherWakeups++;}}printMsg(lvlError, "dispatcher exits");} - replacement in src/hydra-queue-runner/dispatcher.cc at line 50
do {system_time now = std::chrono::system_clock::now();system_time State::doDispatch(){auto sleepUntil = system_time::max();bool keepGoing;do {system_time now = std::chrono::system_clock::now(); - replacement in src/hydra-queue-runner/dispatcher.cc at line 60[2.1278]→[3.15294:15430](∅→∅),[3.15294]→[3.15294:15430](∅→∅),[3.15430]→[2.1279:1410](∅→∅),[2.1410]→[3.15499:15755](∅→∅),[3.15499]→[3.15499:15755](∅→∅),[3.15755]→[2.1411:1787](∅→∅),[2.1787]→[3.15799:15887](∅→∅),[3.15799]→[3.15799:15887](∅→∅)
/* Copy the currentJobs field of each machine. This isnecessary to ensure that the sort comparator below isan ordering. std::sort() can segfault if it isn't. Alsofilter out temporarily disabled machines. */struct MachineInfo{Machine::ptr machine;unsigned int currentJobs;};std::vector<MachineInfo> machinesSorted;{auto machines_(machines.lock());for (auto & m : *machines_) {auto info(m.second->state->connectInfo.lock());if (info->consecutiveFailures && info->disabledUntil > now) {if (info->disabledUntil < sleepUntil)sleepUntil = info->disabledUntil;continue;}machinesSorted.push_back({m.second, m.second->state->currentJobs});/* Copy the currentJobs field of each machine. This isnecessary to ensure that the sort comparator below isan ordering. std::sort() can segfault if it isn't. Alsofilter out temporarily disabled machines. */struct MachineInfo{Machine::ptr machine;unsigned int currentJobs;};std::vector<MachineInfo> machinesSorted;{auto machines_(machines.lock());for (auto & m : *machines_) {auto info(m.second->state->connectInfo.lock());if (info->consecutiveFailures && info->disabledUntil > now) {if (info->disabledUntil < sleepUntil)sleepUntil = info->disabledUntil;continue; - edit in src/hydra-queue-runner/dispatcher.cc at line 79
machinesSorted.push_back({m.second, m.second->state->currentJobs}); - edit in src/hydra-queue-runner/dispatcher.cc at line 81
} - replacement in src/hydra-queue-runner/dispatcher.cc at line 83
/* Sort the machines by a combination of speed factor andavailable slots. Prioritise the available machines asfollows:/* Sort the machines by a combination of speed factor andavailable slots. Prioritise the available machines asfollows: - replacement in src/hydra-queue-runner/dispatcher.cc at line 87
- First by load divided by speed factor, rounded to thenearest integer. This causes fast machines to bepreferred over slow machines with similar loads.- First by load divided by speed factor, rounded to thenearest integer. This causes fast machines to bepreferred over slow machines with similar loads. - replacement in src/hydra-queue-runner/dispatcher.cc at line 91
- Then by speed factor.- Then by speed factor. - replacement in src/hydra-queue-runner/dispatcher.cc at line 93
- Finally by load. */sort(machinesSorted.begin(), machinesSorted.end(),[](const MachineInfo & a, const MachineInfo & b) -> bool{float ta = roundf(a.currentJobs / a.machine->speedFactor);float tb = roundf(b.currentJobs / b.machine->speedFactor);returnta != tb ? ta < tb :a.machine->speedFactor != b.machine->speedFactor ? a.machine->speedFactor > b.machine->speedFactor :a.currentJobs > b.currentJobs;});- Finally by load. */sort(machinesSorted.begin(), machinesSorted.end(),[](const MachineInfo & a, const MachineInfo & b) -> bool{float ta = roundf(a.currentJobs / a.machine->speedFactor);float tb = roundf(b.currentJobs / b.machine->speedFactor);returnta != tb ? ta < tb :a.machine->speedFactor != b.machine->speedFactor ? a.machine->speedFactor > b.machine->speedFactor :a.currentJobs > b.currentJobs;}); - replacement in src/hydra-queue-runner/dispatcher.cc at line 105
/* Find a machine with a free slot and find a step to runon it. Once we find such a pair, we restart the outerloop because the machine sorting will have changed. */keepGoing = false;/* Find a machine with a free slot and find a step to runon it. Once we find such a pair, we restart the outerloop because the machine sorting will have changed. */keepGoing = false; - replacement in src/hydra-queue-runner/dispatcher.cc at line 110
for (auto & mi : machinesSorted) {// FIXME: can we lose a wakeup if a builder exits concurrently?if (mi.machine->state->currentJobs >= mi.machine->maxJobs) continue;for (auto & mi : machinesSorted) {// FIXME: can we lose a wakeup if a builder exits concurrently?if (mi.machine->state->currentJobs >= mi.machine->maxJobs) continue; - replacement in src/hydra-queue-runner/dispatcher.cc at line 114
auto runnable_(runnable.lock());//printMsg(lvlDebug, format("%1% runnable builds") % runnable_->size());auto runnable_(runnable.lock());//printMsg(lvlDebug, format("%1% runnable builds") % runnable_->size());/* FIXME: we're holding the runnable lock too longhere. This could be more efficient. */ - replacement in src/hydra-queue-runner/dispatcher.cc at line 120
/* FIXME: we're holding the runnable lock too longhere. This could be more efficient. */for (auto i = runnable_->begin(); i != runnable_->end(); ) {auto step = i->lock(); - replacement in src/hydra-queue-runner/dispatcher.cc at line 123
for (auto i = runnable_->begin(); i != runnable_->end(); ) {auto step = i->lock();/* Delete dead steps. */if (!step) {i = runnable_->erase(i);continue;} - replacement in src/hydra-queue-runner/dispatcher.cc at line 129
/* Delete dead steps. */if (!step) {i = runnable_->erase(i);continue;}/* Can this machine do this step? */if (!mi.machine->supportsStep(step)) {++i;continue;} - replacement in src/hydra-queue-runner/dispatcher.cc at line 135
/* Can this machine do this step? */if (!mi.machine->supportsStep(step)) {/* Skip previously failed steps that aren't readyto be retried. */{auto step_(step->state.lock());if (step_->tries > 0 && step_->after > now) {if (step_->after < sleepUntil)sleepUntil = step_->after; - edit in src/hydra-queue-runner/dispatcher.cc at line 145
} - replacement in src/hydra-queue-runner/dispatcher.cc at line 147
/* Skip previously failed steps that aren't readyto be retried. */{auto step_(step->state.lock());if (step_->tries > 0 && step_->after > now) {if (step_->after < sleepUntil)sleepUntil = step_->after;++i;continue;}}/* Make a slot reservation and start a thread todo the build. */auto reservation = std::make_shared<MaintainCount>(mi.machine->state->currentJobs);i = runnable_->erase(i);auto builderThread = std::thread(&State::builder, this, step, mi.machine, reservation);builderThread.detach(); // FIXME?/* Make a slot reservation and start a thread todo the build. */auto reservation = std::make_shared<MaintainCount>(mi.machine->state->currentJobs);i = runnable_->erase(i); - replacement in src/hydra-queue-runner/dispatcher.cc at line 152
keepGoing = true;break;}auto builderThread = std::thread(&State::builder, this, step, mi.machine, reservation);builderThread.detach(); // FIXME? - replacement in src/hydra-queue-runner/dispatcher.cc at line 155
if (keepGoing) break;keepGoing = true;break; - replacement in src/hydra-queue-runner/dispatcher.cc at line 159
} while (keepGoing);if (keepGoing) break;} - replacement in src/hydra-queue-runner/dispatcher.cc at line 162
/* Sleep until we're woken up (either because a runnable buildis added, or because a build finishes). */{std::unique_lock<std::mutex> lock(dispatcherMutex);printMsg(lvlDebug, format("dispatcher sleeping for %1%s") %std::chrono::duration_cast<std::chrono::seconds>(sleepUntil - std::chrono::system_clock::now()).count());dispatcherWakeup.wait_until(lock, sleepUntil);nrDispatcherWakeups++;}}} while (keepGoing); - replacement in src/hydra-queue-runner/dispatcher.cc at line 164
printMsg(lvlError, "dispatcher exits");return sleepUntil; - edit in src/hydra-queue-runner/state.hh at line 291[5.8158][5.8158]
system_time doDispatch();