Allow setting GC_INITIAL_HEAP_SIZE for hydra-eval-jobs

This cannot be done in the hydra-evaluator systemd unit, since then
every other Nix process (e.g. hydra-evaluator and nix-prefetch-*) will
also allocate the specified heap size, probably leading to OOM.
This commit is contained in:
Eelco Dolstra 2018-05-16 14:14:53 +02:00
parent 691f7e168c
commit 4e27796eba
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
4 changed files with 64 additions and 49 deletions

View file

@ -2,5 +2,4 @@ bin_PROGRAMS = hydra-eval-jobs
hydra_eval_jobs_SOURCES = hydra-eval-jobs.cc hydra_eval_jobs_SOURCES = hydra-eval-jobs.cc
hydra_eval_jobs_LDADD = $(NIX_LIBS) hydra_eval_jobs_LDADD = $(NIX_LIBS)
hydra_eval_jobs_CXXFLAGS = $(NIX_CFLAGS) -I ../libhydra
AM_CXXFLAGS = $(NIX_CFLAGS)

View file

@ -13,6 +13,8 @@
#include "globals.hh" #include "globals.hh"
#include "common-eval-args.hh" #include "common-eval-args.hh"
#include "hydra-config.hh"
using namespace nix; using namespace nix;
@ -157,6 +159,13 @@ int main(int argc, char * * argv)
unsetenv("NIX_PATH"); unsetenv("NIX_PATH");
return handleExceptions(argv[0], [&]() { return handleExceptions(argv[0], [&]() {
auto config = std::make_unique<::Config>();
auto initialHeapSize = config->getStrOption("evaluator_initial_heap_size", "");
if (initialHeapSize != "")
setenv("GC_INITIAL_HEAP_SIZE", initialHeapSize.c_str(), 1);
initNix(); initNix();
initGC(); initGC();

View file

@ -10,10 +10,11 @@
#include "store-api.hh" #include "store-api.hh"
#include "remote-store.hh" #include "remote-store.hh"
#include "shared.hh"
#include "globals.hh" #include "globals.hh"
#include "hydra-config.hh"
#include "json.hh" #include "json.hh"
#include "s3-binary-cache-store.hh" #include "s3-binary-cache-store.hh"
#include "shared.hh"
using namespace nix; using namespace nix;
@ -27,52 +28,6 @@ template<> void toJSON<double>(std::ostream & str, const double & n) { str << n;
} }
struct Config
{
std::map<std::string, std::string> options;
Config()
{
/* Read hydra.conf. */
auto hydraConfigFile = getEnv("HYDRA_CONFIG");
if (pathExists(hydraConfigFile)) {
for (auto line : tokenizeString<Strings>(readFile(hydraConfigFile), "\n")) {
line = trim(string(line, 0, line.find('#')));
auto eq = line.find('=');
if (eq == std::string::npos) continue;
auto key = trim(std::string(line, 0, eq));
auto value = trim(std::string(line, eq + 1));
if (key == "") continue;
options[key] = value;
}
}
}
std::string getStrOption(const std::string & key, const std::string & def = "")
{
auto i = options.find(key);
return i == options.end() ? def : i->second;
}
uint64_t getIntOption(const std::string & key, uint64_t def = 0)
{
auto i = options.find(key);
return i == options.end() ? def : std::stoll(i->second);
}
bool getBoolOption(const std::string & key, bool def = false)
{
auto i = options.find(key);
return i == options.end() ? def : (i->second == "true" || i->second == "1");
}
};
static uint64_t getMemSize() static uint64_t getMemSize()
{ {
auto pages = sysconf(_SC_PHYS_PAGES); auto pages = sysconf(_SC_PHYS_PAGES);

View file

@ -0,0 +1,52 @@
#pragma once
#include <map>
#include "util.hh"
struct Config
{
std::map<std::string, std::string> options;
Config()
{
using namespace nix;
/* Read hydra.conf. */
auto hydraConfigFile = getEnv("HYDRA_CONFIG");
if (pathExists(hydraConfigFile)) {
for (auto line : tokenizeString<Strings>(readFile(hydraConfigFile), "\n")) {
line = trim(string(line, 0, line.find('#')));
auto eq = line.find('=');
if (eq == std::string::npos) continue;
auto key = trim(std::string(line, 0, eq));
auto value = trim(std::string(line, eq + 1));
if (key == "") continue;
options[key] = value;
}
}
}
std::string getStrOption(const std::string & key, const std::string & def = "")
{
auto i = options.find(key);
return i == options.end() ? def : i->second;
}
uint64_t getIntOption(const std::string & key, uint64_t def = 0)
{
auto i = options.find(key);
return i == options.end() ? def : std::stoll(i->second);
}
bool getBoolOption(const std::string & key, bool def = false)
{
auto i = options.find(key);
return i == options.end() ? def : (i->second == "true" || i->second == "1");
}
};