From 833aabc562c51fa962f9f2da14f7cd4552dab22b Mon Sep 17 00:00:00 2001 From: Christian Mollekopf Date: Tue, 17 Oct 2017 13:54:29 +0200 Subject: dummyresourcebenchmark values --- hawd_defs/dummy_responsiveness | 7 +++ tests/dummyresourcebenchmark.cpp | 92 +++------------------------------------- tests/dummyresourcetest.cpp | 32 ++++++++++++++ tests/mailquerybenchmark.cpp | 8 ++-- tests/testutils.h | 11 +++-- 5 files changed, 57 insertions(+), 93 deletions(-) create mode 100644 hawd_defs/dummy_responsiveness diff --git a/hawd_defs/dummy_responsiveness b/hawd_defs/dummy_responsiveness new file mode 100644 index 0000000..8c16c13 --- /dev/null +++ b/hawd_defs/dummy_responsiveness @@ -0,0 +1,7 @@ +{ + "name": "Dummy resource command responsiveness", + "description": "Measure roundtriptime of command", + "columns": [ + { "name": "responsetime", "type": "float", "unit": "ms" } + ] +} diff --git a/tests/dummyresourcebenchmark.cpp b/tests/dummyresourcebenchmark.cpp index 674d4d6..57ad4de 100644 --- a/tests/dummyresourcebenchmark.cpp +++ b/tests/dummyresourcebenchmark.cpp @@ -74,10 +74,13 @@ private slots: // Wait for notification QUICK_TRY_VERIFY(gotNotification); + HAWD::Dataset dataset("dummy_responsiveness", m_hawdState); + HAWD::Dataset::Row row = dataset.row(); + row.setValue("responsetime", duration); + dataset.insertRow(row); + HAWD::Formatter::print(dataset); - QVERIFY2(duration < 100, QString::fromLatin1("Processing a create command took more than 100ms: %1").arg(duration).toLatin1()); VERIFYEXEC(Sink::ResourceControl::shutdown("sink.dummy.instance1")); - qDebug() << "Single command took [ms]: " << duration; } void testWriteToFacade() @@ -113,12 +116,6 @@ private slots: row.setValue("total", (qreal)num / allProcessedTime); dataset.insertRow(row); HAWD::Formatter::print(dataset); - - auto diskUsage = DummyResource::diskUsage("sink.dummy.instance1"); - qDebug() << "Database size [kb]: " << diskUsage / 1024; - - // Print memory layout, RSS is what is in memory - // std::system("exec pmap -x \"$PPID\""); } void testQueryByUid() @@ -133,7 +130,7 @@ private slots: query.filter("uid", Sink::Query::Comparator("testuid")); auto model = Sink::Store::loadModel(query); - QTRY_COMPARE(model->rowCount(QModelIndex()), num); + QUICK_TRY_VERIFY(model->rowCount(QModelIndex()) == num); } auto queryTime = time.elapsed(); @@ -145,83 +142,6 @@ private slots: HAWD::Formatter::print(dataset); } - void testWriteInProcess() - { - VERIFYEXEC(Sink::Store::removeDataFromDisk("sink.dummy.instance1")); - QTime time; - time.start(); - - DummyResource resource(Sink::ResourceContext{"sink.dummy.instance1", "sink.dummy", Sink::AdaptorFactoryRegistry::instance().getFactories("sink.dummy")}); - - 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().toStdString().data()); - auto delta = fbb.CreateVector(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); - - const QByteArray command(reinterpret_cast(fbb.GetBufferPointer()), fbb.GetSize()); - - 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\""); - } - - void testCreateCommand() - { - Sink::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 entityId = fbb.CreateString(""); - auto type = fbb.CreateString("event"); - // auto delta = fbb.CreateVector(entityFbb.GetBufferPointer(), entityFbb.GetSize()); - auto delta = Sink::EntityBuffer::appendAsVector(fbb, entityFbb.GetBufferPointer(), entityFbb.GetSize()); - auto location = Sink::Commands::CreateCreateEntity(fbb, entityId, type, delta); - Sink::Commands::FinishCreateEntityBuffer(fbb, location); - } - } // This allows to run individual parts without doing a cleanup, but still cleaning up normally void testCleanupForCompleteTest() diff --git a/tests/dummyresourcetest.cpp b/tests/dummyresourcetest.cpp index 17df160..28e8337 100644 --- a/tests/dummyresourcetest.cpp +++ b/tests/dummyresourcetest.cpp @@ -14,6 +14,7 @@ #include "test.h" #include "testutils.h" #include "adaptorfactoryregistry.h" +#include "notifier.h" using namespace Sink; using namespace Sink::ApplicationDomain; @@ -275,6 +276,37 @@ private slots: QTRY_COMPARE(model->rowCount(QModelIndex()), 0); } } + + void testCommandResponsiveness() + { + // Test responsiveness including starting the process. + VERIFYEXEC(Sink::Store::removeDataFromDisk("sink.dummy.instance1")); + + QTime time; + time.start(); + + Sink::ApplicationDomain::Event event("sink.dummy.instance1"); + event.setProperty("uid", "testuid"); + QCOMPARE(event.getProperty("uid").toByteArray(), QByteArray("testuid")); + event.setProperty("summary", "summaryValue"); + + auto notifier = QSharedPointer::create("sink.dummy.instance1", "sink.dummy"); + bool gotNotification = false; + int duration = 0; + notifier->registerHandler([&gotNotification, &duration, &time](const Sink::Notification ¬ification) { + if (notification.type == Sink::Notification::RevisionUpdate) { + gotNotification = true; + duration = time.elapsed(); + } + }); + + Sink::Store::create(event).exec(); + // Wait for notification + QUICK_TRY_VERIFY(gotNotification); + + QVERIFY2(duration < 100, QString::fromLatin1("Processing a create command took more than 100ms: %1").arg(duration).toLatin1()); + VERIFYEXEC(Sink::ResourceControl::shutdown("sink.dummy.instance1")); + } }; QTEST_MAIN(DummyResourceTest) diff --git a/tests/mailquerybenchmark.cpp b/tests/mailquerybenchmark.cpp index ff61e81..4d67dca 100644 --- a/tests/mailquerybenchmark.cpp +++ b/tests/mailquerybenchmark.cpp @@ -103,7 +103,7 @@ class MailQueryBenchmark : public QObject bool done = false; emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); emitter->fetch(Mail::Ptr()); - QUICK_TRY_VERIFY(!done); + QUICK_TRY_VERIFY(done); Q_ASSERT(list.size() == expectedSize); const auto elapsed = time.elapsed(); @@ -217,7 +217,7 @@ private slots: bool done = false; emitter->onInitialResultSetComplete([&done](const Mail::Ptr &mail, bool) { done = true; }); emitter->fetch(Mail::Ptr()); - QUICK_TRY_VERIFY(!done); + QUICK_TRY_VERIFY(done); QCOMPARE(added.size(), expectedSize); auto initialQueryTime = time.elapsed(); @@ -230,9 +230,9 @@ private slots: context.mResourceAccess->revisionChanged(1000 + i * 100); } //We should have 200 items in total in the end. 2000 mails / 10 folders => 200 reduced mails - QUICK_TRY_VERIFY(added.count() != 200); + QUICK_TRY_VERIFY(added.count() == 200); //We get one modification per thread from the first 100 (1000 mails / 10 folders), everything else is optimized away because we ignore repeated updates to the same thread. - QUICK_TRY_VERIFY(modified.count() != 100); + QUICK_TRY_VERIFY(modified.count() == 100); auto incrementalQueryTime = time.elapsed(); std::cout << "Incremental query took " << incrementalQueryTime << std::endl; std::cout << "added " << added.count() << std::endl; diff --git a/tests/testutils.h b/tests/testutils.h index 6e935f3..f464e76 100644 --- a/tests/testutils.h +++ b/tests/testutils.h @@ -46,10 +46,15 @@ do {\ return;\ } while (0) +//qWait(1) seems to simply skip waiting at all. #define QUICK_TRY_VERIFY(statement) \ do {\ - static int timeout = 5000; \ - for (int i = 0; i < timeout && #statement; i++) { \ - QTest::qWait(1); \ + static int timeout = 2500; \ + int i = 0; \ + for (; i < timeout && !(statement); i++) { \ + QTest::qWait(2); \ + } \ + if (i >= timeout) { \ + qWarning() << "Timeout during QUICK_TRY_VERIFY"; \ } \ } while (0) -- cgit v1.2.3