memgraph/tests/benchmark/tx_engine.cpp
Matej Ferencevic 96ece11cdd Move distributed transaction engine logic
Summary:
This change introduces a pure virtual initial implementation of the transaction
engine which is then implemented in two versions: single node and distributed.
The interface classes now have the following hierarchy:

```
    Engine (pure interface)
         |
    +----+---------- EngineDistributed (common logic)
    |                         |
EngineSingleNode      +-------+--------+
                      |                |
                 EngineMaster     EngineWorker
```

In addition to this layout the `EngineMaster` uses `EngineSingleNode` as its
underlying storage engine and only changes the necessary functions to make
them work with the `EngineWorker`.

After this change I recommend that you delete the following leftover files:
```
rm src/distributed/transactional_cache_cleaner_rpc_messages.*
rm src/transactions/common.*
rm src/transactions/engine_rpc_messages.*
```

Reviewers: teon.banek, msantl, buda

Reviewed By: teon.banek

Subscribers: pullbot

Differential Revision: https://phabricator.memgraph.io/D1589
2018-09-07 11:43:57 +02:00

41 lines
1.2 KiB
C++

#include <thread>
#include <vector>
#include <glog/logging.h>
#include "transactions/single_node/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::EngineSingleNode 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;
}