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

Refactor findpath #4095

Merged
merged 21 commits into from
Apr 13, 2022
Merged

Refactor findpath #4095

merged 21 commits into from
Apr 13, 2022

Conversation

nevermore3
Copy link
Contributor

@nevermore3 nevermore3 commented Mar 29, 2022

What type of PR is this?

  • bug
  • feature
  • enhancement

What problem(s) does this PR solve?

Issue(s) number:

Description:

1、reduce AllPath & multiPairShortestPath 's memory usage
2、Integrate the function of conjunct path into the path operator to reduce data copying

for specific details, please refer to the comment in the file

image

image

The blue line is optimized
The green line is not optimized

How do you solve it?

Special notes for your reviewer, ex. impact of this fix, design document, etc:

Checklist:

Tests:

  • Unit test(positive and negative cases)
  • Function test
  • Performance test
  • N/A

Affects:

  • Documentation affected (Please add the label if documentation needs to be modified.)
  • Incompatibility (If it breaks the compatibility, please describe it and add the label.)
  • If it's needed to cherry-pick (If cherry-pick to some branches is required, please label the destination version(s).)
  • Performance impacted: Consumes more CPU/Memory

Release notes:

Please confirm whether to be reflected in release notes and how to describe:

ex. Fixed the bug .....

@nevermore3 nevermore3 added ready-for-testing PR: ready for the CI test ready for review labels Mar 29, 2022
@nevermore3 nevermore3 added this to the v3.1.0 milestone Mar 29, 2022
@nevermore3 nevermore3 mentioned this pull request Mar 29, 2022
11 tasks
@Sophie-Xie Sophie-Xie added the cherry-pick-v3.1 PR: need cherry-pick to this version label Apr 1, 2022
@nevermore3 nevermore3 force-pushed the refactor-findpath branch 6 times, most recently from 9ef59eb to a3d5543 Compare April 11, 2022 05:59
@codecov-commenter
Copy link

codecov-commenter commented Apr 11, 2022

Codecov Report

Merging #4095 (693378b) into master (07cbbac) will decrease coverage by 0.15%.
The diff coverage is 96.61%.

@@            Coverage Diff             @@
##           master    #4095      +/-   ##
==========================================
- Coverage   85.08%   84.92%   -0.16%     
==========================================
  Files        1324     1319       -5     
  Lines      131911   130867    -1044     
==========================================
- Hits       112236   111143    -1093     
- Misses      19675    19724      +49     
Impacted Files Coverage Δ
src/graph/executor/admin/SpaceExecutor.cpp 76.99% <ø> (-0.22%) ⬇️
src/graph/executor/algo/BFSShortestPathExecutor.h 100.00% <ø> (ø)
src/graph/executor/algo/ProduceAllPathsExecutor.h 100.00% <ø> (ø)
src/graph/executor/query/DataCollectExecutor.h 100.00% <ø> (ø)
src/graph/planner/ngql/PathPlanner.h 100.00% <ø> (ø)
src/graph/planner/plan/Algo.cpp 43.75% <0.00%> (+2.57%) ⬆️
src/graph/planner/plan/PlanNode.h 86.91% <ø> (ø)
src/graph/service/GraphFlags.cpp 100.00% <ø> (ø)
src/graph/validator/test/FindPathValidatorTest.cpp 100.00% <ø> (ø)
src/meta/test/BalancerTest.cpp 94.70% <ø> (-1.41%) ⬇️
... and 85 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 39fbb94...693378b. Read the comment docs.

batchVids.reserve(batchSize);
std::vector<folly::Future<DataSet>> futures;
for (size_t i = 0; i < totalSize; ++i) {
batchVids.push_back(meetVids[i]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you iterate the meetVids vector from end to start, you will need not to copy the contents to a new vector.

}

std::unordered_multimap<Value, Path> BFSShortestPathExecutor::createPath(
std::vector<Value> meetVids, bool reverse, bool oddStep) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

need not to copy the vector of values.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

});
}

