diff options
author | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-16 18:22:21 +0100 |
---|---|---|
committer | Christian Mollekopf <chrigi_1@fastmail.fm> | 2016-02-17 09:16:02 +0100 |
commit | 166d864f5e55b146ad2eef8db59b4eaec38b41c0 (patch) | |
tree | b29430e40191ff9cbfa9ca22c9b01dd28e96401c /tests/pipelinebenchmark.cpp | |
parent | 101176cc504bbecf0eb36e04f250796030a10152 (diff) | |
download | sink-166d864f5e55b146ad2eef8db59b4eaec38b41c0.tar.gz sink-166d864f5e55b146ad2eef8db59b4eaec38b41c0.zip |
Pipeline benchmark
Diffstat (limited to 'tests/pipelinebenchmark.cpp')
-rw-r--r-- | tests/pipelinebenchmark.cpp | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/tests/pipelinebenchmark.cpp b/tests/pipelinebenchmark.cpp new file mode 100644 index 0000000..c0c5cb1 --- /dev/null +++ b/tests/pipelinebenchmark.cpp | |||
@@ -0,0 +1,151 @@ | |||
1 | /* | ||
2 | * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm> | ||
3 | * | ||
4 | * This library is free software; you can redistribute it and/or | ||
5 | * modify it under the terms of the GNU Lesser General Public | ||
6 | * License as published by the Free Software Foundation; either | ||
7 | * version 2.1 of the License, or (at your option) version 3, or any | ||
8 | * later version accepted by the membership of KDE e.V. (or its | ||
9 | * successor approved by the membership of KDE e.V.), which shall | ||
10 | * act as a proxy defined in Section 6 of version 3 of the license. | ||
11 | * | ||
12 | * This library is distributed in the hope that it will be useful, | ||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
15 | * Lesser General Public License for more details. | ||
16 | * | ||
17 | * You should have received a copy of the GNU Lesser General Public | ||
18 | * License along with this library. If not, see <http://www.gnu.org/licenses/>. | ||
19 | */ | ||
20 | #include <QtTest> | ||
21 | |||
22 | #include <QString> | ||
23 | |||
24 | #include "testimplementations.h" | ||
25 | |||
26 | #include <common/facade.h> | ||
27 | #include <common/domainadaptor.h> | ||
28 | #include <common/resultprovider.h> | ||
29 | #include <common/synclistresult.h> | ||
30 | #include <common/definitions.h> | ||
31 | #include <common/query.h> | ||
32 | #include <common/store.h> | ||
33 | #include <common/pipeline.h> | ||
34 | #include <common/index.h> | ||
35 | #include <common/indexupdater.h> | ||
36 | |||
37 | #include "hawd/dataset.h" | ||
38 | #include "hawd/formatter.h" | ||
39 | |||
40 | #include <iostream> | ||
41 | #include <math.h> | ||
42 | |||
43 | #include "mail_generated.h" | ||
44 | #include "createentity_generated.h" | ||
45 | #include "getrssusage.h" | ||
46 | |||
47 | // class IndexUpdater : public Sink::Preprocessor { | ||
48 | // public: | ||
49 | // void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
50 | // { | ||
51 | // for (int i = 0; i < 10; i++) { | ||
52 | // Index ridIndex(QString("index.index%1").arg(i).toLatin1(), transaction); | ||
53 | // ridIndex.add("foo", uid); | ||
54 | // } | ||
55 | // } | ||
56 | // | ||
57 | // void modifiedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
58 | // { | ||
59 | // } | ||
60 | // | ||
61 | // void deletedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
62 | // { | ||
63 | // } | ||
64 | // }; | ||
65 | // | ||
66 | |||
67 | /** | ||
68 | * Benchmark pipeline processing speed. | ||
69 | * | ||
70 | * This benchmark especially highlights: | ||
71 | * * Cost of an index in speed and size | ||
72 | */ | ||
73 | class PipelineBenchmark : public QObject | ||
74 | { | ||
75 | Q_OBJECT | ||
76 | |||
77 | QByteArray resourceIdentifier; | ||
78 | HAWD::State mHawdState; | ||
79 | |||
80 | void populateDatabase(int count, const QVector<Sink::Preprocessor*> &preprocessors) | ||
81 | { | ||
82 | TestResource::removeFromDisk(resourceIdentifier); | ||
83 | |||
84 | auto pipeline = QSharedPointer<Sink::Pipeline>::create(resourceIdentifier); | ||
85 | |||
86 | auto mailFactory = QSharedPointer<TestMailAdaptorFactory>::create(); | ||
87 | pipeline->setPreprocessors("mail", preprocessors); | ||
88 | pipeline->setAdaptorFactory("mail", mailFactory); | ||
89 | |||
90 | QTime time; | ||
91 | time.start(); | ||
92 | |||
93 | auto domainTypeAdaptorFactory = QSharedPointer<TestMailAdaptorFactory>::create(); | ||
94 | |||
95 | pipeline->startTransaction(); | ||
96 | const auto date = QDateTime::currentDateTimeUtc(); | ||
97 | for (int i = 0; i < count; i++) { | ||
98 | auto domainObject = Sink::ApplicationDomain::Mail::Ptr::create(); | ||
99 | domainObject->setProperty("uid", "uid"); | ||
100 | domainObject->setProperty("subject", QString("subject%1").arg(i)); | ||
101 | domainObject->setProperty("date", date.addSecs(count)); | ||
102 | domainObject->setProperty("folder", "folder1"); | ||
103 | // domainObject->setProperty("attachment", attachment); | ||
104 | const auto command = createCommand<Sink::ApplicationDomain::Mail>(*domainObject, *domainTypeAdaptorFactory); | ||
105 | pipeline->newEntity(command.data(), command.size()); | ||
106 | } | ||
107 | pipeline->commit(); | ||
108 | auto appendTime = time.elapsed(); | ||
109 | |||
110 | auto allProcessedTime = time.elapsed(); | ||
111 | |||
112 | // Print memory layout, RSS is what is in memory | ||
113 | // std::system("exec pmap -x \"$PPID\""); | ||
114 | // | ||
115 | std::cout << "Size: " << Sink::Storage(Sink::storageLocation(), resourceIdentifier, Sink::Storage::ReadOnly).diskUsage()/1024 << " [kb]" << std::endl; | ||
116 | std::cout << "Time: " << allProcessedTime << " [ms]" << std::endl; | ||
117 | |||
118 | HAWD::Dataset dataset("pipeline", mHawdState); | ||
119 | HAWD::Dataset::Row row = dataset.row(); | ||
120 | |||
121 | row.setValue("rows", count); | ||
122 | row.setValue("append", (qreal)count/appendTime); | ||
123 | row.setValue("total", (qreal)count/allProcessedTime); | ||
124 | dataset.insertRow(row); | ||
125 | HAWD::Formatter::print(dataset); | ||
126 | |||
127 | } | ||
128 | |||
129 | private Q_SLOTS: | ||
130 | |||
131 | void init() | ||
132 | { | ||
133 | Sink::Log::setDebugOutputLevel(Sink::Log::Warning); | ||
134 | resourceIdentifier = "org.kde.test.instance1"; | ||
135 | } | ||
136 | |||
137 | void testWithoutIndex() | ||
138 | { | ||
139 | populateDatabase(10000, QVector<Sink::Preprocessor*>()); | ||
140 | } | ||
141 | |||
142 | void testWithIndex() | ||
143 | { | ||
144 | auto indexer = QSharedPointer<DefaultIndexUpdater<Sink::ApplicationDomain::Mail> >::create(); | ||
145 | populateDatabase(10000, QVector<Sink::Preprocessor*>() << indexer.data()); | ||
146 | } | ||
147 | |||
148 | }; | ||
149 | |||
150 | QTEST_MAIN(PipelineBenchmark) | ||
151 | #include "pipelinebenchmark.moc" | ||