summaryrefslogtreecommitdiffstats
path: root/searchlib
diff options
context:
space:
mode:
authorHenning Baldersheim <balder@yahoo-inc.com>2023-03-14 15:57:32 +0100
committerGitHub <noreply@github.com>2023-03-14 15:57:32 +0100
commit4f53639e4c262a9806d05b24114aee40b1f9336b (patch)
tree5e16dbfc400849f83e3b3189a868cc771cd30cbb /searchlib
parent12a906cd6d29c637cbbada5a881a3636a27885e0 (diff)
parent880d37d8adbd904c2701a8ce35fd4fb9e60da946 (diff)
Merge pull request #26433 from vespa-engine/balder/also-consider-static-cost-of-caches
Balder/also consider static cost of caches
Diffstat (limited to 'searchlib')
-rw-r--r--searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp33
-rw-r--r--searchlib/src/vespa/searchlib/docstore/documentstore.cpp5
-rw-r--r--searchlib/src/vespa/searchlib/docstore/visitcache.cpp18
-rw-r--r--searchlib/src/vespa/searchlib/docstore/visitcache.h4
4 files changed, 46 insertions, 14 deletions
diff --git a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp
index 258b4d6518a..eec49043282 100644
--- a/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp
+++ b/searchlib/src/tests/docstore/logdatastore/logdatastore_test.cpp
@@ -497,20 +497,20 @@ private:
}
bool allowVisitCaching() const override { return _allowVisitCaching; }
private:
- VisitCacheStore &_vcs;
- vespalib::hash_set<uint32_t> _expected;
- vespalib::hash_set<uint32_t> _actual;
- bool _allowVisitCaching;
+ VisitCacheStore &_vcs;
+ vespalib::hash_set<uint32_t> _expected;
+ vespalib::hash_set<uint32_t> _actual;
+ bool _allowVisitCaching;
};
- DirectoryHandler _myDir;
- document::DocumentTypeRepo _repo;
- LogDocumentStore::Config _config;
- DummyFileHeaderContext _fileHeaderContext;
- vespalib::ThreadStackExecutor _executor;
- MyTlSyncer _tlSyncer;
+ DirectoryHandler _myDir;
+ document::DocumentTypeRepo _repo;
+ LogDocumentStore::Config _config;
+ DummyFileHeaderContext _fileHeaderContext;
+ vespalib::ThreadStackExecutor _executor;
+ MyTlSyncer _tlSyncer;
std::unique_ptr<LogDocumentStore> _datastore;
- std::map<uint32_t, Document::UP> _inserted;
- SerialNum _serial;
+ std::map<uint32_t, Document::UP> _inserted;
+ SerialNum _serial;
};
VisitCacheStore::VerifyVisitor::VerifyVisitor(VisitCacheStore & vcs, std::vector<uint32_t> lids, bool allowCaching)
@@ -560,6 +560,15 @@ verifyCacheStats(CacheStats cs, size_t hits, size_t misses, size_t elements, siz
EXPECT_GREATER_EQUAL(memory_used+20, cs.memory_used);
}
+TEST("Control static memory usage") {
+ VisitCacheStore vcs(DocumentStore::Config::UpdateStrategy::UPDATE);
+ IDocumentStore &ds = vcs.getStore();
+ vespalib::MemoryUsage usage = ds.getMemoryUsage();
+ constexpr size_t mutex_size = sizeof(std::mutex) * 2 * (113 + 1); // sizeof(std::mutex) is platform dependent
+ EXPECT_EQUAL(74580 + mutex_size, usage.allocatedBytes());
+ EXPECT_EQUAL(952u + mutex_size, usage.usedBytes());
+}
+
TEST("test the update cache strategy") {
VisitCacheStore vcs(DocumentStore::Config::UpdateStrategy::UPDATE);
IDocumentStore & ds = vcs.getStore();
diff --git a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp
index 1e04b7c61db..368dd31678d 100644
--- a/searchlib/src/vespa/searchlib/docstore/documentstore.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/documentstore.cpp
@@ -428,7 +428,10 @@ DocumentStore::getStorageStats() const
vespalib::MemoryUsage
DocumentStore::getMemoryUsage() const
{
- return _backingStore.getMemoryUsage();
+ vespalib::MemoryUsage usage = _backingStore.getMemoryUsage();
+ usage.merge(_cache->getStaticMemoryUsage());
+ usage.merge(_visitCache->getStaticMemoryUsage());
+ return usage;
}
std::vector<DataStoreFileChunkStats>
diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
index 60c08c281df..c99bb50d4f8 100644
--- a/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
+++ b/searchlib/src/vespa/searchlib/docstore/visitcache.cpp
@@ -259,4 +259,22 @@ VisitCache::Cache::onRemove(const K & key) {
_id2KeySet.erase(key.getKeys().front());
}
+vespalib::MemoryUsage
+VisitCache::Cache::getStaticMemoryUsage() const {
+ vespalib::MemoryUsage usage = Parent::getStaticMemoryUsage();
+ auto cacheGuard = getGuard();
+ size_t baseSelf = sizeof(_lid2Id) + sizeof(_id2KeySet);
+ usage.incAllocatedBytes(baseSelf);
+ usage.incAllocatedBytes(_lid2Id.capacity() * sizeof(LidUniqueKeySetId::value_type));
+ usage.incAllocatedBytes(_id2KeySet.capacity() * sizeof(IdKeySetMap::value_type));
+ usage.incUsedBytes(baseSelf);
+ usage.incUsedBytes(_lid2Id.size() * sizeof(LidUniqueKeySetId::value_type));
+ usage.incUsedBytes(_id2KeySet.size() * sizeof(IdKeySetMap::value_type));
+ for (const auto & entry: _id2KeySet) {
+ usage.incAllocatedBytes(entry.second.getKeys().capacity() * sizeof(uint32_t));
+ usage.incUsedBytes(entry.second.getKeys().size() * sizeof(uint32_t));
+ }
+ return usage;
+}
+
}
diff --git a/searchlib/src/vespa/searchlib/docstore/visitcache.h b/searchlib/src/vespa/searchlib/docstore/visitcache.h
index 9a07c0ceab2..baa594b8d28 100644
--- a/searchlib/src/vespa/searchlib/docstore/visitcache.h
+++ b/searchlib/src/vespa/searchlib/docstore/visitcache.h
@@ -104,6 +104,7 @@ public:
void invalidate(uint32_t key) { remove(key); }
vespalib::CacheStats getCacheStats() const;
+ vespalib::MemoryUsage getStaticMemoryUsage() const { return _cache->getStaticMemoryUsage(); }
void reconfigure(size_t cacheSize, CompressionConfig compression);
private:
/**
@@ -144,9 +145,10 @@ private:
class Cache : public vespalib::cache<CacheParams> {
public:
Cache(BackingStore & b, size_t maxBytes);
- ~Cache();
+ ~Cache() override;
CompressedBlobSet readSet(const KeySet & keys);
void removeKey(uint32_t key);
+ vespalib::MemoryUsage getStaticMemoryUsage() const override;
private:
void locateAndInvalidateOtherSubsets(const UniqueLock & cacheGuard, const KeySet & keys);
using IdSet = vespalib::hash_set<uint64_t>;