Cache .narinfo lookups
[?]
Feb 19, 2016, 3:19 PM
XLYHZUHTGM3HJBIINHPY4JLMENBFXPQEZYNEXENUOX3C47JLXJMACDependencies
- [2]
SOB276BAKeep some statistics for the binary cache stores - [3]
ENXUSMSVMake concurrency more robust - [4]
HPJKBFZ4Handle concurrent finishing of the same build - [5]
73YR46NJhydra-queue-runner: Write directly to a binary cache - [6]
MB3TISH2Rate-limit the number of threads copying closures at the same time - [7]
32HHP5CWhydra-queue-runner: Support generating a signed binary cache - [8]
N2NKSKHSRefactor local binary cache code into a subclass - [*]
GH4S4AWMRename file - [*]
EOO4EFWDUse a single BinaryCacheStore for all threads - [*]
24BMQDZAStart of single-process hydra-queue-runner
Change contents
- edit in src/hydra-queue-runner/binary-cache-store.cc at line 2
#include "sync.hh" - edit in src/hydra-queue-runner/binary-cache-store.cc at line 97
{auto state_(state.lock());auto res = state_->narInfoCache.get(storePath);if (res) {stats.narInfoReadAverted++;return **res;}} - replacement in src/hydra-queue-runner/binary-cache-store.cc at line 109
auto narInfo = NarInfo(getFile(narInfoFile), narInfoFile);assert(narInfo.path == storePath);auto narInfo = make_ref<NarInfo>(getFile(narInfoFile), narInfoFile);assert(narInfo->path == storePath); - replacement in src/hydra-queue-runner/binary-cache-store.cc at line 113
if (!narInfo.checkSignature(*publicKeys))if (!narInfo->checkSignature(*publicKeys)) - replacement in src/hydra-queue-runner/binary-cache-store.cc at line 117
return narInfo;{auto state_(state.lock());state_->narInfoCache.upsert(storePath, narInfo);stats.narInfoCacheSize = state_->narInfoCache.size();}return *narInfo; - edit in src/hydra-queue-runner/binary-cache-store.hh at line 5
#include "lru-cache.hh"#include "sync.hh" - edit in src/hydra-queue-runner/binary-cache-store.hh at line 28
struct State{LRUCache<Path, ref<NarInfo>> narInfoCache{32 * 1024};};Sync<State> state; - edit in src/hydra-queue-runner/binary-cache-store.hh at line 54
std::atomic<uint64_t> narInfoReadAverted{0}; - edit in src/hydra-queue-runner/binary-cache-store.hh at line 56
std::atomic<uint64_t> narInfoCacheSize{0}; - edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 594
nested.attr("narInfoReadAverted", stats.narInfoReadAverted); - edit in src/hydra-queue-runner/hydra-queue-runner.cc at line 596
nested.attr("narInfoCacheSize", stats.narInfoCacheSize); - file addition: lru-cache.hh[12.187]
#pragma once#include <map>#include <list>/* A simple least-recently used cache. Not thread-safe. */template<typename Key, typename Value>class LRUCache{private:size_t maxSize;// Stupid wrapper to get around circular dependency between Data// and LRU.struct LRUIterator;using Data = std::map<Key, std::pair<LRUIterator, Value>>;using LRU = std::list<typename Data::iterator>;struct LRUIterator { typename LRU::iterator it; };Data data;LRU lru;public:LRUCache(size_t maxSize) : maxSize(maxSize) { }/* Insert or upsert an item in the cache. */void upsert(const Key & key, const Value & value){erase(key);if (data.size() >= maxSize) {/* Retire the oldest item. */auto oldest = lru.begin();data.erase(*oldest);lru.erase(oldest);}auto res = data.emplace(key, std::make_pair(LRUIterator(), value));assert(res.second);auto & i(res.first);auto j = lru.insert(lru.end(), i);i->second.first.it = j;}bool erase(const Key & key){auto i = data.find(key);if (i == data.end()) return false;lru.erase(i->second.first.it);data.erase(i);return true;}/* Look up an item in the cache. If it's exists, it becomes themost recently used item. */// FIXME: use boost::optional?Value * get(const Key & key){auto i = data.find(key);if (i == data.end()) return 0;/* Move this item to the back of the LRU list. */lru.erase(i->second.first.it);auto j = lru.insert(lru.end(), i);i->second.first.it = j;return &i->second.second;}size_t size(){return data.size();}}; - replacement in src/hydra-queue-runner/sync.hh at line 23
template <class T>template<class T>