diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-10-17 18:42:01 +0200 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2017-10-17 18:42:01 +0200 |
commit | 02a6f3a2c816bc4fb31a13b8f428c0525660438c (patch) | |
tree | 53b9cb25ac2cda050776b225c5a22a1d8541599f /tests | |
parent | 49fdda2bc452ea93ebfdb43798ee8f486eb3975f (diff) | |
download | sink-02a6f3a2c816bc4fb31a13b8f428c0525660438c.tar.gz sink-02a6f3a2c816bc4fb31a13b8f428c0525660438c.zip |
Initial query test
Diffstat (limited to 'tests')
-rw-r--r-- | tests/mailquerybenchmark.cpp | 86 |
1 files changed, 72 insertions, 14 deletions
diff --git a/tests/mailquerybenchmark.cpp b/tests/mailquerybenchmark.cpp index 4d67dca..1d295b5 100644 --- a/tests/mailquerybenchmark.cpp +++ b/tests/mailquerybenchmark.cpp | |||
@@ -27,6 +27,7 @@ | |||
27 | #include <common/definitions.h> | 27 | #include <common/definitions.h> |
28 | #include <common/query.h> | 28 | #include <common/query.h> |
29 | #include <common/storage/entitystore.h> | 29 | #include <common/storage/entitystore.h> |
30 | #include <common/resourcecontrol.h> | ||
30 | 31 | ||
31 | #include "hawd/dataset.h" | 32 | #include "hawd/dataset.h" |
32 | #include "hawd/formatter.h" | 33 | #include "hawd/formatter.h" |
@@ -81,15 +82,9 @@ class MailQueryBenchmark : public QObject | |||
81 | entityStore.commitTransaction(); | 82 | entityStore.commitTransaction(); |
82 | } | 83 | } |
83 | 84 | ||
84 | qreal testLoad(const Sink::Query &query, int count, int expectedSize) | 85 | //Execute query and block until the initial query is complete |
86 | int load(const Sink::Query &query) | ||
85 | { | 87 | { |
86 | const auto startingRss = getCurrentRSS(); | ||
87 | |||
88 | // Benchmark | ||
89 | QTime time; | ||
90 | time.start(); | ||
91 | |||
92 | //FIXME why do we need this here? | ||
93 | auto domainTypeAdaptorFactory = QSharedPointer<TestMailAdaptorFactory>::create(); | 88 | auto domainTypeAdaptorFactory = QSharedPointer<TestMailAdaptorFactory>::create(); |
94 | Sink::ResourceContext context{resourceIdentifier, "test", {{"mail", domainTypeAdaptorFactory}}}; | 89 | Sink::ResourceContext context{resourceIdentifier, "test", {{"mail", domainTypeAdaptorFactory}}}; |
95 | context.mResourceAccess = QSharedPointer<TestResourceAccess>::create(); | 90 | context.mResourceAccess = QSharedPointer<TestResourceAccess>::create(); |
@@ -98,13 +93,25 @@ class MailQueryBenchmark : public QObject | |||
98 | auto ret = facade.load(query, Sink::Log::Context{"benchmark"}); | 93 | auto ret = facade.load(query, Sink::Log::Context{"benchmark"}); |
99 | ret.first.exec().waitForFinished(); | 94 | ret.first.exec().waitForFinished(); |
100 | auto emitter = ret.second; | 95 | auto emitter = ret.second; |
101 | QList<Mail::Ptr> list; | 96 | int i = 0; |
102 | emitter->onAdded([&list](const Mail::Ptr &mail) { list << mail; }); | 97 | emitter->onAdded([&](const Mail::Ptr &) { i++; }); |
103 | bool done = false; | 98 | bool done = false; |
104 | emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); | 99 | emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); |
105 | emitter->fetch(Mail::Ptr()); | 100 | emitter->fetch(Mail::Ptr()); |
106 | QUICK_TRY_VERIFY(done); | 101 | QUICK_TRY_VERIFY(done); |
107 | Q_ASSERT(list.size() == expectedSize); | 102 | return i; |
103 | } | ||
104 | |||
105 | qreal testLoad(const Sink::Query &query, int count, int expectedSize) | ||
106 | { | ||
107 | const auto startingRss = getCurrentRSS(); | ||
108 | |||
109 | // Benchmark | ||
110 | QTime time; | ||
111 | time.start(); | ||
112 | |||
113 | auto loadedResults = load(query); | ||
114 | Q_ASSERT(loadedResults == expectedSize); | ||
108 | 115 | ||
109 | const auto elapsed = time.elapsed(); | 116 | const auto elapsed = time.elapsed(); |
110 | 117 | ||
@@ -117,7 +124,7 @@ class MailQueryBenchmark : public QObject | |||
117 | 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); |
118 | auto rssGrowthPerEntity = rssGrowth / count; | 125 | auto rssGrowthPerEntity = rssGrowth / count; |
119 | 126 | ||
120 | std::cout << "Loaded " << list.size() << " results." << std::endl; | 127 | std::cout << "Loaded " << expectedSize << " results." << std::endl; |
121 | std::cout << "The query took [ms]: " << elapsed << std::endl; | 128 | std::cout << "The query took [ms]: " << elapsed << std::endl; |
122 | std::cout << "Current Rss usage [kb]: " << finalRss / 1024 << std::endl; | 129 | std::cout << "Current Rss usage [kb]: " << finalRss / 1024 << std::endl; |
123 | std::cout << "Peak Rss usage [kb]: " << peakRss / 1024 << std::endl; | 130 | std::cout << "Peak Rss usage [kb]: " << peakRss / 1024 << std::endl; |
@@ -134,7 +141,7 @@ class MailQueryBenchmark : public QObject | |||
134 | // Print memory layout, RSS is what is in memory | 141 | // Print memory layout, RSS is what is in memory |
135 | // std::system("exec pmap -x \"$PPID\""); | 142 | // std::system("exec pmap -x \"$PPID\""); |
136 | // std::system("top -p \"$PPID\" -b -n 1"); | 143 | // std::system("top -p \"$PPID\" -b -n 1"); |
137 | return (qreal)list.size() / elapsed; | 144 | return (qreal)expectedSize / elapsed; |
138 | } | 145 | } |
139 | 146 | ||
140 | private slots: | 147 | private slots: |
@@ -144,6 +151,56 @@ private slots: | |||
144 | resourceIdentifier = "sink.test.instance1"; | 151 | resourceIdentifier = "sink.test.instance1"; |
145 | } | 152 | } |
146 | 153 | ||
154 | void testInitialQueryResult() | ||
155 | { | ||
156 | int count = 50000; | ||
157 | int limit = 1; | ||
158 | populateDatabase(count); | ||
159 | |||
160 | //Run a warm-up query first | ||
161 | Sink::Query query{}; | ||
162 | query.request<Mail::MessageId>() | ||
163 | .request<Mail::Subject>() | ||
164 | .request<Mail::Date>(); | ||
165 | query.sort<Mail::Date>(); | ||
166 | query.filter<Mail::Folder>("folder1"); | ||
167 | query.limit(limit); | ||
168 | |||
169 | load(query); | ||
170 | |||
171 | int liveQueryTime = 0; | ||
172 | { | ||
173 | VERIFYEXEC(Sink::ResourceControl::shutdown(resourceIdentifier)); | ||
174 | |||
175 | auto q = query; | ||
176 | q.setFlags(Sink::Query::LiveQuery); | ||
177 | |||
178 | QTime time; | ||
179 | time.start(); | ||
180 | load(q); | ||
181 | liveQueryTime = time.elapsed(); | ||
182 | } | ||
183 | |||
184 | int nonLiveQueryTime = 0; | ||
185 | { | ||
186 | VERIFYEXEC(Sink::ResourceControl::shutdown(resourceIdentifier)); | ||
187 | |||
188 | auto q = query; | ||
189 | |||
190 | QTime time; | ||
191 | time.start(); | ||
192 | load(q); | ||
193 | nonLiveQueryTime = time.elapsed(); | ||
194 | } | ||
195 | |||
196 | HAWD::Dataset dataset("mail_query_initial", mHawdState); | ||
197 | HAWD::Dataset::Row row = dataset.row(); | ||
198 | row.setValue("live", liveQueryTime); | ||
199 | row.setValue("nonlive", nonLiveQueryTime); | ||
200 | dataset.insertRow(row); | ||
201 | HAWD::Formatter::print(dataset); | ||
202 | } | ||
203 | |||
147 | void test50k() | 204 | void test50k() |
148 | { | 205 | { |
149 | int count = 50000; | 206 | int count = 50000; |
@@ -151,6 +208,7 @@ private slots: | |||
151 | qreal simpleResultRate = 0; | 208 | qreal simpleResultRate = 0; |
152 | qreal threadResultRate = 0; | 209 | qreal threadResultRate = 0; |
153 | { | 210 | { |
211 | //A query that just filters by a property and sorts (using an index) | ||
154 | Sink::Query query; | 212 | Sink::Query query; |
155 | query.request<Mail::MessageId>() | 213 | query.request<Mail::MessageId>() |
156 | .request<Mail::Subject>() | 214 | .request<Mail::Subject>() |
@@ -163,11 +221,11 @@ private slots: | |||
163 | simpleResultRate = testLoad(query, count, query.limit()); | 221 | simpleResultRate = testLoad(query, count, query.limit()); |
164 | } | 222 | } |
165 | { | 223 | { |
224 | //A query that reduces (like the maillist query) | ||
166 | Sink::Query query; | 225 | Sink::Query query; |
167 | query.request<Mail::MessageId>() | 226 | query.request<Mail::MessageId>() |
168 | .request<Mail::Subject>() | 227 | .request<Mail::Subject>() |
169 | .request<Mail::Date>(); | 228 | .request<Mail::Date>(); |
170 | // query.filter<ApplicationDomain::Mail::Trash>(false); | ||
171 | query.reduce<ApplicationDomain::Mail::Folder>(Query::Reduce::Selector::max<ApplicationDomain::Mail::Date>()); | 229 | query.reduce<ApplicationDomain::Mail::Folder>(Query::Reduce::Selector::max<ApplicationDomain::Mail::Date>()); |
172 | query.limit(limit); | 230 | query.limit(limit); |
173 | 231 | ||