diff options
author | Geir Storli <geirst@yahoo-inc.com> | 2016-12-15 15:01:38 +0100 |
---|---|---|
committer | Geir Storli <geirst@yahoo-inc.com> | 2016-12-15 15:01:38 +0100 |
commit | d5c4e1020920302f97a03f9eb313b60e9962e90c (patch) | |
tree | a0fd4cdd450bc0e8f0b2db87b8793641fdbca1f4 | |
parent | fe66f1be411e51a3f767d3db30eebfde458aeb94 (diff) |
Expose index memory usage metrics.
7 files changed, 53 insertions, 21 deletions
diff --git a/searchcore/src/vespa/searchcore/proton/index/memoryindexwrapper.h b/searchcore/src/vespa/searchcore/proton/index/memoryindexwrapper.h index a4ef714d09d..6521c98bcdb 100644 --- a/searchcore/src/vespa/searchcore/proton/index/memoryindexwrapper.h +++ b/searchcore/src/vespa/searchcore/proton/index/memoryindexwrapper.h @@ -51,7 +51,7 @@ public: } virtual search::SearchableStats getSearchableStats() const override { return search::SearchableStats() - .memoryUsage(getMemoryUsage().allocatedBytes()) + .memoryUsage(getMemoryUsage()) .docsInMemory(_index.getNumDocs()) .sizeOnDisk(0); } diff --git a/searchcore/src/vespa/searchcore/proton/metrics/documentdb_tagged_metrics.cpp b/searchcore/src/vespa/searchcore/proton/metrics/documentdb_tagged_metrics.cpp index 68580d90974..213c869a8e4 100644 --- a/searchcore/src/vespa/searchcore/proton/metrics/documentdb_tagged_metrics.cpp +++ b/searchcore/src/vespa/searchcore/proton/metrics/documentdb_tagged_metrics.cpp @@ -76,10 +76,17 @@ DocumentDBTaggedMetrics::AttributeMetrics::ResourceUsageMetrics::ResourceUsageMe { } +DocumentDBTaggedMetrics::IndexMetrics::IndexMetrics(MetricSet *parent) + : MetricSet("index", "", "Index metrics (memory and disk) for this document db", parent), + memoryUsage(this) +{ +} + DocumentDBTaggedMetrics::DocumentDBTaggedMetrics(const vespalib::string &docTypeName) : MetricSet("documentdb", {{"documenttype", docTypeName}}, "Document DB metrics", nullptr), job(this), attribute(this), + index(this), ready("ready", this), notReady("notready", this), removed("removed", this) diff --git a/searchcore/src/vespa/searchcore/proton/metrics/documentdb_tagged_metrics.h b/searchcore/src/vespa/searchcore/proton/metrics/documentdb_tagged_metrics.h index 39f4733f66c..323d0766e6f 100644 --- a/searchcore/src/vespa/searchcore/proton/metrics/documentdb_tagged_metrics.h +++ b/searchcore/src/vespa/searchcore/proton/metrics/documentdb_tagged_metrics.h @@ -76,8 +76,16 @@ struct DocumentDBTaggedMetrics : metrics::MetricSet AttributeMetrics(metrics::MetricSet *parent); }; + struct IndexMetrics : metrics::MetricSet + { + MemoryUsageMetrics memoryUsage; + + IndexMetrics(metrics::MetricSet *parent); + }; + JobMetrics job; AttributeMetrics attribute; + IndexMetrics index; SubDBMetrics ready; SubDBMetrics notReady; SubDBMetrics removed; diff --git a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp index b21d6c1eba8..46e01757088 100644 --- a/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp +++ b/searchcore/src/vespa/searchcore/proton/server/documentdb.cpp @@ -1245,12 +1245,16 @@ DocumentDB::getIndexManagerFactory(const vespalib::stringref &name) const namespace { void -updateIndexMetrics(LegacyDocumentDBMetrics::IndexMetrics &metrics, +updateIndexMetrics(DocumentDBMetricsCollection &metrics, const search::SearchableStats &stats) { - metrics.memoryUsage.set(stats.memoryUsage()); - metrics.docsInMemory.set(stats.docsInMemory()); - metrics.diskUsage.set(stats.sizeOnDisk()); + DocumentDBTaggedMetrics::IndexMetrics &indexMetrics = metrics.getTaggedMetrics().index; + indexMetrics.memoryUsage.update(stats.memoryUsage()); + + LegacyDocumentDBMetrics::IndexMetrics &legacyIndexMetrics = metrics.getMetrics().index; + legacyIndexMetrics.memoryUsage.set(stats.memoryUsage().allocatedBytes()); + legacyIndexMetrics.docsInMemory.set(stats.docsInMemory()); + legacyIndexMetrics.diskUsage.set(stats.sizeOnDisk()); } struct TempAttributeMetric @@ -1456,6 +1460,7 @@ void DocumentDB::updateMetrics(DocumentDBMetricsCollection &metrics) { updateLegacyMetrics(metrics.getMetrics()); + updateIndexMetrics(metrics, _subDBs.getReadySubDB()->getSearchableStats()); updateAttributeMetrics(metrics, _subDBs); updateMetrics(metrics.getTaggedMetrics()); } @@ -1463,8 +1468,6 @@ DocumentDB::updateMetrics(DocumentDBMetricsCollection &metrics) void DocumentDB::updateLegacyMetrics(LegacyDocumentDBMetrics &metrics) { - updateIndexMetrics(metrics.index, - _subDBs.getReadySubDB()->getSearchableStats()); updateMatchingMetrics(metrics.matching, *_subDBs.getReadySubDB()); metrics.executor.update(_writeService.getMasterExecutor().getStats()); metrics.indexExecutor.update(_writeService.getIndexExecutor().getStats()); diff --git a/searchcorespi/src/vespa/searchcorespi/index/index_manager_explorer.cpp b/searchcorespi/src/vespa/searchcorespi/index/index_manager_explorer.cpp index 959f5ccdc59..7920c1650cb 100644 --- a/searchcorespi/src/vespa/searchcorespi/index/index_manager_explorer.cpp +++ b/searchcorespi/src/vespa/searchcorespi/index/index_manager_explorer.cpp @@ -18,7 +18,8 @@ namespace searchcorespi { namespace { -void insertDiskIndex(Cursor &arrayCursor, const DiskIndexStats &diskIndex) +void +insertDiskIndex(Cursor &arrayCursor, const DiskIndexStats &diskIndex) { Cursor &diskIndexCursor = arrayCursor.addObject(); const SearchableStats &sstats = diskIndex.getSearchableStats(); @@ -27,13 +28,24 @@ void insertDiskIndex(Cursor &arrayCursor, const DiskIndexStats &diskIndex) diskIndexCursor.setLong("sizeOnDisk", sstats.sizeOnDisk()); } -void insertMemoryIndex(Cursor &arrayCursor, const MemoryIndexStats &memoryIndex) +void +insertMemoryUsage(Cursor &object, const search::MemoryUsage &usage) +{ + Cursor &memory = object.setObject("memoryUsage"); + memory.setLong("allocatedBytes", usage.allocatedBytes()); + memory.setLong("usedBytes", usage.usedBytes()); + memory.setLong("deadBytes", usage.deadBytes()); + memory.setLong("onHoldBytes", usage.allocatedBytesOnHold()); +} + +void +insertMemoryIndex(Cursor &arrayCursor, const MemoryIndexStats &memoryIndex) { Cursor &memoryIndexCursor = arrayCursor.addObject(); const SearchableStats &sstats = memoryIndex.getSearchableStats(); memoryIndexCursor.setLong("serialNum", memoryIndex.getSerialNum()); memoryIndexCursor.setLong("docsInMemory", sstats.docsInMemory()); - memoryIndexCursor.setLong("memoryUsage", sstats.memoryUsage()); + insertMemoryUsage(memoryIndexCursor, sstats.memoryUsage()); } } diff --git a/searchlib/src/tests/util/searchable_stats/searchable_stats_test.cpp b/searchlib/src/tests/util/searchable_stats/searchable_stats_test.cpp index 83aba794824..d5c77fb28e4 100644 --- a/searchlib/src/tests/util/searchable_stats/searchable_stats_test.cpp +++ b/searchlib/src/tests/util/searchable_stats/searchable_stats_test.cpp @@ -18,21 +18,21 @@ Test::Main() TEST_INIT("searchable_stats_test"); { SearchableStats stats; - EXPECT_EQUAL(0u, stats.memoryUsage()); + EXPECT_EQUAL(0u, stats.memoryUsage().allocatedBytes()); EXPECT_EQUAL(0u, stats.docsInMemory()); EXPECT_EQUAL(0u, stats.sizeOnDisk()); { SearchableStats rhs; - EXPECT_EQUAL(&rhs.memoryUsage(100), &rhs); + EXPECT_EQUAL(&rhs.memoryUsage(MemoryUsage(100,0,0,0)), &rhs); EXPECT_EQUAL(&rhs.docsInMemory(10), &rhs); EXPECT_EQUAL(&rhs.sizeOnDisk(1000), &rhs); EXPECT_EQUAL(&stats.add(rhs), &stats); } - EXPECT_EQUAL(100u, stats.memoryUsage()); + EXPECT_EQUAL(100u, stats.memoryUsage().allocatedBytes()); EXPECT_EQUAL(10u, stats.docsInMemory()); EXPECT_EQUAL(1000u, stats.sizeOnDisk()); - EXPECT_EQUAL(&stats.add(SearchableStats().memoryUsage(100).docsInMemory(10).sizeOnDisk(1000)), &stats); - EXPECT_EQUAL(200u, stats.memoryUsage()); + EXPECT_EQUAL(&stats.add(SearchableStats().memoryUsage(MemoryUsage(100,0,0,0)).docsInMemory(10).sizeOnDisk(1000)), &stats); + EXPECT_EQUAL(200u, stats.memoryUsage().allocatedBytes()); EXPECT_EQUAL(20u, stats.docsInMemory()); EXPECT_EQUAL(2000u, stats.sizeOnDisk()); } diff --git a/searchlib/src/vespa/searchlib/util/searchable_stats.h b/searchlib/src/vespa/searchlib/util/searchable_stats.h index a7d5764de7c..a87c15990f0 100644 --- a/searchlib/src/vespa/searchlib/util/searchable_stats.h +++ b/searchlib/src/vespa/searchlib/util/searchable_stats.h @@ -1,6 +1,8 @@ // Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root. #pragma once +#include "memoryusage.h" + namespace search { /** @@ -11,17 +13,17 @@ namespace search { class SearchableStats { private: - size_t _memoryUsage; + MemoryUsage _memoryUsage; size_t _docsInMemory; size_t _sizeOnDisk; public: - SearchableStats() : _memoryUsage(0), _docsInMemory(0), _sizeOnDisk(0) {} - SearchableStats &memoryUsage(size_t value) { - _memoryUsage = value; + SearchableStats() : _memoryUsage(), _docsInMemory(0), _sizeOnDisk(0) {} + SearchableStats &memoryUsage(const MemoryUsage &usage) { + _memoryUsage = usage; return *this; } - size_t memoryUsage() const { return _memoryUsage; } + const MemoryUsage &memoryUsage() const { return _memoryUsage; } SearchableStats &docsInMemory(size_t value) { _docsInMemory = value; return *this; @@ -33,7 +35,7 @@ public: } size_t sizeOnDisk() const { return _sizeOnDisk; } SearchableStats &add(const SearchableStats &rhs) { - _memoryUsage += rhs._memoryUsage; + _memoryUsage.merge(rhs._memoryUsage); _docsInMemory += rhs._docsInMemory; _sizeOnDisk += rhs._sizeOnDisk; return *this; |