hydra-queue-runner: Limit memory usage
[?]
Mar 9, 2016, 1:30 PM
SL3WSRACCX2IMJHHLTRAUQT7QDLCOKYLVO2FEHWIHXM5GPKSRJTQCDependencies
- [2]
B2L4T3X6Sync with Nix - [3]
UVNTWTWGPrevent download of NARs we just uploaded - [4]
BRAESISHWarn if PostgreSQL appears stalled - [5]
MB3TISH2Rate-limit the number of threads copying closures at the same time - [6]
DIEY5USNKeep better bytesReceived/bytesSent stats - [7]
LE4VZIY5More stats - [8]
GJV2J5HXPool local store connections - [9]
5AIYUMTBBasic remote building - [10]
N4IROACVMove buildRemote() into State - [11]
FITVNQ2SKeep track of the time we spend copying to/from build machines - [12]
A2GL5FOZMoar stats - [13]
CNLNT3T4Allow only 1 thread to send a closure to a given machine at the same time - [14]
OG3Z3QGCNamespace cleanup - [15]
73YR46NJhydra-queue-runner: Write directly to a binary cache - [16]
HJOEIMLRRefactor - [17]
6EO3HVNAMerge remote-tracking branch 'origin/master' into binary-cache - [*]
24BMQDZAStart of single-process hydra-queue-runner - [*]
PLOZBRTRAdd command ‘hydra-queue-runner --status’ to show current status - [*]
IK2UBDAURevive jobset scheduling - [*]
EYR3EW6JKeep stats for the Hydra auto scaler - [*]
EOO4EFWDUse a single BinaryCacheStore for all threads
Change contents
- replacement in src/hydra-queue-runner/build-remote.cc at line 286
printMsg(lvlDebug, format("copying outputs of ‘%1%’ from ‘%2%’") % step->drvPath % machine->sshName);MaintainCount mc(nrStepsCopyingFrom);auto now1 = std::chrono::steady_clock::now(); - replacement in src/hydra-queue-runner/build-remote.cc at line 293
MaintainCount mc(nrStepsCopyingFrom);/* Query the size of the output paths. */size_t totalNarSize = 0;to << cmdQueryPathInfos << outputs;to.flush();while (true) {if (readString(from) == "") break;readString(from); // deriverreadStrings<PathSet>(from); // referencesreadLongLong(from); // download sizetotalNarSize += readLongLong(from);}printMsg(lvlDebug, format("copying outputs of ‘%s’ from ‘%s’ (%d bytes)")% step->drvPath % machine->sshName % totalNarSize);/* Block until we have the required amount of memoryavailable. FIXME: only need this for binary cachedestination stores. */auto resStart = std::chrono::steady_clock::now();auto memoryReservation(memoryTokens.get(totalNarSize));auto resStop = std::chrono::steady_clock::now(); - replacement in src/hydra-queue-runner/build-remote.cc at line 316
result.accessor = destStore->getFSAccessor();auto resMs = std::chrono::duration_cast<std::chrono::milliseconds>(resStop - resStart).count();if (resMs >= 1000)printMsg(lvlError, format("warning: had to wait %d ms for %d memory tokens for %s")% resMs % totalNarSize % step->drvPath); - replacement in src/hydra-queue-runner/build-remote.cc at line 321
auto now1 = std::chrono::steady_clock::now();result.accessor = destStore->getFSAccessor(); - edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 20
: memoryTokens(4ULL << 30) // FIXME: make this configurable - edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 571
root.attr("memoryTokensInUse", memoryTokens.currentUse()); - edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 595
- edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 607
- edit in src/hydra-queue-runner/state.hh at line 12
#include "token-server.hh"#include "derivations.hh" - edit in src/hydra-queue-runner/state.hh at line 17
#include "sync.hh" - replacement in src/hydra-queue-runner/state.hh at line 18
#include "derivations.hh"#include "binary-cache-store.hh" // FIXME#include "sync.hh" - edit in src/hydra-queue-runner/state.hh at line 355[23.1502][23.1502]
/* Token server to prevent threads from allocating too many bigstrings concurrently while importing NARs from the buildmachines. When a thread imports a NAR of size N, it will firstacquire N memory tokens, causing it to block until that manytokens are available. */nix::TokenServer memoryTokens; - edit in src/hydra-queue-runner/token-server.hh at line 6
#include "types.hh"namespace nix { - edit in src/hydra-queue-runner/token-server.hh at line 10
MakeError(NoTokens, Error) - replacement in src/hydra-queue-runner/token-server.hh at line 13
available. Calling get() will return a Token object, representingownership of a token. If no token is available, get() will sleepuntil another thread returns a token. */available. Calling get(N) will return a Token object, representingownership of N tokens. If the requested number of tokens isunavailable, get() will sleep until another thread returns atoken. */ - replacement in src/hydra-queue-runner/token-server.hh at line 20
unsigned int maxTokens;const size_t maxTokens; - replacement in src/hydra-queue-runner/token-server.hh at line 22
Sync<unsigned int> curTokens{0};Sync<size_t> inUse{0}; - replacement in src/hydra-queue-runner/token-server.hh at line 26
TokenServer(unsigned int maxTokens) : maxTokens(maxTokens) { }TokenServer(size_t maxTokens) : maxTokens(maxTokens) { } - edit in src/hydra-queue-runner/token-server.hh at line 34
size_t tokens; - replacement in src/hydra-queue-runner/token-server.hh at line 38
Token(TokenServer * ts, unsigned int timeout) : ts(ts)Token(TokenServer * ts, size_t tokens, unsigned int timeout): ts(ts), tokens(tokens) - replacement in src/hydra-queue-runner/token-server.hh at line 41
auto curTokens(ts->curTokens.lock());while (*curTokens >= ts->maxTokens)if (tokens >= ts->maxTokens)throw NoTokens(format("requesting more tokens (%d) than exist (%d)") % tokens);auto inUse(ts->inUse.lock());while (*inUse + tokens > ts->maxTokens) - replacement in src/hydra-queue-runner/token-server.hh at line 46
if (!curTokens.wait_for(ts->wakeup, std::chrono::seconds(timeout),[&]() { return *curTokens < ts->maxTokens; }))if (!inUse.wait_for(ts->wakeup, std::chrono::seconds(timeout),[&]() { return *inUse + tokens <= ts->maxTokens; })) - replacement in src/hydra-queue-runner/token-server.hh at line 50
curTokens.wait(ts->wakeup);(*curTokens)++;inUse.wait(ts->wakeup);*inUse += tokens; - replacement in src/hydra-queue-runner/token-server.hh at line 64
auto curTokens(ts->curTokens.lock());assert(*curTokens);(*curTokens)--;auto inUse(ts->inUse.lock());assert(*inUse >= tokens);*inUse -= tokens; - replacement in src/hydra-queue-runner/token-server.hh at line 74
Token get(unsigned int timeout = 0)Token get(size_t tokens = 1, unsigned int timeout = 0){return Token(this, tokens, timeout);}size_t currentUse() - replacement in src/hydra-queue-runner/token-server.hh at line 81
return Token(this, timeout);auto inUse_(inUse.lock());return *inUse_; - edit in src/hydra-queue-runner/token-server.hh at line 85[5.3315]
}