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
|
#include <QtTest>
#include <QString>
#include "dummyresource/resourcefactory.h"
#include "dummyresource/domainadaptor.h"
#include "clientapi.h"
#include "commands.h"
#include "entitybuffer.h"
#include "synclistresult.h"
#include "event_generated.h"
#include "entity_generated.h"
#include "metadata_generated.h"
#include "createentity_generated.h"
#include <iostream>
static void removeFromDisk(const QString &name)
{
Akonadi2::Storage store(Akonadi2::Store::storageLocation(), name, Akonadi2::Storage::ReadWrite);
store.removeFromDisk();
}
class DummyResourceBenchmark : public QObject
{
Q_OBJECT
private Q_SLOTS:
void initTestCase()
{
auto factory = Akonadi2::ResourceFactory::load("org.kde.dummy");
QVERIFY(factory);
removeFromDisk("org.kde.dummy.instance1");
removeFromDisk("org.kde.dummy.instance1.userqueue");
removeFromDisk("org.kde.dummy.instance1.synchronizerqueue");
removeFromDisk("org.kde.dummy.instance1.index.uid");
}
void cleanup()
{
removeFromDisk("org.kde.dummy.instance1");
removeFromDisk("org.kde.dummy.instance1.userqueue");
removeFromDisk("org.kde.dummy.instance1.synchronizerqueue");
removeFromDisk("org.kde.dummy.instance1.index.uid");
}
void testWriteToFacadeAndQueryByUid()
{
QTime time;
time.start();
int num = 10000;
for (int i = 0; i < num; i++) {
Akonadi2::ApplicationDomain::Event event;
event.setProperty("uid", "testuid");
QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid"));
event.setProperty("summary", "summaryValue");
Akonadi2::Store::create<Akonadi2::ApplicationDomain::Event>(event, "org.kde.dummy.instance1");
}
auto appendTime = time.elapsed();
//Ensure everything is processed
{
Akonadi2::Query query;
query.resources << "org.kde.dummy.instance1";
query.syncOnDemand = false;
query.processAll = true;
query.propertyFilter.insert("uid", "nonexistantuid");
async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Event>(query));
result.exec();
}
auto allProcessedTime = time.elapsed();
//Measure query
{
time.start();
Akonadi2::Query query;
query.resources << "org.kde.dummy.instance1";
query.syncOnDemand = false;
query.processAll = false;
query.propertyFilter.insert("uid", "testuid");
async::SyncListResult<Akonadi2::ApplicationDomain::Event::Ptr> result(Akonadi2::Store::load<Akonadi2::ApplicationDomain::Event>(query));
result.exec();
QCOMPARE(result.size(), num);
}
qDebug() << "Append to messagequeue " << appendTime;
qDebug() << "All processed: " << allProcessedTime << "/sec " << num*1000/allProcessedTime;
qDebug() << "Query Time: " << time.elapsed() << "/sec " << num*1000/time.elapsed();
}
void testWriteInProcess()
{
QTime time;
time.start();
int num = 10000;
Akonadi2::Pipeline pipeline("org.kde.dummy.instance1");
QSignalSpy revisionSpy(&pipeline, SIGNAL(revisionUpdated()));
DummyResource resource("org.kde.dummy.instance1");
resource.configurePipeline(&pipeline);
flatbuffers::FlatBufferBuilder eventFbb;
eventFbb.Clear();
{
auto summary = eventFbb.CreateString("summary");
Akonadi2::ApplicationDomain::Buffer::EventBuilder eventBuilder(eventFbb);
eventBuilder.add_summary(summary);
auto eventLocation = eventBuilder.Finish();
Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(eventFbb, eventLocation);
}
flatbuffers::FlatBufferBuilder localFbb;
{
auto uid = localFbb.CreateString("testuid");
auto localBuilder = Akonadi2::ApplicationDomain::Buffer::EventBuilder(localFbb);
localBuilder.add_uid(uid);
auto location = localBuilder.Finish();
Akonadi2::ApplicationDomain::Buffer::FinishEventBuffer(localFbb, location);
}
flatbuffers::FlatBufferBuilder entityFbb;
Akonadi2::EntityBuffer::assembleEntityBuffer(entityFbb, 0, 0, eventFbb.GetBufferPointer(), eventFbb.GetSize(), localFbb.GetBufferPointer(), localFbb.GetSize());
flatbuffers::FlatBufferBuilder fbb;
auto type = fbb.CreateString(Akonadi2::ApplicationDomain::getTypeName<Akonadi2::ApplicationDomain::Event>().toStdString().data());
auto delta = fbb.CreateVector<uint8_t>(entityFbb.GetBufferPointer(), entityFbb.GetSize());
Akonadi2::Commands::CreateEntityBuilder builder(fbb);
builder.add_domainType(type);
builder.add_delta(delta);
auto location = builder.Finish();
Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location);
const QByteArray command(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize());
for (int i = 0; i < num; i++) {
resource.processCommand(Akonadi2::Commands::CreateEntityCommand, command, &pipeline);
}
auto appendTime = time.elapsed();
//Wait until all messages have been processed
resource.processAllMessages().exec().waitForFinished();
auto allProcessedTime = time.elapsed();
std::cout << "Append to messagequeue " << appendTime << std::endl;
std::cout << "All processed: " << allProcessedTime << "/sec " << num*1000/allProcessedTime << std::endl;
}
void testCreateCommand()
{
Akonadi2::ApplicationDomain::Event event;
QBENCHMARK {
auto mFactory = new DummyEventAdaptorFactory;
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 = Akonadi2::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize());
auto location = Akonadi2::Commands::CreateCreateEntity(fbb, type, delta);
Akonadi2::Commands::FinishCreateEntityBuffer(fbb, location);
}
}
};
QTEST_MAIN(DummyResourceBenchmark)
#include "dummyresourcebenchmark.moc"
|