DataSet BFSShortestPathExecutor::doConjunct(const std::vector<Value> meetVids, bool oddStep) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

const std::vector<Value> &

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done


std::vector<folly::Future<Status>> futures;
auto leftFuture = folly::via(runner(), [this]() { return buildPath(false); });
auto rightFuture = folly::via(runner(), [this]() { return buildPath(true); });
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to remind you that the buildPath will be executed in different threads carefully, don't share the same variables inside the function, especially the fields of the class.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, the previous version used local variables but may cause data copying, so use the member variables


DataSet MultiShortestPathExecutor::doConjunct(Interims::iterator startIter,
Interims::iterator endIter,
bool oddStep) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's better to let it be a const function for thread-safe usage.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this function modifies member variables

yixinglu
yixinglu previously approved these changes Apr 12, 2022
CPWstatic
CPWstatic previously approved these changes Apr 12, 2022
@Sophie-Xie Sophie-Xie merged commit 072af05 into vesoft-inc:master Apr 13, 2022
Sophie-Xie pushed a commit that referenced this pull request Apr 13, 2022
* optimize bfs

* optimizer allpath

* optimizer multi-shortestpath

* optimizer multi shortest path

* fix validate unit test

* add some comment

* fix error

* fix bfs error

* add comment

* delete conjunct

* add findpath unit test

* delete useless file

* delete log

* remove check

* multi thread executor

* single shortest multi thread

* add some testcases

* add gflags

* fix bfs error

* address comment
@nevermore3 nevermore3 deleted the refactor-findpath branch April 13, 2022 05:45
Sophie-Xie added a commit that referenced this pull request Apr 13, 2022
* Add SetUsageMessage For daemons (#4134)

* fix the wrong regex pattern of scientific notation (#4136)

* fix updatePart (#4139)

* fix updatePart

* fix format check

Co-authored-by: Sophie <[email protected]>

* show DATA_BALANCE in job list (#4138)

Co-authored-by: Sophie <[email protected]>

* fix disk fault recovery (#4131)

* fix disk fault recovery

* add ut

Co-authored-by: Sophie <[email protected]>

* Refactor findpath (#4095)

* optimize bfs

* optimizer allpath

* optimizer multi-shortestpath

* optimizer multi shortest path

* fix validate unit test

* add some comment

* fix error

* fix bfs error

* add comment

* delete conjunct

* add findpath unit test

* delete useless file

* delete log

* remove check

* multi thread executor

* single shortest multi thread

* add some testcases

* add gflags

* fix bfs error

* address comment

* Just report errorof property pruner in debug mode (#4142)

Co-authored-by: Sophie <[email protected]>

* remove Atomic Edge (#4127)

* try to remove Atomic Edge

* remove some space

* remove zone

Co-authored-by: Doodle <[email protected]>

* fix show tag/edge index status (#4148)

* fix multiple match (#4143)

Co-authored-by: Sophie <[email protected]>

* Refactor the process of symbols in optimizer. (#4146)

* Refactor the process of symbols in optimizer.

* Fix variable shadowing.

* Collect boundary from MatchResult directly.

* Check variable in TransformResult don't referenced by outside plan
nodes.

Co-authored-by: Sophie <[email protected]>

Co-authored-by: Alex Xing <[email protected]>
Co-authored-by: jie.wang <[email protected]>
Co-authored-by: Doodle <[email protected]>
Co-authored-by: liwenhui-soul <[email protected]>
Co-authored-by: panda-sheep <[email protected]>
Co-authored-by: jimingquan <[email protected]>
Co-authored-by: [email protected] <[email protected]>
Co-authored-by: kyle.cao <[email protected]>
Co-authored-by: shylock <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-pick-v3.1 PR: need cherry-pick to this version ready for review ready-for-testing PR: ready for the CI test
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants