summaryrefslogtreecommitdiffstats
path: root/tests/databasepopulationandfacadequerybenchmark.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-16 14:55:20 +0200
committerChristian Mollekopf <chrigi_1@fastmail.fm>2016-10-21 09:02:21 +0200
commit237b9ae4113e7a9f489632296941becb71afdb45 (patch)
tree01cde58f495944f01cad9d282391d4efd2897141 /tests/databasepopulationandfacadequerybenchmark.cpp
parent95d11bf0be98a4e3c08502fe23417b800233ce14 (diff)
downloadsink-237b9ae4113e7a9f489632296941becb71afdb45.tar.gz
sink-237b9ae4113e7a9f489632296941becb71afdb45.zip
Refactor how the storage is used.
This is the initial refactoring to improve how we deal with the storage. It does a couple of things: * Rename Sink::Storage to Sink::Storage::DataStore to free up the Sink::Storage namespace * Introduce a Sink::ResourceContext to have a single object that can be passed around containing everything that is necessary to operate on a resource. This is a lot better than the multiple separate parameters that we used to pass around all over the place, while still allowing for dependency injection for tests. * Tie storage access together using the new EntityStore that directly works with ApplicationDomainTypes. This gives us a central place where main storage, indexes and buffer adaptors are tied together, which will also give us a place to implement external indexes, such as a fulltextindex using xapian. * Use ApplicationDomainTypes as the default way to pass around entities. Instead of using various ways to pass around entities (buffers, buffer adaptors, ApplicationDomainTypes), only use a single way. The old approach was confusing, and was only done as: * optimization; really shouldn't be necessary and otherwise I'm sure we can find better ways to optimize ApplicationDomainType itself. * a way to account for entities that have multiple buffers, a concept that I no longer deem relevant. While this commit does the bulk of the work to get there, the following commits will refactor more stuff to get things back to normal.
Diffstat (limited to 'tests/databasepopulationandfacadequerybenchmark.cpp')
-rw-r--r--tests/databasepopulationandfacadequerybenchmark.cpp22
1 files changed, 13 insertions, 9 deletions
diff --git a/tests/databasepopulationandfacadequerybenchmark.cpp b/tests/databasepopulationandfacadequerybenchmark.cpp
index 5efe292..4e00bd4 100644
--- a/tests/databasepopulationandfacadequerybenchmark.cpp
+++ b/tests/databasepopulationandfacadequerybenchmark.cpp
@@ -38,13 +38,13 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
38 38
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::DataStore(Sink::storageLocation(), "identifier", Sink::Storage::DataStore::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::DataStore storage(Sink::storageLocation(), identifier, Sink::Storage::DataStore::ReadWrite);
46 auto transaction = storage.createTransaction(Sink::Storage::ReadWrite); 46 auto transaction = storage.createTransaction(Sink::Storage::DataStore::ReadWrite);
47 auto db = Sink::Storage::mainDatabase(transaction, "event"); 47 auto db = Sink::Storage::DataStore::mainDatabase(transaction, "event");
48 48
49 int bufferSizeTotal = 0; 49 int bufferSizeTotal = 0;
50 int keysSizeTotal = 0; 50 int keysSizeTotal = 0;
@@ -58,15 +58,15 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
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 = Sink::Storage::generateUid(); 61 const auto key = Sink::Storage::DataStore::generateUid();
62 db.write(key, buffer); 62 db.write(key, buffer);
63 bufferSizeTotal += buffer.size(); 63 bufferSizeTotal += buffer.size();
64 keysSizeTotal += key.size(); 64 keysSizeTotal += key.size();
65 } 65 }
66 transaction.commit(); 66 transaction.commit();
67 67
68 transaction = storage.createTransaction(Sink::Storage::ReadOnly); 68 transaction = storage.createTransaction(Sink::Storage::DataStore::ReadOnly);
69 db = Sink::Storage::mainDatabase(transaction, "event"); 69 db = Sink::Storage::DataStore::mainDatabase(transaction, "event");
70 70
71 auto dataSizeTotal = count * (QByteArray("uid").size() + QByteArray("summary").size() + attachment.size()); 71 auto dataSizeTotal = count * (QByteArray("uid").size() + QByteArray("summary").size() + attachment.size());
72 auto size = db.getSize(); 72 auto size = db.getSize();
@@ -100,7 +100,11 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
100 100
101 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr>>::create(); 101 auto resultSet = QSharedPointer<Sink::ResultProvider<Sink::ApplicationDomain::Event::Ptr>>::create();
102 auto resourceAccess = QSharedPointer<TestResourceAccess>::create(); 102 auto resourceAccess = QSharedPointer<TestResourceAccess>::create();
103 TestResourceFacade facade(identifier, resourceAccess); 103
104 QMap<QByteArray, DomainTypeAdaptorFactoryInterface::Ptr> factories;
105 Sink::ResourceContext context{identifier, "test", factories};
106 context.mResourceAccess = resourceAccess;
107 TestResourceFacade facade(context);
104 108
105 auto ret = facade.load(query); 109 auto ret = facade.load(query);
106 ret.first.exec().waitForFinished(); 110 ret.first.exec().waitForFinished();
@@ -118,7 +122,7 @@ class DatabasePopulationAndFacadeQueryBenchmark : public QObject
118 const auto finalRss = getCurrentRSS(); 122 const auto finalRss = getCurrentRSS();
119 const auto rssGrowth = finalRss - startingRss; 123 const auto rssGrowth = finalRss - startingRss;
120 // Since the database is memory mapped it is attributted to the resident set size. 124 // Since the database is memory mapped it is attributted to the resident set size.
121 const auto rssWithoutDb = finalRss - Sink::Storage(Sink::storageLocation(), identifier, Sink::Storage::ReadWrite).diskUsage(); 125 const auto rssWithoutDb = finalRss - Sink::Storage::DataStore(Sink::storageLocation(), identifier, Sink::Storage::DataStore::ReadWrite).diskUsage();
122 const auto peakRss = getPeakRSS(); 126 const auto peakRss = getPeakRSS();
123 // How much peak deviates from final rss in percent (should be around 0) 127 // How much peak deviates from final rss in percent (should be around 0)
124 const auto percentageRssError = static_cast<double>(peakRss - finalRss) * 100.0 / static_cast<double>(finalRss); 128 const auto percentageRssError = static_cast<double>(peakRss - finalRss) * 100.0 / static_cast<double>(finalRss);