Add some initial measurements

This commit is contained in:
Marko Budiselic 2023-02-21 22:40:07 +01:00
parent 51ed451b82
commit 3095cbd956
7 changed files with 37 additions and 9 deletions

View File

@ -1,4 +1,4 @@
// Copyright 2022 Memgraph Ltd.
// Copyright 2023 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -63,7 +63,7 @@ class CachedPlan {
private:
std::unique_ptr<LogicalPlan> plan_;
utils::Timer cache_timer_;
utils::Timer<> cache_timer_;
};
struct CachedQuery {

View File

@ -63,7 +63,7 @@ class CachedPlan {
private:
std::unique_ptr<LogicalPlan> plan_;
utils::Timer cache_timer_;
utils::Timer<> cache_timer_;
};
struct CachedQuery {

View File

@ -47,6 +47,7 @@
#include "storage/v3/id_types.hpp"
#include "storage/v3/value_conversions.hpp"
#include "utils/result.hpp"
#include "utils/timer.hpp"
namespace memgraph::query::v2 {
@ -151,6 +152,7 @@ class RequestRouter : public RequestRouterInterface {
}
void StartTransaction() override {
MG_RAII_TIMER(timer, __PRETTY_FUNCTION__);
coordinator::HlcRequest req{.last_shard_map_version = shards_map_.GetHlc()};
CoordinatorWriteRequests write_req = req;
spdlog::trace("sending hlc request to start transaction");
@ -172,6 +174,7 @@ class RequestRouter : public RequestRouterInterface {
}
void Commit() override {
MG_RAII_TIMER(timer, __PRETTY_FUNCTION__);
coordinator::HlcRequest req{.last_shard_map_version = shards_map_.GetHlc()};
CoordinatorWriteRequests write_req = req;
spdlog::trace("sending hlc request before committing transaction");
@ -232,6 +235,7 @@ class RequestRouter : public RequestRouterInterface {
}
bool IsPrimaryProperty(storage::v3::LabelId primary_label, storage::v3::PropertyId property) const override {
MG_RAII_TIMER(timer, __PRETTY_FUNCTION__);
const auto schema_it = shards_map_.schemas.find(primary_label);
MG_ASSERT(schema_it != shards_map_.schemas.end(), "Invalid primary label id: {}", primary_label.AsUint());
@ -248,6 +252,7 @@ class RequestRouter : public RequestRouterInterface {
// TODO(kostasrim) Simplify return result
std::vector<VertexAccessor> ScanVertices(std::optional<std::string> label) override {
MG_RAII_TIMER(timer, __PRETTY_FUNCTION__);
// create requests
auto requests_to_be_sent = RequestsForScanVertices(label);
@ -283,6 +288,7 @@ class RequestRouter : public RequestRouterInterface {
std::vector<msgs::CreateVerticesResponse> CreateVertices(std::vector<msgs::NewVertex> new_vertices) override {
MG_ASSERT(!new_vertices.empty());
MG_RAII_TIMER(timer, __PRETTY_FUNCTION__);
// create requests
std::vector<ShardRequestState<msgs::CreateVerticesRequest>> requests_to_be_sent =
@ -310,6 +316,7 @@ class RequestRouter : public RequestRouterInterface {
std::vector<msgs::CreateExpandResponse> CreateExpand(std::vector<msgs::NewExpand> new_edges) override {
MG_ASSERT(!new_edges.empty());
MG_RAII_TIMER(timer, __PRETTY_FUNCTION__);
// create requests
std::vector<ShardRequestState<msgs::CreateExpandRequest>> requests_to_be_sent =
@ -332,6 +339,7 @@ class RequestRouter : public RequestRouterInterface {
}
std::vector<msgs::ExpandOneResultRow> ExpandOne(msgs::ExpandOneRequest request) override {
MG_RAII_TIMER(timer, __PRETTY_FUNCTION__);
// TODO(kostasrim)Update to limit the batch size here
// Expansions of the destination must be handled by the caller. For example
// match (u:L1 { prop : 1 })-[:Friend]-(v:L1)
@ -373,6 +381,7 @@ class RequestRouter : public RequestRouterInterface {
}
std::vector<msgs::GetPropertiesResultRow> GetProperties(msgs::GetPropertiesRequest requests) override {
MG_RAII_TIMER(timer, __PRETTY_FUNCTION__);
requests.transaction_id = transaction_id_;
// create requests
std::vector<ShardRequestState<msgs::GetPropertiesRequest>> requests_to_be_sent =

View File

@ -1,4 +1,4 @@
// Copyright 2022 Memgraph Ltd.
// Copyright 2023 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -58,7 +58,7 @@ class Telemetry final {
const std::string machine_id_;
uint64_t num_{0};
utils::Scheduler scheduler_;
utils::Timer timer_;
utils::Timer<> timer_;
const uint64_t send_every_n_;

View File

@ -1,4 +1,4 @@
// Copyright 2022 Memgraph Ltd.
// Copyright 2023 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -16,17 +16,35 @@
namespace memgraph::utils {
// This class is threadsafe.
template <typename TTime = std::chrono::duration<double>>
class Timer {
public:
Timer() : start_time_(std::chrono::steady_clock::now()) {}
Timer(std::function<void(decltype(std::declval<TTime>().count()) elapsed)> destroy_callback = nullptr)
: start_time_(std::chrono::steady_clock::now()), destroy_callback_(destroy_callback) {}
template <typename TDuration = std::chrono::duration<double>>
TDuration Elapsed() const {
return std::chrono::duration_cast<TDuration>(std::chrono::steady_clock::now() - start_time_);
}
~Timer() {
if (destroy_callback_) {
destroy_callback_(Elapsed<TTime>().count());
}
}
private:
std::chrono::steady_clock::time_point start_time_;
std::function<void(decltype(std::declval<TTime>().count()))> destroy_callback_ = nullptr;
};
#define __MG_RAII_TIMER(name, message) \
memgraph::utils::Timer<> name([](auto elapsed) { spdlog::critical("{} {}s", message, elapsed); })
// TODO(gitbuda): Swap MG_TIMER defines
#ifdef MG_TIMER
#define MG_RAII_TIMER(name, message)
#else
#define MG_RAII_TIMER(name, message) __MG_RAII_TIMER(name, message)
#endif
} // namespace memgraph::utils

View File

@ -257,6 +257,7 @@ void RunV2() {
void RunV3() {
spdlog::critical("Running V3");
MG_RAII_TIMER(timer, "WHOLE v3");
const auto run_start = std::chrono::high_resolution_clock::now();
std::ifstream sm_file{FLAGS_split_file, std::ios::in};
MG_ASSERT(sm_file.good(), "Cannot open split file to read: {}", FLAGS_split_file);

View File

@ -1,4 +1,4 @@
// Copyright 2022 Memgraph Ltd.
// Copyright 2023 Memgraph Ltd.
//
// Use of this software is governed by the Business Source License
// included in the file licenses/BSL.txt; by using this file, you agree to be bound by the terms of the Business Source
@ -92,7 +92,7 @@ class GraphSession {
std::mt19937 generator_;
memgraph::utils::Timer timer_;
memgraph::utils::Timer<> timer_;
private:
double GetRandom() { return std::generate_canonical<double, 10>(generator_); }