diff options
Diffstat (limited to 'tests/genericresourcebenchmark.cpp')
-rw-r--r-- | tests/genericresourcebenchmark.cpp | 209 |
1 files changed, 0 insertions, 209 deletions
diff --git a/tests/genericresourcebenchmark.cpp b/tests/genericresourcebenchmark.cpp deleted file mode 100644 index 2315d0b..0000000 --- a/tests/genericresourcebenchmark.cpp +++ /dev/null | |||
@@ -1,209 +0,0 @@ | |||
1 | #include <QtTest> | ||
2 | |||
3 | #include <QString> | ||
4 | |||
5 | #include "testimplementations.h" | ||
6 | |||
7 | #include "event_generated.h" | ||
8 | #include "createentity_generated.h" | ||
9 | #include "commands.h" | ||
10 | #include "entitybuffer.h" | ||
11 | #include "pipeline.h" | ||
12 | #include "genericresource.h" | ||
13 | #include "definitions.h" | ||
14 | #include "domainadaptor.h" | ||
15 | #include "index.h" | ||
16 | |||
17 | #include "hawd/dataset.h" | ||
18 | #include "hawd/formatter.h" | ||
19 | |||
20 | |||
21 | static void removeFromDisk(const QString &name) | ||
22 | { | ||
23 | Sink::Storage store(Sink::storageLocation(), name, Sink::Storage::ReadWrite); | ||
24 | store.removeFromDisk(); | ||
25 | } | ||
26 | |||
27 | static QByteArray createEntityBuffer() | ||
28 | { | ||
29 | flatbuffers::FlatBufferBuilder eventFbb; | ||
30 | eventFbb.Clear(); | ||
31 | { | ||
32 | auto summary = eventFbb.CreateString("summary"); | ||
33 | Sink::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb); | ||
34 | eventBuilder.add_summary(summary); | ||
35 | auto eventLocation = eventBuilder.Finish(); | ||
36 | Sink::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation); | ||
37 | } | ||
38 | |||
39 | flatbuffers::FlatBufferBuilder localFbb; | ||
40 | { | ||
41 | auto uid = localFbb.CreateString("testuid"); | ||
42 | auto localBuilder = Sink::ApplicationDomain::Buffer::EventBuilder(localFbb); | ||
43 | localBuilder.add_uid(uid); | ||
44 | auto location = localBuilder.Finish(); | ||
45 | Sink::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location); | ||
46 | } | ||
47 | |||
48 | flatbuffers::FlatBufferBuilder entityFbb; | ||
49 | Sink::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize()); | ||
50 | |||
51 | flatbuffers::FlatBufferBuilder fbb; | ||
52 | auto type = fbb.CreateString(Sink::ApplicationDomain::getTypeName<Sink::ApplicationDomain::Event>().toStdString().data()); | ||
53 | auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
54 | Sink::Commands::CreateEntityBuilder builder(fbb); | ||
55 | builder.add_domainType(type); | ||
56 | builder.add_delta(delta); | ||
57 | auto location = builder.Finish(); | ||
58 | Sink::Commands::FinishCreateEntityBuffer(fbb, location); | ||
59 | |||
60 | return QByteArray(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | ||
61 | } | ||
62 | |||
63 | class IndexUpdater : public Sink::Preprocessor | ||
64 | { | ||
65 | public: | ||
66 | void newEntity(const QByteArray &uid, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &newEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
67 | { | ||
68 | for (int i = 0; i < 10; i++) { | ||
69 | Index ridIndex(QString("index.index%1").arg(i).toLatin1(), transaction); | ||
70 | ridIndex.add("foo", uid); | ||
71 | } | ||
72 | } | ||
73 | |||
74 | void modifiedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, const Sink::ApplicationDomain::BufferAdaptor &newEntity, | ||
75 | Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
76 | { | ||
77 | } | ||
78 | |||
79 | void deletedEntity(const QByteArray &key, qint64 revision, const Sink::ApplicationDomain::BufferAdaptor &oldEntity, Sink::Storage::Transaction &transaction) Q_DECL_OVERRIDE | ||
80 | { | ||
81 | } | ||
82 | }; | ||
83 | |||
84 | /** | ||
85 | * Benchmark write performance of generic resource implementation including queues and pipeline. | ||
86 | */ | ||
87 | class GenericResourceBenchmark : public QObject | ||
88 | { | ||
89 | Q_OBJECT | ||
90 | private slots: | ||
91 | |||
92 | void init() | ||
93 | { | ||
94 | Sink::Log::setDebugOutputLevel(Sink::Log::Warning); | ||
95 | } | ||
96 | |||
97 | void initTestCase() | ||
98 | { | ||
99 | removeFromDisk("sink.test.instance1"); | ||
100 | removeFromDisk("sink.test.instance1.userqueue"); | ||
101 | removeFromDisk("sink.test.instance1.synchronizerqueue"); | ||
102 | } | ||
103 | |||
104 | |||
105 | void testWriteInProcess() | ||
106 | { | ||
107 | int num = 10000; | ||
108 | |||
109 | auto pipeline = QSharedPointer<Sink::Pipeline>::create("sink.test.instance1"); | ||
110 | TestResource resource("sink.test.instance1", pipeline); | ||
111 | |||
112 | auto command = createEntityBuffer(); | ||
113 | |||
114 | QTime time; | ||
115 | time.start(); | ||
116 | |||
117 | for (int i = 0; i < num; i++) { | ||
118 | resource.processCommand(Sink::Commands::CreateEntityCommand, command); | ||
119 | } | ||
120 | auto appendTime = time.elapsed(); | ||
121 | |||
122 | // Wait until all messages have been processed | ||
123 | resource.processAllMessages().exec().waitForFinished(); | ||
124 | |||
125 | auto allProcessedTime = time.elapsed(); | ||
126 | |||
127 | // Print memory layout, RSS is what is in memory | ||
128 | // std::system("exec pmap -x \"$PPID\""); | ||
129 | |||
130 | HAWD::Dataset dataset("generic_write_in_process", m_hawdState); | ||
131 | HAWD::Dataset::Row row = dataset.row(); | ||
132 | |||
133 | row.setValue("rows", num); | ||
134 | row.setValue("append", (qreal)num / appendTime); | ||
135 | row.setValue("total", (qreal)num / allProcessedTime); | ||
136 | dataset.insertRow(row); | ||
137 | HAWD::Formatter::print(dataset); | ||
138 | } | ||
139 | |||
140 | void testWriteInProcessWithIndex() | ||
141 | { | ||
142 | int num = 50000; | ||
143 | |||
144 | auto pipeline = QSharedPointer<Sink::Pipeline>::create("sink.test.instance1"); | ||
145 | |||
146 | auto eventFactory = QSharedPointer<TestEventAdaptorFactory>::create(); | ||
147 | const QByteArray resourceIdentifier = "sink.test.instance1"; | ||
148 | auto indexer = QSharedPointer<IndexUpdater>::create(); | ||
149 | |||
150 | pipeline->setPreprocessors("event", QVector<Sink::Preprocessor *>() << indexer.data()); | ||
151 | pipeline->setAdaptorFactory("event", eventFactory); | ||
152 | |||
153 | TestResource resource("sink.test.instance1", pipeline); | ||
154 | |||
155 | auto command = createEntityBuffer(); | ||
156 | |||
157 | QTime time; | ||
158 | time.start(); | ||
159 | |||
160 | for (int i = 0; i < num; i++) { | ||
161 | resource.processCommand(Sink::Commands::CreateEntityCommand, command); | ||
162 | } | ||
163 | auto appendTime = time.elapsed(); | ||
164 | |||
165 | // Wait until all messages have been processed | ||
166 | resource.processAllMessages().exec().waitForFinished(); | ||
167 | |||
168 | auto allProcessedTime = time.elapsed(); | ||
169 | |||
170 | // Print memory layout, RSS is what is in memory | ||
171 | // std::system("exec pmap -x \"$PPID\""); | ||
172 | |||
173 | HAWD::Dataset dataset("generic_write_in_process_with_indexes", m_hawdState); | ||
174 | HAWD::Dataset::Row row = dataset.row(); | ||
175 | |||
176 | row.setValue("rows", num); | ||
177 | row.setValue("append", (qreal)num / appendTime); | ||
178 | row.setValue("total", (qreal)num / allProcessedTime); | ||
179 | dataset.insertRow(row); | ||
180 | HAWD::Formatter::print(dataset); | ||
181 | } | ||
182 | |||
183 | void testCreateCommand() | ||
184 | { | ||
185 | Sink::ApplicationDomain::Event event; | ||
186 | |||
187 | QBENCHMARK { | ||
188 | auto mFactory = new TestEventAdaptorFactory; | ||
189 | static flatbuffers::FlatBufferBuilder entityFbb; | ||
190 | entityFbb.Clear(); | ||
191 | mFactory->createBuffer(event, entityFbb); | ||
192 | |||
193 | static flatbuffers::FlatBufferBuilder fbb; | ||
194 | fbb.Clear(); | ||
195 | // This is the resource buffer type and not the domain type | ||
196 | auto type = fbb.CreateString("event"); | ||
197 | // auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
198 | auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); | ||
199 | auto location = Sink::Commands::CreateCreateEntity(fbb, type, delta); | ||
200 | Sink::Commands::FinishCreateEntityBuffer(fbb, location); | ||
201 | } | ||
202 | } | ||
203 | |||
204 | private: | ||
205 | HAWD::State m_hawdState; | ||
206 | }; | ||
207 | |||
208 | QTEST_MAIN(GenericResourceBenchmark) | ||
209 | #include "genericresourcebenchmark.moc" | ||