Unindent

[?]
Aug 10, 2015, 9:26 AM
4I2HF4L3JOC6KPYLI2YTEVTHBRRYO5XKXOZ6VQ2SJKSQKAPNQXCQC

Dependencies

  • [2] YR2IM6Y5 Temporarily disable machines after a connection failure
  • [3] MHVIT4JY Split hydra-queue-runner.cc more
  • [*] HJOEIMLR Refactor

Change contents

  • replacement in src/hydra-queue-runner/dispatcher.cc at line 34
    [3.15209][3.15209:15255]()
    auto sleepUntil = system_time::max();
    [3.15209]
    [3.15255]
    auto sleepUntil = doDispatch();
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 36
    [3.15256][3.15256:15280]()
    bool keepGoing;
    [3.15256]
    [3.15280]
    /* Sleep until we're woken up (either because a runnable build
    is 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
    [3.15281][3.15281:15294](),[3.15294][2.1213:1277]()
    do {
    system_time now = std::chrono::system_clock::now();
    [3.15281]
    [2.1277]
    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 is
    necessary to ensure that the sort comparator below is
    an ordering. std::sort() can segfault if it isn't. Also
    filter 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});
    [2.1278]
    [2.1788]
    /* Copy the currentJobs field of each machine. This is
    necessary to ensure that the sort comparator below is
    an ordering. std::sort() can segfault if it isn't. Also
    filter 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
    [2.1806]
    [3.15887]
    machinesSorted.push_back({m.second, m.second->state->currentJobs});
  • edit in src/hydra-queue-runner/dispatcher.cc at line 81
    [3.15901]
    [3.15901]
    }
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 83
    [3.15902][3.15902:16065]()
    /* Sort the machines by a combination of speed factor and
    available slots. Prioritise the available machines as
    follows:
    [3.15902]
    [3.16065]
    /* Sort the machines by a combination of speed factor and
    available slots. Prioritise the available machines as
    follows:
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 87
    [3.16066][3.16066:16270]()
    - First by load divided by speed factor, rounded to the
    nearest integer. This causes fast machines to be
    preferred over slow machines with similar loads.
    [3.16066]
    [3.16270]
    - First by load divided by speed factor, rounded to the
    nearest integer. This causes fast machines to be
    preferred over slow machines with similar loads.
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 91
    [3.16271][3.16271:16310]()
    - Then by speed factor.
    [3.16271]
    [3.16310]
    - Then by speed factor.
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 93
    [3.16311][3.16311:16932]()
    - 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);
    return
    ta != tb ? ta < tb :
    a.machine->speedFactor != b.machine->speedFactor ? a.machine->speedFactor > b.machine->speedFactor :
    a.currentJobs > b.currentJobs;
    });
    [3.16311]
    [3.16932]
    - 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);
    return
    ta != 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
    [3.16933][3.16933:17173]()
    /* Find a machine with a free slot and find a step to run
    on it. Once we find such a pair, we restart the outer
    loop because the machine sorting will have changed. */
    keepGoing = false;
    [3.16933]
    [3.17237]
    /* Find a machine with a free slot and find a step to run
    on it. Once we find such a pair, we restart the outer
    loop because the machine sorting will have changed. */
    keepGoing = false;
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 110
    [3.17238][3.17238:17450]()
    for (auto & mi : machinesSorted) {
    // FIXME: can we lose a wakeup if a builder exits concurrently?
    if (mi.machine->state->currentJobs >= mi.machine->maxJobs) continue;
    [3.17238]
    [3.17450]
    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
    [3.17451][3.17451:17589]()
    auto runnable_(runnable.lock());
    //printMsg(lvlDebug, format("%1% runnable builds") % runnable_->size());
    [3.17451]
    [3.17589]
    auto runnable_(runnable.lock());
    //printMsg(lvlDebug, format("%1% runnable builds") % runnable_->size());
    /* FIXME: we're holding the runnable lock too long
    here. This could be more efficient. */
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 120
    [3.17590][3.17590:17715]()
    /* FIXME: we're holding the runnable lock too long
    here. This could be more efficient. */
    [3.17590]
    [3.17715]
    for (auto i = runnable_->begin(); i != runnable_->end(); ) {
    auto step = i->lock();
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 123
    [3.17716][3.17716:17836]()
    for (auto i = runnable_->begin(); i != runnable_->end(); ) {
    auto step = i->lock();
    [3.17716]
    [3.17836]
    /* Delete dead steps. */
    if (!step) {
    i = runnable_->erase(i);
    continue;
    }
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 129
    [3.17837][3.17837:18020]()
    /* Delete dead steps. */
    if (!step) {
    i = runnable_->erase(i);
    continue;
    }
    [3.17837]
    [3.18020]
    /* Can this machine do this step? */
    if (!mi.machine->supportsStep(step)) {
    ++i;
    continue;
    }
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 135
    [3.18021][3.18021:18137]()
    /* Can this machine do this step? */
    if (!mi.machine->supportsStep(step)) {
    [3.18021]
    [3.18137]
    /* Skip previously failed steps that aren't ready
    to 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
    [3.18222]
    [3.18222]
    }
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 147
    [3.18223][3.18223:19141]()
    /* Skip previously failed steps that aren't ready
    to 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 to
    do 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?
    [3.18223]
    [3.19141]
    /* Make a slot reservation and start a thread to
    do 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
    [3.19142][3.19142:19225]()
    keepGoing = true;
    break;
    }
    [3.19142]
    [3.19225]
    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
    [3.19226][3.19226:19264]()
    if (keepGoing) break;
    [3.19226]
    [3.19264]
    keepGoing = true;
    break;
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 159
    [3.19279][3.19279:19308]()
    } while (keepGoing);
    [3.19279]
    [3.19308]
    if (keepGoing) break;
    }
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 162
    [3.19309][3.19309:19812]()
    /* Sleep until we're woken up (either because a runnable build
    is 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++;
    }
    }
    [3.19309]
    [3.19812]
    } while (keepGoing);
  • replacement in src/hydra-queue-runner/dispatcher.cc at line 164
    [3.19813][3.19813:19857]()
    printMsg(lvlError, "dispatcher exits");
    [3.19813]
    [3.19857]
    return sleepUntil;
  • edit in src/hydra-queue-runner/state.hh at line 291
    [5.8158]
    [5.8158]
    system_time doDispatch();