summaryrefslogtreecommitdiffstats
path: root/tests/databasepopulationandfacadequerybenchmark.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'tests/databasepopulationandfacadequerybenchmark.cpp')
-rw-r--r--tests/databasepopulationandfacadequerybenchmark.cpp61
1 files changed, 29 insertions, 32 deletions
diff --git a/tests/databasepopulationandfacadequerybenchmark.cpp b/tests/databasepopulationandfacadequerybenchmark.cpp
index 16537c0..4e886af 100644
--- a/tests/databasepopulationandfacadequerybenchmark.cpp
+++ b/tests/databasepopulationandfacadequerybenchmark.cpp
@@ -23,7 +23,7 @@
23 23
24/** 24/**
25 * Benchmark read performance of the facade implementation. 25 * Benchmark read performance of the facade implementation.
26 * 26 *
27 * The memory used should grow linearly with the number of retrieved entities. 27 * The memory used should grow linearly with the number of retrieved entities.
28 * The memory used should be independent from the database size, after accounting for the memory mapped db. 28 * The memory used should be independent from the database size, after accounting for the memory mapped db.
29 */ 29 */
@@ -39,7 +39,7 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
39 void populateDatabase(int count) 39 void populateDatabase(int count)
40 { 40 {
41 Sink::Storage(Sink::storageLocation(), "identifier", Sink::Storage::ReadWrite).removeFromDisk(); 41 Sink::Storage(Sink::storageLocation(), "identifier", Sink::Storage::ReadWrite).removeFromDisk();
42 //Setup 42 // Setup
43 auto domainTypeAdaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create(); 43 auto domainTypeAdaptorFactory = QSharedPointer<TestEventAdaptorFactory>::create();
44 { 44 {
45 Sink::Storage storage(Sink::storageLocation(), identifier, Sink::Storage::ReadWrite); 45 Sink::Storage storage(Sink::storageLocation(), identifier, Sink::Storage::ReadWrite);
@@ -57,7 +57,7 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
57 domainObject->setProperty("attachment", attachment); 57 domainObject->setProperty("attachment", attachment);
58 flatbuffers::FlatBufferBuilder fbb; 58 flatbuffers::FlatBufferBuilder fbb;
59 domainTypeAdaptorFactory->createBuffer(*domainObject, fbb); 59 domainTypeAdaptorFactory->createBuffer(*domainObject, fbb);
60 const auto buffer = QByteArray::fromRawData(reinterpret_cast<const char*>(fbb.GetBufferPointer()), fbb.GetSize()); 60 const auto buffer = QByteArray::fromRawData(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize());
61 const auto key = QUuid::createUuid().toString().toLatin1(); 61 const auto key = QUuid::createUuid().toString().toLatin1();
62 db.write(key, buffer); 62 db.write(key, buffer);
63 bufferSizeTotal += buffer.size(); 63 bufferSizeTotal += buffer.size();
@@ -72,15 +72,15 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
72 auto size = db.getSize(); 72 auto size = db.getSize();
73 auto onDisk = storage.diskUsage(); 73 auto onDisk = storage.diskUsage();
74 auto writeAmplification = static_cast<double>(onDisk) / static_cast<double>(bufferSizeTotal); 74 auto writeAmplification = static_cast<double>(onDisk) / static_cast<double>(bufferSizeTotal);
75 std::cout << "Database size [kb]: " << size/1024 << std::endl; 75 std::cout << "Database size [kb]: " << size / 1024 << std::endl;
76 std::cout << "On disk [kb]: " << onDisk/1024 << std::endl; 76 std::cout << "On disk [kb]: " << onDisk / 1024 << std::endl;
77 std::cout << "Buffer size total [kb]: " << bufferSizeTotal/1024 << std::endl; 77 std::cout << "Buffer size total [kb]: " << bufferSizeTotal / 1024 << std::endl;
78 std::cout << "Key size total [kb]: " << keysSizeTotal/1024 << std::endl; 78 std::cout << "Key size total [kb]: " << keysSizeTotal / 1024 << std::endl;
79 std::cout << "Data size total [kb]: " << dataSizeTotal/1024 << std::endl; 79 std::cout << "Data size total [kb]: " << dataSizeTotal / 1024 << std::endl;
80 std::cout << "Write amplification: " << writeAmplification << std::endl; 80 std::cout << "Write amplification: " << writeAmplification << std::endl;
81 81
82 //The buffer has an overhead, but with a reasonable attachment size it should be relatively small 82 // The buffer has an overhead, but with a reasonable attachment size it should be relatively small
83 //A write amplification of 2 should be the worst case 83 // A write amplification of 2 should be the worst case
84 QVERIFY(writeAmplification < 2); 84 QVERIFY(writeAmplification < 2);
85 } 85 }
86 } 86 }
@@ -91,13 +91,14 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
91 91
92 Sink::Query query; 92 Sink::Query query;
93 query.liveQuery = false; 93 query.liveQuery = false;
94 query.requestedProperties << "uid" << "summary"; 94 query.requestedProperties << "uid"
95 << "summary";
95 96
96 //Benchmark 97 // Benchmark
97 QTime time; 98 QTime time;
98 time.start(); 99 time.start();
99 100
100 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr> >::create(); 101 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr>>::create();
101 auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); 102 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
102 TestResourceFacade facade(identifier, resourceAccess); 103 TestResourceFacade facade(identifier, resourceAccess);
103 104
@@ -105,13 +106,9 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
105 ret.first.exec().waitForFinished(); 106 ret.first.exec().waitForFinished();
106 auto emitter = ret.second; 107 auto emitter = ret.second;
107 QList<Sink::ApplicationDomain::Event::Ptr> list; 108 QList<Sink::ApplicationDomain::Event::Ptr> list;
108 emitter->onAdded([&list](const Sink::ApplicationDomain::Event::Ptr &event) { 109 emitter->onAdded([&list](const Sink::ApplicationDomain::Event::Ptr &event) { list << event; });
109 list << event;
110 });
111 bool done = false; 110 bool done = false;
112 emitter->onInitialResultSetComplete([&done](const Sink::ApplicationDomain::Event::Ptr &event) { 111 emitter->onInitialResultSetComplete([&done](const Sink::ApplicationDomain::Event::Ptr &event) { done = true; });
113 done = true;
114 });
115 emitter->fetch(Sink::ApplicationDomain::Event::Ptr()); 112 emitter->fetch(Sink::ApplicationDomain::Event::Ptr());
116 QTRY_VERIFY(done); 113 QTRY_VERIFY(done);
117 QCOMPARE(list.size(), count); 114 QCOMPARE(list.size(), count);
@@ -120,35 +117,35 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
120 117
121 const auto finalRss = getCurrentRSS(); 118 const auto finalRss = getCurrentRSS();
122 const auto rssGrowth = finalRss - startingRss; 119 const auto rssGrowth = finalRss - startingRss;
123 //Since the database is memory mapped it is attributted to the resident set size. 120 // Since the database is memory mapped it is attributted to the resident set size.
124 const auto rssWithoutDb = finalRss - Sink::Storage(Sink::storageLocation(), identifier, Sink::Storage::ReadWrite).diskUsage(); 121 const auto rssWithoutDb = finalRss - Sink::Storage(Sink::storageLocation(), identifier, Sink::Storage::ReadWrite).diskUsage();
125 const auto peakRss = getPeakRSS(); 122 const auto peakRss = getPeakRSS();
126 //How much peak deviates from final rss in percent (should be around 0) 123 // How much peak deviates from final rss in percent (should be around 0)
127 const auto percentageRssError = static_cast<double>(peakRss - finalRss)*100.0/static_cast<double>(finalRss); 124 const auto percentageRssError = static_cast<double>(peakRss - finalRss) * 100.0 / static_cast<double>(finalRss);
128 auto rssGrowthPerEntity = rssGrowth/count; 125 auto rssGrowthPerEntity = rssGrowth / count;
129 126
130 std::cout << "Loaded " << list.size() << " results." << std::endl; 127 std::cout << "Loaded " << list.size() << " results." << std::endl;
131 std::cout << "The query took [ms]: " << elapsed << std::endl; 128 std::cout << "The query took [ms]: " << elapsed << std::endl;
132 std::cout << "Current Rss usage [kb]: " << finalRss/1024 << std::endl; 129 std::cout << "Current Rss usage [kb]: " << finalRss / 1024 << std::endl;
133 std::cout << "Peak Rss usage [kb]: " << peakRss/1024 << std::endl; 130 std::cout << "Peak Rss usage [kb]: " << peakRss / 1024 << std::endl;
134 std::cout << "Rss growth [kb]: " << rssGrowth/1024 << std::endl; 131 std::cout << "Rss growth [kb]: " << rssGrowth / 1024 << std::endl;
135 std::cout << "Rss growth per entity [byte]: " << rssGrowthPerEntity << std::endl; 132 std::cout << "Rss growth per entity [byte]: " << rssGrowthPerEntity << std::endl;
136 std::cout << "Rss without db [kb]: " << rssWithoutDb/1024 << std::endl; 133 std::cout << "Rss without db [kb]: " << rssWithoutDb / 1024 << std::endl;
137 std::cout << "Percentage error: " << percentageRssError << std::endl; 134 std::cout << "Percentage error: " << percentageRssError << std::endl;
138 135
139 HAWD::Dataset dataset("facade_query", mHawdState); 136 HAWD::Dataset dataset("facade_query", mHawdState);
140 HAWD::Dataset::Row row = dataset.row(); 137 HAWD::Dataset::Row row = dataset.row();
141 row.setValue("rows", list.size()); 138 row.setValue("rows", list.size());
142 row.setValue("queryResultPerMs", (qreal)list.size()/elapsed); 139 row.setValue("queryResultPerMs", (qreal)list.size() / elapsed);
143 dataset.insertRow(row); 140 dataset.insertRow(row);
144 HAWD::Formatter::print(dataset); 141 HAWD::Formatter::print(dataset);
145 142
146 mTimePerEntity << static_cast<double>(elapsed)/static_cast<double>(count); 143 mTimePerEntity << static_cast<double>(elapsed) / static_cast<double>(count);
147 mRssGrowthPerEntity << rssGrowthPerEntity; 144 mRssGrowthPerEntity << rssGrowthPerEntity;
148 145
149 QVERIFY(percentageRssError < 10); 146 QVERIFY(percentageRssError < 10);
150 //TODO This is much more than it should it seems, although adding the attachment results in pretty exactly a 1k increase, 147 // TODO This is much more than it should it seems, although adding the attachment results in pretty exactly a 1k increase,
151 //so it doesn't look like that memory is being duplicated. 148 // so it doesn't look like that memory is being duplicated.
152 QVERIFY(rssGrowthPerEntity < 3300); 149 QVERIFY(rssGrowthPerEntity < 3300);
153 150
154 // Print memory layout, RSS is what is in memory 151 // Print memory layout, RSS is what is in memory