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(meta): split meta into smaller crates (step 1) #12924

Merged
merged 9 commits into from
Oct 18, 2023
Merged

Conversation

xxchan
Copy link
Member

@xxchan xxchan commented Oct 17, 2023

I hereby agree to the terms of the RisingWave Labs, Inc. Contributor License Agreement.

What's changed and what's your intention?

Just trying my idea quickly. Feel free to leave any comments/concerns. Will proceed if the idea sounds good.

I came up with this idea because I thought async_trait is a major reason of the slow compilation (#9553 (comment)). There are many async_traits in tonic services, and many heavy futures to type check. We can hardly get rid of them, but maybe we can split the services into crates so that we can compile them in parallel. (a little similar to #12485, but different)

As a first step, split out:

  • meta/service: tonic grpc service implementations. We may further split this into parallel sub-crates.
  • meta/node: the server binary

Result

A rough manual test:
compiling only meta takes 50s -> 42s
compiling pb -> cmd_all takes 92s -> 76s

Before
image

After
image

Note

In order to quickly pass compilation, some brute force is used:

  • All pub(crate) are simply replaced with pub.
  • use risingwave_meta::* is used without careful fine-graind imports.

Checklist

  • I have written necessary rustdoc comments
  • I have added necessary unit tests and integration tests
  • I have added fuzzing tests or opened an issue to track them. (Optional, recommended for new SQL features Sqlsmith: Sql feature generation #7934).
  • My PR contains breaking changes. (If it deprecates some features, please create a tracking issue to remove them in the future).
  • All checks passed in ./risedev check (or alias, ./risedev c)
  • My PR changes performance-critical code. (Please run macro/micro-benchmarks and show the results.)
  • My PR contains critical fixes that are necessary to be merged into the latest release. (Please check out the details)

Documentation

  • My PR needs documentation updates. (Please use the Release note section below to summarize the impact on users)

Release note

If this PR includes changes that directly affect users or other significant modifications relevant to the community, kindly draft a release note to provide a concise summary of these changes. Please prioritize highlighting the impact these changes will have on users.

Just trying my idea quickly. Feel free to leave any comments/concerns.

I came up with this idea because I thought `async_trait` is a major reason of the slow compilation (#9553 (comment)). There are many `async_trait`s in tonic services, and many heavy futures to type check. We can hardly get rid of them, but maybe we can split the services into crates so that we can compile them in parallel. (a little similar to #12485, but different)

As a first step, split out:
- `meta/service`: tonic grpc service implementations. We may further split this into parallel sub-crates.
- `meta/node`: the server binary

### Result
compiling only meta takes 50s -> 42s
compiling pb -> cmd_all takes 92s -> 76s

### Note
In order to quickly pass compilation, some brute force is used:
- All `pub(crate)` are simply replaced with `pub`.
- `use risingwave_meta::*` is used without careful fine-graind imports.
Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

license-eye has totally checked 4280 files.

Valid Invalid Ignored Fixed
1904 1 2375 0
Click to see the invalid file list
  • src/meta/service/src/mod.rs

@codecov
Copy link

codecov bot commented Oct 17, 2023

Codecov Report

Merging #12924 (3bd8ff7) into main (4b4afc8) will decrease coverage by 0.62%.
Report is 2 commits behind head on main.
The diff coverage is 8.83%.

@@            Coverage Diff             @@
##             main   #12924      +/-   ##
==========================================
- Coverage   69.19%   68.58%   -0.62%     
==========================================
  Files        1493     1494       +1     
  Lines      246484   249286    +2802     
==========================================
+ Hits       170560   170964     +404     
- Misses      75924    78322    +2398     
Flag Coverage Δ
rust 68.58% <8.83%> (-0.62%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files Coverage Δ
src/cmd_all/src/bin/risingwave.rs 0.00% <ø> (ø)
src/compute/src/lib.rs 17.50% <ø> (ø)
src/connector/src/lib.rs 52.08% <ø> (ø)
src/meta/service/src/backup_service.rs 0.22% <ø> (ø)
src/meta/service/src/cloud_service.rs 0.00% <ø> (ø)
src/meta/service/src/cluster_service.rs 0.00% <ø> (ø)
src/meta/service/src/ddl_service.rs 0.00% <ø> (ø)
src/meta/service/src/heartbeat_service.rs 0.00% <ø> (ø)
src/meta/service/src/hummock_service.rs 3.02% <ø> (ø)
src/meta/service/src/meta_member_service.rs 0.00% <ø> (ø)
... and 42 more

... and 5 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@xxchan xxchan requested a review from shanicky October 18, 2023 02:21
Copy link
Contributor

@wenym1 wenym1 left a comment

Choose a reason for hiding this comment

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

Rest LGTM.

src/meta/src/rpc/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@fuyufjh fuyufjh left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@yezizp2012 yezizp2012 left a comment

Choose a reason for hiding this comment

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

LGTM!

Copy link
Member

@BugenZhao BugenZhao left a comment

Choose a reason for hiding this comment

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

LGTM. How were you able to do this so quickly?

@xxchan
Copy link
Member Author

xxchan commented Oct 18, 2023

How were you able to do this so quickly?

🤔️ It took me about 2h to do this. Steps were:

  1. Simply mv meta/src/rpc/service, to meta_service and meta/src/lib.rs, meta/src/rpc/server.rs to meta_node.
    • Cargo.toml is copied from meta (without pruning the dependencies), and add meta as dependency.
    • Add use risingwave_meta::* to new crates so that we don't need to change use crate::...
  2. make cargo build -p risingwave_meta compile. IIRC this is very easy, thanks to the fact that the dependency relationship of these are very clear.
  3. make cargo build -p risingwave_meta_service compile. Mainly just need to change pub(crate) to pub... Then fix a few minor issues. IIRC this part took the most time.
  4. make cargo build -p risingwave_meta_node compile. Easier. Mainly just replace imports.
  5. make cargo build -p risingwave_cmd_all compile.
  6. risedev check-fix, and fix a few minor issues.

As you can see the diff of this PR is also very reviewable, so it's a relatively easy refactor. I think it should mainly because the dependency node <- service <- others is clear.

Copy link
Contributor

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

license-eye has totally checked 4281 files.

Valid Invalid Ignored Fixed
1904 1 2376 0
Click to see the invalid file list
  • src/meta/service/src/mod.rs

@xxchan xxchan enabled auto-merge October 18, 2023 07:55
@xxchan xxchan added this pull request to the merge queue Oct 18, 2023
Merged via the queue into main with commit f102193 Oct 18, 2023
6 of 8 checks passed
@xxchan xxchan deleted the xxchan/split-meta branch October 18, 2023 08:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants