hydra-queue-runner: More accurate memory accounting

[?]
Nov 16, 2016, 4:46 PM
YNO7CQ6P56YQP7UMGQFL4AZED7DBXE32U7TI6OMOKT6GMWZDMWWQC

Dependencies

  • [2] MQNJPMCU Fix bad format string
  • [3] BYVRA54Q Temporarily disable machines on any exception, not just connection failures
  • [4] MB3TISH2 Rate-limit the number of threads copying closures at the same time
  • [5] BG6PEOB2 Make the output size limit configurable
  • [6] SL3WSRAC hydra-queue-runner: Limit memory usage
  • [*] 5AIYUMTB Basic remote building
  • [*] UVNTWTWG Prevent download of NARs we just uploaded
  • [*] MHVIT4JY Split hydra-queue-runner.cc more
  • [*] HJOEIMLR Refactor
  • [*] N4IROACV Move buildRemote() into State

Change contents

  • replacement in src/hydra-queue-runner/build-remote.cc at line 376
    [3.8141][3.8141:8244]()
    available. FIXME: only need this for binary cache
    destination stores. */
    [3.8141]
    [3.8244]
    available, which is twice the NAR size (namely the
    uncompressed and worst-case compressed NAR), plus 150
    MB for xz compression overhead. (The xz manpage claims
    ~94 MiB, but that's not was I'm seeing.) */
  • replacement in src/hydra-queue-runner/build-remote.cc at line 381
    [3.8306][3.8306:8374]()
    auto memoryReservation(memoryTokens.get(totalNarSize));
    [3.8306]
    [3.8374]
    size_t compressionCost = totalNarSize + 150 * 1024 * 1024;
    result.tokens = std::make_unique<nix::TokenServer::Token>(memoryTokens.get(totalNarSize + compressionCost));
  • edit in src/hydra-queue-runner/build-remote.cc at line 396
    [9.232]
    [3.8937]
    /* Release the tokens pertaining to NAR
    compression. After this we only have the uncompressed
    NAR in memory. */
    result.tokens->give_back(compressionCost);
  • edit in src/hydra-queue-runner/builder.cc at line 182
    [9.441]
    [10.4678]
    result.accessor = 0;
    result.tokens = 0;
  • edit in src/hydra-queue-runner/state.hh at line 53
    [12.1810]
    [9.442]
    std::unique_ptr<nix::TokenServer::Token> tokens;
  • edit in src/hydra-queue-runner/token-server.hh at line 43
    [2.112]
    [4.2573]
    debug("acquiring %d tokens", tokens);
  • replacement in src/hydra-queue-runner/token-server.hh at line 58
    [4.2807][4.2807:2858]()
    Token(Token && t) : ts(t.ts) { t.ts = 0; }
    [4.2807]
    [4.2858]
    Token(Token && t) : ts(t.ts), tokens(t.tokens), acquired(t.acquired)
    {
    t.ts = 0;
    t.acquired = false;
    }
  • edit in src/hydra-queue-runner/token-server.hh at line 68
    [4.2969]
    [4.2969]
    give_back(tokens);
    }
    bool operator ()() { return acquired; }
    void give_back(size_t t)
    {
    debug("returning %d tokens", t);
    if (!t) return;
    assert(acquired);
    assert(t <= tokens);
  • replacement in src/hydra-queue-runner/token-server.hh at line 81
    [4.2954][4.2954:3030]()
    assert(*inUse >= tokens);
    *inUse -= tokens;
    [4.2954]
    [4.3105]
    assert(*inUse >= t);
    *inUse -= t;
    tokens -= t;
  • replacement in src/hydra-queue-runner/token-server.hh at line 85
    [4.3119][4.3119:3156]()
    ts->wakeup.notify_one();
    [4.3119]
    [4.3156]
    // FIXME: inefficient. Should wake up waiters that can
    // proceed now.
    ts->wakeup.notify_all();
  • edit in src/hydra-queue-runner/token-server.hh at line 90
    [4.3167][4.3167:3215]()
    bool operator ()() { return acquired; }