Benchmark tx::SingleNodeEngine

Summary:
Results are:
```
I0327 12:22:56.312857 13756] Testing with 1 threads and 100000 transactions per thread...
I0327 12:22:56.337549 13756] Result (millions of transactions per second) 4.07272
I0327 12:22:56.337618 13756] Testing with 2 threads and 100000 transactions per thread...
I0327 12:22:56.449129 13756] Result (millions of transactions per second) 1.79392
I0327 12:22:56.449151 13756] Testing with 4 threads and 100000 transactions per thread...
I0327 12:22:56.821496 13756] Result (millions of transactions per second) 1.07434
I0327 12:22:56.821519 13756] Testing with 8 threads and 100000 transactions per thread...
I0327 12:22:58.265359 13756] Result (millions of transactions per second) 0.554081
I0327 12:22:58.265383 13756] Testing with 16 threads and 100000 transactions per thread...
I0327 12:23:03.978154 13756] Result (millions of transactions per second) 0.280075
```

After changing the lock to `std::mutex`:
```
I0327 12:28:47.493680 14755] Testing with 1 threads and 100000 transactions per thread...
I0327 12:28:47.520134 14755] Result (millions of transactions per second) 3.80314
I0327 12:28:47.520270 14755] Testing with 2 threads and 100000 transactions per thread...
I0327 12:28:47.744608 14755] Result (millions of transactions per second) 0.891592
I0327 12:28:47.744639 14755] Testing with 4 threads and 100000 transactions per thread...
I0327 12:28:48.213151 14755] Result (millions of transactions per second) 0.853791
I0327 12:28:48.213181 14755] Testing with 8 threads and 100000 transactions per thread...
I0327 12:28:49.342561 14755] Result (millions of transactions per second) 0.70836
I0327 12:28:49.342594 14755] Testing with 16 threads and 100000 transactions per thread...
I0327 12:28:51.722991 14755] Result (millions of transactions per second) 0.672164
```

Reviewers: dgleich

Reviewed By: dgleich

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1319
This commit is contained in:
florijan 2018-03-27 12:23:02 +02:00
parent f1a8d7cd3d
commit 242e75911f

View File

@ -0,0 +1,40 @@
#include <thread>
#include <vector>
#include <glog/logging.h>
#include "transactions/engine_single_node.hpp"
#include "utils/timer.hpp"
void Benchmark(int64_t num_threads, int64_t num_transactions) {
LOG(INFO) << "Testing with " << num_threads << " threads and "
<< num_transactions << " transactions per thread...";
tx::SingleNodeEngine engine;
std::vector<std::thread> threads;
utils::Timer timer;
for (int i = 0; i < num_threads; ++i) {
threads.emplace_back([num_transactions, &engine]() {
for (int j = 0; j < num_transactions; ++j) {
auto *tx = engine.Begin();
engine.Commit(*tx);
}
});
}
for (auto &t : threads) t.join();
int64_t tx_count = engine.GlobalGcSnapshot().front() - 1;
CHECK(tx_count == num_threads * num_transactions)
<< "Got a bad number of transactions: " << tx_count;
auto tps = (double)(tx_count) / timer.Elapsed().count();
LOG(INFO) << "Result (millions of transactions per second) " << tps / 1000000;
}
int main(int, char **argv) {
google::InitGoogleLogging(argv[0]);
for (int thread_count : {1, 2, 4, 8, 16}) {
Benchmark(thread_count, 100000);
}
return 0;
}