summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests')
-rw-r--r--tests/dummyresourcewritebenchmark.cpp93
1 files changed, 90 insertions, 3 deletions
diff --git a/tests/dummyresourcewritebenchmark.cpp b/tests/dummyresourcewritebenchmark.cpp
index 87bb57a..07f57f6 100644
--- a/tests/dummyresourcewritebenchmark.cpp
+++ b/tests/dummyresourcewritebenchmark.cpp
@@ -27,16 +27,21 @@
27#include "getrssusage.h" 27#include "getrssusage.h"
28#include "utils.h" 28#include "utils.h"
29 29
30static QByteArray createEntityBuffer(int &bufferSize) 30static QByteArray createEntityBuffer(size_t attachmentSize, int &bufferSize)
31{ 31{
32 uint8_t rawData[attachmentSize];
32 flatbuffers::FlatBufferBuilder eventFbb; 33 flatbuffers::FlatBufferBuilder eventFbb;
33 eventFbb.Clear(); 34 eventFbb.Clear();
34 { 35 {
36 uint8_t *rawDataPtr = Q_NULLPTR;
37 auto data = eventFbb.CreateUninitializedVector<uint8_t>(attachmentSize, &rawDataPtr);
35 auto summary = eventFbb.CreateString("summary"); 38 auto summary = eventFbb.CreateString("summary");
36 Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); 39 Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb);
37 eventBuilder.add_summary(summary); 40 eventBuilder.add_summary(summary);
41 eventBuilder.add_attachment(data);
38 auto eventLocation = eventBuilder.Finish(); 42 auto eventLocation = eventBuilder.Finish();
39 Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); 43 Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation);
44 memcpy((void *)rawDataPtr, rawData, attachmentSize);
40 } 45 }
41 46
42 flatbuffers::FlatBufferBuilder localFbb; 47 flatbuffers::FlatBufferBuilder localFbb;
@@ -84,7 +89,7 @@ class DummyResourceWriteBenchmark : public QObject
84 DummyResource resource(Sink::ResourceContext{"sink.dummy.instance1", "sink.dummy", Sink::AdaptorFactoryRegistry::instance().getFactories("sink.dummy")}); 89 DummyResource resource(Sink::ResourceContext{"sink.dummy.instance1", "sink.dummy", Sink::AdaptorFactoryRegistry::instance().getFactories("sink.dummy")});
85 90
86 int bufferSize = 0; 91 int bufferSize = 0;
87 auto command = createEntityBuffer(bufferSize); 92 auto command = createEntityBuffer(0, bufferSize);
88 93
89 const auto startingRss = getCurrentRSS(); 94 const auto startingRss = getCurrentRSS();
90 for (int i = 0; i < num; i++) { 95 for (int i = 0; i < num; i++) {
@@ -114,7 +119,7 @@ class DummyResourceWriteBenchmark : public QObject
114 std::cout << "Rss without db [kb]: " << rssWithoutDb / 1024 << std::endl; 119 std::cout << "Rss without db [kb]: " << rssWithoutDb / 1024 << std::endl;
115 std::cout << "Percentage peak rss error: " << percentageRssError << std::endl; 120 std::cout << "Percentage peak rss error: " << percentageRssError << std::endl;
116 121
117 auto onDisk = DummyResource::diskUsage("sink.dummy.instance1"); 122 auto onDisk = Sink::Storage::DataStore(Sink::storageLocation(), "sink.dummy.instance1", Sink::Storage::DataStore::ReadOnly).diskUsage();
118 auto writeAmplification = static_cast<double>(onDisk) / static_cast<double>(bufferSizeTotal); 123 auto writeAmplification = static_cast<double>(onDisk) / static_cast<double>(bufferSizeTotal);
119 std::cout << "On disk [kb]: " << onDisk / 1024 << std::endl; 124 std::cout << "On disk [kb]: " << onDisk / 1024 << std::endl;
120 std::cout << "Buffer size total [kb]: " << bufferSizeTotal / 1024 << std::endl; 125 std::cout << "Buffer size total [kb]: " << bufferSizeTotal / 1024 << std::endl;
@@ -165,6 +170,84 @@ class DummyResourceWriteBenchmark : public QObject
165 // std::system("exec pmap -x \"$PPID\""); 170 // std::system("exec pmap -x \"$PPID\"");
166 } 171 }
167 172
173 void testDiskUsage(int num)
174 {
175 auto resourceId = "testDiskUsage";
176 DummyResource::removeFromDisk(resourceId);
177
178 {
179 DummyResource resource(Sink::ResourceContext{resourceId, "sink.dummy", Sink::AdaptorFactoryRegistry::instance().getFactories("sink.dummy")});
180
181 int bufferSize = 0;
182 auto command = createEntityBuffer(1000, bufferSize);
183
184 for (int i = 0; i < num; i++) {
185 resource.processCommand(Sink::Commands::CreateEntityCommand, command);
186 }
187
188 // Wait until all messages have been processed
189 resource.processAllMessages().exec().waitForFinished();
190 }
191
192 qint64 totalDbSizes = 0;
193 qint64 totalKeysAndValues = 0;
194 QMap<QByteArray, qint64> dbSizes;
195 Sink::Storage::DataStore storage(Sink::storageLocation(), resourceId, Sink::Storage::DataStore::ReadOnly);
196 auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly);
197 auto stat = transaction.stat();
198
199 std::cout << "Free pages: " << stat.freePages << std::endl;
200 std::cout << "Total pages: " << stat.totalPages << std::endl;
201 auto totalUsedSize = stat.pageSize * (stat.totalPages - stat.freePages);
202 std::cout << "Used size: " << totalUsedSize << std::endl;
203
204 auto freeDbSize = stat.pageSize * (stat.freeDbStat.leafPages + stat.freeDbStat.overflowPages + stat.freeDbStat.branchPages);
205 std::cout << "Free db size: " << freeDbSize << std::endl;
206 auto mainDbSize = stat.pageSize * (stat.mainDbStat.leafPages + stat.mainDbStat.overflowPages + stat.mainDbStat.branchPages);
207 std::cout << "Main db size: " << mainDbSize << std::endl;
208
209 totalDbSizes += mainDbSize;
210 QList<QByteArray> databases = transaction.getDatabaseNames();
211 for (const auto &databaseName : databases) {
212 auto db = transaction.openDatabase(databaseName);
213 const auto size = db.getSize();
214 dbSizes.insert(databaseName, size);
215 totalDbSizes += size;
216
217 qint64 keySizes = 0;
218 qint64 valueSizes = 0;
219 db.scan({}, [&] (const QByteArray &key, const QByteArray &data) {
220 keySizes += key.size();
221 valueSizes += data.size();
222 return true;
223 },
224 [&](const Sink::Storage::DataStore::Error &e) {
225 qWarning() << "Error while reading" << e;
226 },
227 false, false);
228
229 auto s = db.stat();
230 auto usedPages = (s.leafPages + s.branchPages + s.overflowPages);
231
232 std::cout << std::endl;
233 std::cout << "Db: " << databaseName.toStdString() << (db.allowsDuplicates() ? " DUP" : "") << std::endl;
234 std::cout << "Used pages " << usedPages << std::endl;
235 std::cout << "Used size " << (keySizes + valueSizes) / 4096.0 << std::endl;
236 std::cout << "Entries " << s.numEntries << std::endl;
237 totalKeysAndValues += (keySizes + valueSizes);
238 }
239 std::cout << std::endl;
240
241 auto mainStoreOnDisk = Sink::Storage::DataStore(Sink::storageLocation(), resourceId, Sink::Storage::DataStore::ReadOnly).diskUsage();
242 auto totalOnDisk = DummyResource::diskUsage(resourceId);
243 std::cout << "Calculated key + value size: " << totalKeysAndValues << std::endl;
244 std::cout << "Calculated total db sizes: " << totalDbSizes << std::endl;
245 std::cout << "Main store on disk: " << mainStoreOnDisk << std::endl;
246 std::cout << "Total on disk: " << totalOnDisk << std::endl;
247 std::cout << "Used size amplification: " << static_cast<double>(totalUsedSize) / static_cast<double>(totalKeysAndValues) << std::endl;
248 std::cout << "Write amplification: " << static_cast<double>(mainStoreOnDisk) / static_cast<double>(totalKeysAndValues) << std::endl;
249 std::cout << std::endl;
250 }
168 251
169private slots: 252private slots:
170 void initTestCase() 253 void initTestCase()
@@ -201,6 +284,10 @@ private slots:
201 HAWD::Formatter::print(dataset); 284 HAWD::Formatter::print(dataset);
202 } 285 }
203 286
287 void testDiskUsage()
288 {
289 testDiskUsage(1000);
290 }
204 291
205 // This allows to run individual parts without doing a cleanup, but still cleaning up normally 292 // This allows to run individual parts without doing a cleanup, but still cleaning up normally
206 void testCleanupForCompleteTest() 293 void testCleanupForCompleteTest()