File indexing completed on 2024-05-12 05:26:24
0001 /* 0002 * Copyright (C) 2016 Christian Mollekopf <chrigi_1@fastmail.fm> 0003 * 0004 * This library is free software; you can redistribute it and/or 0005 * modify it under the terms of the GNU Lesser General Public 0006 * License as published by the Free Software Foundation; either 0007 * version 2.1 of the License, or (at your option) version 3, or any 0008 * later version accepted by the membership of KDE e.V. (or its 0009 * successor approved by the membership of KDE e.V.), which shall 0010 * act as a proxy defined in Section 6 of version 3 of the license. 0011 * 0012 * This library is distributed in the hope that it will be useful, 0013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 0015 * Lesser General Public License for more details. 0016 * 0017 * You should have received a copy of the GNU Lesser General Public 0018 * License along with this library. If not, see <http://www.gnu.org/licenses/>. 0019 */ 0020 #include <QTest> 0021 0022 #include <QString> 0023 0024 #include "testimplementations.h" 0025 0026 #include <common/facade.h> 0027 #include <common/domainadaptor.h> 0028 #include <common/resultprovider.h> 0029 #include <common/definitions.h> 0030 #include <common/query.h> 0031 #include <common/store.h> 0032 #include <common/pipeline.h> 0033 #include <common/index.h> 0034 #include <common/adaptorfactoryregistry.h> 0035 0036 #include "hawd/dataset.h" 0037 #include "hawd/formatter.h" 0038 0039 #include <iostream> 0040 #include <math.h> 0041 0042 #include "mail_generated.h" 0043 #include "createentity_generated.h" 0044 #include "getrssusage.h" 0045 0046 /** 0047 * Benchmark pipeline processing speed. 0048 * 0049 * This benchmark especially highlights: 0050 * * Cost of an index in speed and size 0051 */ 0052 class PipelineBenchmark : public QObject 0053 { 0054 Q_OBJECT 0055 0056 QByteArray resourceIdentifier; 0057 HAWD::State mHawdState; 0058 0059 void populateDatabase(int count, const QVector<Sink::Preprocessor *> &preprocessors) 0060 { 0061 TestResource::removeFromDisk(resourceIdentifier); 0062 0063 auto pipeline = QSharedPointer<Sink::Pipeline>::create(Sink::ResourceContext{resourceIdentifier, "test", Sink::AdaptorFactoryRegistry::instance().getFactories("test")}, "test"); 0064 pipeline->setPreprocessors("mail", preprocessors); 0065 0066 QTime time; 0067 time.start(); 0068 0069 auto domainTypeAdaptorFactory = QSharedPointer<TestMailAdaptorFactory>::create(); 0070 0071 pipeline->startTransaction(); 0072 const auto date = QDateTime::currentDateTimeUtc(); 0073 for (int i = 0; i < count; i++) { 0074 auto domainObject = Sink::ApplicationDomain::Mail::Ptr::create(); 0075 domainObject->setExtractedMessageId("uid"); 0076 domainObject->setExtractedSubject(QString("subject%1").arg(i)); 0077 domainObject->setExtractedDate(date.addSecs(count)); 0078 domainObject->setFolder("folder1"); 0079 // domainObject->setProperty("attachment", attachment); 0080 const auto command = createCommand<Sink::ApplicationDomain::Mail>(*domainObject, *domainTypeAdaptorFactory); 0081 pipeline->newEntity(command.data(), command.size()).exec(); 0082 } 0083 pipeline->commit(); 0084 auto appendTime = time.elapsed(); 0085 0086 auto allProcessedTime = time.elapsed(); 0087 0088 // Print memory layout, RSS is what is in memory 0089 // std::system("exec pmap -x \"$PPID\""); 0090 // 0091 std::cout << "Size: " << Sink::Storage::DataStore(Sink::storageLocation(), resourceIdentifier, Sink::Storage::DataStore::ReadOnly).diskUsage() / 1024 << " [kb]" << std::endl; 0092 std::cout << "Time: " << allProcessedTime << " [ms]" << std::endl; 0093 0094 HAWD::Dataset dataset("pipeline", mHawdState); 0095 HAWD::Dataset::Row row = dataset.row(); 0096 0097 row.setValue("rows", count); 0098 row.setValue("append", (qreal)count / appendTime); 0099 row.setValue("total", (qreal)count / allProcessedTime); 0100 dataset.insertRow(row); 0101 HAWD::Formatter::print(dataset); 0102 } 0103 0104 private slots: 0105 0106 void init() 0107 { 0108 Sink::Log::setDebugOutputLevel(Sink::Log::Warning); 0109 Sink::AdaptorFactoryRegistry::instance().registerFactory<Sink::ApplicationDomain::Mail, TestMailAdaptorFactory>("test"); 0110 resourceIdentifier = "sink.test.instance1"; 0111 } 0112 0113 void testWithIndex() 0114 { 0115 populateDatabase(10000, QVector<Sink::Preprocessor *>()); 0116 } 0117 }; 0118 0119 QTEST_MAIN(PipelineBenchmark) 0120 #include "pipelinebenchmark.moc"