-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
fix VertexHolder::getDefaultProp performance issue. #2249
fix VertexHolder::getDefaultProp performance issue. #2249
Conversation
Anyway VertexHolder::get also has performance problem, due to call malloc for every vertex prop fetch. nebula/src/graph/GoExecutor.cpp Lines 1352 to 1356 in a2d51c8
|
rewrite VertexHolder maybe required. |
if (it2 != it->second.cend()) { | ||
return RowReader::getDefaultProp(std::get<0>(it2->second).get(), prop); | ||
} | ||
OptVariantType GoExecutor::VertexHolder::getDefaultProp( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, we don't need "getDefaultProp" and "getDefaultPropType" inside VertexHolder,
You could use RowReader::getDefaultProp directly.
FYI. You could pass schemaManager into VertexHolder directly.
Thanks for your contribution. It is really a stupid mistake. |
I found the problem too. Not only in graphd, but also inside storaged. We have fixed the issue inside 2.0 |
Totally the PR looks good to me. Do you have any plan to fix the RowReader problem in this pr? @xuguruogu |
i prefer to fix rowreader later |
wait for a while. Writing codes. |
expose RowReader with the interface of std::unique_ptr may be a better choice. Without changing large amount of code, all functions using RowReader can benefit from malloc free codes. |
@@ -87,7 +87,7 @@ std::string AddEdgesProcessor::addEdges(int64_t version, PartitionID partId, | |||
}); | |||
for (auto& e : newEdges) { | |||
std::string val; | |||
std::unique_ptr<RowReader> nReader; | |||
RowReader nReader = RowReader::getEmptyRowReader(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You'd better use pointer of RowReader this place. Because there are lots of check null for rowReader in the code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nebula/src/dataman/RowReader.h
Lines 299 to 313 in e5cefb2
bool operator==(nullptr_t) const noexcept { | |
return !data_.data(); | |
} | |
bool operator==(const RowReader& x) const noexcept { | |
return data_ == x.data_; | |
} | |
bool operator!=(nullptr_t) const noexcept { | |
return (bool)data_.data(); | |
} | |
bool operator!=(const RowReader& x) const noexcept { | |
return data_ != x.data_; | |
} |
Solve it with CPP magic. This can really help to improve performance, the total batch computing costs reduces from 13min to 5min, for about 2.6X improvement.
Access data set from the stack is much faster than from heap, for CPU hardware cache optimization.
@@ -88,7 +87,7 @@ kvstore::ResultCode QueryBoundProcessor::processEdgeSampling(const PartitionID p | |||
using Sample = std::tuple< | |||
EdgeType, /* type */ | |||
std::string, /* key */ | |||
std::unique_ptr<RowReader>, /* val */ | |||
RowReader, /* val */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RowReader size is large. Pointer is a better choice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
make sense
e5cefb2
to
bf264be
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome work!! The pr looks good to me.
Besides the RowReader, there is another point we have optimized in 2.0. You could take it as your reference.
That is MetaClient::getEdgeSchemaFromCache
For each row, inside the RowReader, it will call this method to get the related schema.
It is costly, because there are two hashMap inside it.
So in 2.0, we copy the related edge schema before scanning each edgeType. And use a vector to store the multi versions schema for the edgeType.
So two hash lookup will be replaced by one random array access.
return *get(); | ||
} | ||
|
||
void reset() noexcept { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems we dont need reset any more. But never mind, leave it here.
currEdgeSchema, props)); | ||
std::make_tuple( | ||
edgeType, k.str(), | ||
std::make_unique<RowReader>(std::move(reader)), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
HaHa. Very tricky one~
Please check the code style. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Impressive!
c7ee3b4
to
8ef5730
Compare
8ef5730
to
ce66684
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job!
emm... It may not give the expected performance improvement. I am familiar with commonly used optimization method. Maybe we can talk about it later in a specified scenario. |
For RowReader, it has about 1.3x improvement. |
* fix VertexHolder::getDefaultProp performance issue. * rewrite row reader to avoid malloc Co-authored-by: trippli <trippli@tencent.com> Co-authored-by: dangleptr <37216992+dangleptr@users.noreply.github.com>
* fix VertexHolder::getDefaultProp performance issue. * rewrite row reader to avoid malloc Co-authored-by: trippli <trippli@tencent.com> Co-authored-by: dangleptr <37216992+dangleptr@users.noreply.github.com>
* add allpath test * add shortest path test case * add subgraph test case * add go test case * add go test case Co-authored-by: jimingquan <mingquan.ji@vesoft.com>
VertexHolder::getDefaultProp has huge performace problem, if get some prop not exist.
before:
after: