From 1acf9f3c486813df807ff6931e56cc13eb26eeaf Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Sun, 23 Aug 2015 18:56:43 +0200 Subject: Store indexes as named databases in the same db. Because we also keep using the same transactions this finally makes the resource somewhat performant. On my system genericresourcebenchmark now processes ~4200 messages per second instead of ~280. --- tests/genericresourcebenchmark.cpp | 56 ++++++++++++++++++++++++++++++++++---- tests/storagetest.cpp | 4 +-- 2 files changed, 53 insertions(+), 7 deletions(-) (limited to 'tests') diff --git a/tests/genericresourcebenchmark.cpp b/tests/genericresourcebenchmark.cpp index 01dc95d..27678b0 100644 --- a/tests/genericresourcebenchmark.cpp +++ b/tests/genericresourcebenchmark.cpp @@ -12,6 +12,7 @@ #include "genericresource.h" #include "definitions.h" #include "domainadaptor.h" +#include "index.h" #include class TestResource : public Akonadi2::GenericResource @@ -88,20 +89,21 @@ class GenericResourceBenchmark : public QObject private Q_SLOTS: void init() + { + Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Warning); + } + + void initTestCase() { removeFromDisk("org.kde.test.instance1"); removeFromDisk("org.kde.test.instance1.userqueue"); removeFromDisk("org.kde.test.instance1.synchronizerqueue"); - Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Warning); - qDebug(); - qDebug() << "-----------------------------------------"; - qDebug(); } void testWriteInProcess() { - int num = 50000; + int num = 10000; auto pipeline = QSharedPointer::create("org.kde.test.instance1"); TestResource resource("org.kde.test.instance1", pipeline); @@ -125,6 +127,50 @@ private Q_SLOTS: std::cout << "All processed: " << allProcessedTime << " /sec " << num*1000/allProcessedTime << std::endl; } + void testWriteInProcessWithIndex() + { + int num = 10000; + + auto pipeline = QSharedPointer::create("org.kde.test.instance1"); + + auto eventFactory = QSharedPointer::create(); + const QByteArray resourceIdentifier = "org.kde.test.instance1"; + auto eventIndexer = new Akonadi2::SimpleProcessor("eventIndexer", [eventFactory, resourceIdentifier](const Akonadi2::PipelineState &state, const Akonadi2::Entity &entity, Akonadi2::Storage::Transaction &transaction) { + auto adaptor = eventFactory->createAdaptor(entity); + Akonadi2::ApplicationDomain::Event event(resourceIdentifier, state.key(), -1, adaptor); + Akonadi2::ApplicationDomain::TypeImplementation::index(event, transaction); + + //Create a bunch of indexes + for (int i = 0; i < 10; i++) { + Index ridIndex(QString("index.index%1").arg(i).toLatin1(), transaction); + ridIndex.add("foo", event.identifier()); + } + }); + + pipeline->setPreprocessors("event", Akonadi2::Pipeline::NewPipeline, QVector() << eventIndexer); + 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(Akonadi2::Commands::CreateEntityCommand, command); + } + 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 << " /sec " << num*1000/appendTime << std::endl; + std::cout << "All processed: " << allProcessedTime << " /sec " << num*1000/allProcessedTime << std::endl; + } + void testCreateCommand() { Akonadi2::ApplicationDomain::Event event; diff --git a/tests/storagetest.cpp b/tests/storagetest.cpp index e872c44..6ba4bcd 100644 --- a/tests/storagetest.cpp +++ b/tests/storagetest.cpp @@ -223,7 +223,7 @@ private Q_SLOTS: bool gotError = false; Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, false); auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); - auto db = transaction.openDatabase(); + auto db = transaction.openDatabase("default", nullptr, false); db.write("key","value"); db.write("key","value"); @@ -246,7 +246,7 @@ private Q_SLOTS: bool gotError = false; Akonadi2::Storage store(testDataPath, dbName, Akonadi2::Storage::ReadWrite, true); auto transaction = store.createTransaction(Akonadi2::Storage::ReadWrite); - auto db = transaction.openDatabase(); + auto db = transaction.openDatabase("default", nullptr, true); db.write("key","value1"); db.write("key","value2"); int numValues = db.scan("key", [&](const QByteArray &key, const QByteArray &value) -> bool { -- cgit v1.2.3