hydra-queue-runner: Limit memory usage
When using a binary cache store, the queue runner receives NARs from the build machines, compresses them, and uploads them to the cache. However, keeping multiple large NARs in memory can cause the queue runner to run out of memory. This can happen for instance when it's processing multiple ISO images concurrently. The fix is to use a TokenServer to prevent the builder threads to store more than a certain total size of NARs concurrently (at the moment, this is hard-coded at 4 GiB). Builder threads that cause the limit to be exceeded will block until other threads have finished. The 4 GiB limit does not include certain other allocations, such as for xz compression or for FSAccessor::readFile(). But since these are unlikely to be more than the size of the NARs and hydra.nixos.org has 32 GiB RAM, it should be fine.
This commit is contained in:
@ -9,14 +9,13 @@
|
||||
|
||||
#include "db.hh"
|
||||
#include "counter.hh"
|
||||
#include "token-server.hh"
|
||||
|
||||
#include "derivations.hh"
|
||||
#include "pathlocks.hh"
|
||||
#include "pool.hh"
|
||||
#include "sync.hh"
|
||||
|
||||
#include "store-api.hh"
|
||||
#include "derivations.hh"
|
||||
|
||||
#include "binary-cache-store.hh" // FIXME
|
||||
#include "sync.hh"
|
||||
|
||||
|
||||
typedef unsigned int BuildID;
|
||||
@ -354,6 +353,13 @@ private:
|
||||
std::shared_ptr<nix::Store> _localStore;
|
||||
std::shared_ptr<nix::Store> _destStore;
|
||||
|
||||
/* Token server to prevent threads from allocating too many big
|
||||
strings concurrently while importing NARs from the build
|
||||
machines. When a thread imports a NAR of size N, it will first
|
||||
acquire N memory tokens, causing it to block until that many
|
||||
tokens are available. */
|
||||
nix::TokenServer memoryTokens;
|
||||
|
||||
public:
|
||||
State();
|
||||
|
||||
|
Reference in New Issue
Block a user