diff options
Diffstat (limited to 'tests/storagebenchmark.cpp')
-rw-r--r-- | tests/storagebenchmark.cpp | 118 |
1 files changed, 48 insertions, 70 deletions
diff --git a/tests/storagebenchmark.cpp b/tests/storagebenchmark.cpp index e6ab049..81fd997 100644 --- a/tests/storagebenchmark.cpp +++ b/tests/storagebenchmark.cpp | |||
@@ -5,8 +5,8 @@ | |||
5 | #include "hawd/dataset.h" | 5 | #include "hawd/dataset.h" |
6 | #include "hawd/formatter.h" | 6 | #include "hawd/formatter.h" |
7 | #include "common/storage.h" | 7 | #include "common/storage.h" |
8 | #include "common/log.h" | ||
8 | 9 | ||
9 | #include <iostream> | ||
10 | #include <fstream> | 10 | #include <fstream> |
11 | 11 | ||
12 | #include <QDebug> | 12 | #include <QDebug> |
@@ -38,12 +38,6 @@ static QByteArray createEvent() | |||
38 | return QByteArray::fromRawData(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); | 38 | return QByteArray::fromRawData(reinterpret_cast<const char *>(fbb.GetBufferPointer()), fbb.GetSize()); |
39 | } | 39 | } |
40 | 40 | ||
41 | // static void readEvent(const std::string &data) | ||
42 | // { | ||
43 | // auto readEvent = GetEvent(data.c_str()); | ||
44 | // std::cout << readEvent->summary()->c_str() << std::endl; | ||
45 | // } | ||
46 | |||
47 | class StorageBenchmark : public QObject | 41 | class StorageBenchmark : public QObject |
48 | { | 42 | { |
49 | Q_OBJECT | 43 | Q_OBJECT |
@@ -57,6 +51,7 @@ private: | |||
57 | private Q_SLOTS: | 51 | private Q_SLOTS: |
58 | void initTestCase() | 52 | void initTestCase() |
59 | { | 53 | { |
54 | Akonadi2::Log::setDebugOutputLevel(Akonadi2::Log::Warning); | ||
60 | testDataPath = "./testdb"; | 55 | testDataPath = "./testdb"; |
61 | dbName = "test"; | 56 | dbName = "test"; |
62 | filePath = testDataPath + "buffer.fb"; | 57 | filePath = testDataPath + "buffer.fb"; |
@@ -68,79 +63,71 @@ private Q_SLOTS: | |||
68 | store.removeFromDisk(); | 63 | store.removeFromDisk(); |
69 | } | 64 | } |
70 | 65 | ||
71 | void testWriteRead_data() | ||
72 | { | ||
73 | QTest::addColumn<bool>("useDb"); | ||
74 | QTest::addColumn<int>("count"); | ||
75 | |||
76 | QTest::newRow("db, 50k") << true << count; | ||
77 | QTest::newRow("file, 50k") << false << count; | ||
78 | } | ||
79 | |||
80 | void testWriteRead() | 66 | void testWriteRead() |
81 | { | 67 | { |
82 | QFETCH(bool, useDb); | 68 | auto event = createEvent(); |
83 | QFETCH(int, count); | ||
84 | 69 | ||
85 | QScopedPointer<Akonadi2::Storage> store; | 70 | QScopedPointer<Akonadi2::Storage> store(new Akonadi2::Storage(testDataPath, dbName, Akonadi2::Storage::ReadWrite)); |
86 | if (useDb) { | ||
87 | store.reset(new Akonadi2::Storage(testDataPath, dbName, Akonadi2::Storage::ReadWrite)); | ||
88 | } | ||
89 | 71 | ||
90 | std::ofstream myfile; | ||
91 | myfile.open(filePath.toStdString()); | ||
92 | const char *keyPrefix = "key"; | 72 | const char *keyPrefix = "key"; |
93 | 73 | ||
94 | QTime time; | 74 | QTime time; |
95 | time.start(); | 75 | time.start(); |
76 | //Test db write time | ||
96 | { | 77 | { |
97 | auto event = createEvent(); | 78 | auto transaction = store->createTransaction(Akonadi2::Storage::ReadWrite); |
98 | if (store) { | 79 | for (int i = 0; i < count; i++) { |
99 | auto transaction = store->createTransaction(Akonadi2::Storage::ReadWrite); | 80 | transaction.openDatabase().write(keyPrefix + QByteArray::number(i), event); |
100 | for (int i = 0; i < count; i++) { | 81 | if ((i % 10000) == 0) { |
101 | transaction.openDatabase().write(keyPrefix + QByteArray::number(i), event); | 82 | transaction.commit(); |
102 | if ((i % 10000) == 0) { | 83 | transaction = store->createTransaction(Akonadi2::Storage::ReadWrite); |
103 | transaction.commit(); | ||
104 | transaction = store->createTransaction(Akonadi2::Storage::ReadWrite); | ||
105 | } | ||
106 | } | 84 | } |
107 | transaction.commit(); | ||
108 | } else { | ||
109 | for (int i = 0; i < count; i++) { | ||
110 | myfile << event.toStdString(); | ||
111 | } | ||
112 | myfile.close(); | ||
113 | } | 85 | } |
86 | transaction.commit(); | ||
114 | } | 87 | } |
115 | qreal writeDuration = time.restart(); | 88 | qreal dbWriteDuration = time.restart(); |
116 | qreal writeOpsPerMs = count / writeDuration; | 89 | qreal dbWriteOpsPerMs = count / dbWriteDuration; |
117 | qDebug() << "Writing took[ms]: " << writeDuration << "->" << writeOpsPerMs << "ops/ms"; | ||
118 | 90 | ||
91 | //Test file write time | ||
119 | { | 92 | { |
120 | if (store) { | 93 | std::ofstream myfile; |
121 | auto transaction = store->createTransaction(Akonadi2::Storage::ReadOnly); | 94 | myfile.open(filePath.toStdString()); |
122 | auto db = transaction.openDatabase(); | 95 | for (int i = 0; i < count; i++) { |
123 | for (int i = 0; i < count; i++) { | 96 | myfile << event.toStdString(); |
124 | db.scan(keyPrefix + QByteArray::number(i), [](const QByteArray &key, const QByteArray &value) -> bool { return true; }); | 97 | } |
125 | } | 98 | myfile.close(); |
99 | } | ||
100 | qreal fileWriteDuration = time.restart(); | ||
101 | qreal fileWriteOpsPerMs = count / fileWriteDuration; | ||
102 | |||
103 | //Db read time | ||
104 | { | ||
105 | auto transaction = store->createTransaction(Akonadi2::Storage::ReadOnly); | ||
106 | auto db = transaction.openDatabase(); | ||
107 | for (int i = 0; i < count; i++) { | ||
108 | db.scan(keyPrefix + QByteArray::number(i), [](const QByteArray &key, const QByteArray &value) -> bool { return true; }); | ||
126 | } | 109 | } |
127 | } | 110 | } |
128 | qreal readDuration = time.restart(); | 111 | qreal readDuration = time.restart(); |
129 | qreal readOpsPerMs = count / readDuration; | 112 | qreal readOpsPerMs = count / readDuration; |
130 | 113 | ||
131 | if (store) { | 114 | HAWD::Dataset dataset("storage_readwrite", m_hawdState); |
132 | HAWD::Dataset dataset("storage_readwrite", m_hawdState); | 115 | HAWD::Dataset::Row row = dataset.row(); |
133 | HAWD::Dataset::Row row = dataset.row(); | 116 | row.setValue("rows", count); |
134 | row.setValue("rows", count); | 117 | row.setValue("dbWrite", dbWriteOpsPerMs); |
135 | row.setValue("write", writeDuration); | 118 | row.setValue("fileWrite", fileWriteOpsPerMs); |
136 | row.setValue("writeOps", writeOpsPerMs); | 119 | row.setValue("dbRead", readOpsPerMs); |
137 | row.setValue("read", readOpsPerMs); | 120 | dataset.insertRow(row); |
138 | row.setValue("readOps", readOpsPerMs); | 121 | HAWD::Formatter::print(dataset); |
139 | dataset.insertRow(row); | 122 | } |
140 | HAWD::Formatter::print(dataset); | 123 | |
141 | } else { | 124 | void testSizes() |
142 | qDebug() << "File reading is not implemented."; | 125 | { |
143 | } | 126 | Akonadi2::Storage store(testDataPath, dbName); |
127 | qDebug() << "Database size [kb]: " << store.diskUsage()/1024; | ||
128 | |||
129 | QFileInfo fileInfo(filePath); | ||
130 | qDebug() << "File size [kb]: " << fileInfo.size()/1024; | ||
144 | } | 131 | } |
145 | 132 | ||
146 | void testScan() | 133 | void testScan() |
@@ -195,15 +182,6 @@ private Q_SLOTS: | |||
195 | HAWD::Formatter::print(dataset); | 182 | HAWD::Formatter::print(dataset); |
196 | } | 183 | } |
197 | 184 | ||
198 | void testSizes() | ||
199 | { | ||
200 | Akonadi2::Storage store(testDataPath, dbName); | ||
201 | qDebug() << "Database size [kb]: " << store.diskUsage()/1024; | ||
202 | |||
203 | QFileInfo fileInfo(filePath); | ||
204 | qDebug() << "File size [kb]: " << fileInfo.size()/1024; | ||
205 | } | ||
206 | |||
207 | 185 | ||
208 | private: | 186 | private: |
209 | HAWD::State m_hawdState; | 187 | HAWD::State m_hawdState; |