Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query modules in C++ are being congested by the unique lock #1942

Open
Josipmrden opened this issue Apr 16, 2024 · 0 comments
Open

Query modules in C++ are being congested by the unique lock #1942

Josipmrden opened this issue Apr 16, 2024 · 0 comments
Assignees
Labels
bug bug Effort - Medium Effort - Medium Frequency - Daily Frequency - Daily Priority - Now Priority - Now Reach - Most Reach - Most Severity - S1 Severity - S1

Comments

@Josipmrden
Copy link
Contributor

Memgraph version
v2.16.0

Environment
Ubuntu 22.04

Describe the bug
It seems that the memory dispatch guard is taking around 30% time on holding the unique lock while registering and unregistering the thread. Furthermore, the Register and Unregister methods are both called as many times as the query module is run (so at least once per query, but can be more)

Query module for testing

#include <mgp.hpp>
#include <string>

void isEqual(mgp_list *args, mgp_func_context *ctx, mgp_func_result *res, mgp_memory *memory) {
    mgp::MemoryDispatcherGuard guard(memory);

    const auto arguments = mgp::List(args);
    auto result = mgp::Result(res);

    std::string output = std::string(arguments[0].ValueString());
    std::string input = std::string(arguments[1].ValueString());

    result.SetValue(output == input);
}
 
extern "C" int mgp_init_module(struct mgp_module *module, struct mgp_memory *memory) {
  try {
    mgp::MemoryDispatcherGuard guard(memory);
 
    mgp::AddFunction(isEqual, "is_equal",
                     {mgp::Parameter("output", mgp::Type::String), mgp::Parameter("input", mgp::Type::String)}, module, memory);
  } catch (const std::exception &e) {
    return 1;
  }
  return 0;
}
 
extern "C" int mgp_shutdown_module() {
  return 0;
}

To Reproduce
Steps to reproduce the behavior:

  1. foreach (i in range(1, 10000000) | CREATE (:Node {id1: toString(i), id2: toString(i)}));
  2. Observe how much time it takes to execute match (n) where equality.is_equal(n.id1, n.id2) = true return count(*);
  3. observe how much time it takes to execute the command above in parallel (use 2 consoles and run one immediately after the other) -> the time is more than doubled for both queries

Expected behavior
Queries shouldn't be that slow

Flamegraph
Screenshot from 2024-04-15 16-12-20

@Josipmrden Josipmrden added bug bug Effort - Medium Effort - Medium Severity - S1 Severity - S1 Frequency - Daily Frequency - Daily Reach - Most Reach - Most Priority - Now Priority - Now labels Apr 16, 2024
@DavIvek DavIvek self-assigned this May 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug bug Effort - Medium Effort - Medium Frequency - Daily Frequency - Daily Priority - Now Priority - Now Reach - Most Reach - Most Severity - S1 Severity - S1
Projects
None yet
Development

No branches or pull requests

2 participants