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