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

H-3413: harpc implement tower-based server #5320

Merged
merged 17 commits into from
Oct 7, 2024
Merged

H-3413: harpc implement tower-based server #5320

merged 17 commits into from
Oct 7, 2024

Conversation

indietyp
Copy link
Member

@indietyp indietyp commented Oct 6, 2024

🌟 What is the purpose of this PR?

This implement a harpc server that's based on tower, it's basically a culmination of the efforts over the last few weeks, integrating harpc-tower and harpc-service into one cohesive thing.

This is mostly all working, but there are currently some things that I need to come back to, specifically around:

  • SessionStorageTask - this should all work, but needs to be - ergonomically - hooked into harpc-net via the receiver. I have an idea how to do so, but will do that in a separate task instead. (just to keep this focused on the server component)
  • Codec during this PR I found problems specifically with our current Codec, while it works, it's a bit hard to grapple, especially I found it hard to have a Body<Error = E> turn into a Body<Error = !> (this is possible, but the current design makes this harder than it should be. You'd need to get the first error, then encode that error (which is a future), you get back a bytes object, which you then poll_frame instead of the inner. That's quite a handful of things to get right, and I want to streamline the issue.1 2

To showcase the changes, account.rs moved from tower to server.

side note: I am kinda proud how we don't have a lot of boxing here^^

Pre-Merge Checklist 🚀

🚢 Has this modified a publishable library?

This PR:

  • does not modify any publishable blocks or libraries, or modifications do not need publishing

📜 Does this require a change to the docs?

The changes in this PR:

  • are internal and do not require a docs change

🕸️ Does this require a change to the Turbo Graph?

The changes in this PR:

  • affected the execution graph, and the turbo.json's have been updated to reflect this

🐾 Next steps

  • ergonomic integration of SessionStorageTask and harpc-net
  • client integration
  • sort out Codec - either by revamping it / limiting it or by moving to serde.

Footnotes

  1. this also opens the question if the encode/decode function even need to be async and if we don't want to use something like serde. I have tried to stay away from using serde specifically here because of object safety and because it allows us down the line to implement codecs using bincode, etc. that have a nicer API outside of serde

  2. another problem - and why Codec was born - is that we're unable to encode/decode errors correctly, especially decoding reports, I tried to circumvent that a bit, but maybe this isn't the right solution. Another thing here is that we kinda want to guarantee that encoding an error doesn't lead to an error, because then we have the problem of: how do we report that encoding an error failed?!

@indietyp indietyp requested a review from a team as a code owner October 6, 2024 18:11
@github-actions github-actions bot added area/deps Relates to third-party dependencies (area) area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team type/legal Owned by the @legal team labels Oct 6, 2024
@github-advanced-security
Copy link

This pull request sets up GitHub code scanning for this repository. Once the scans have completed and the checks have passed, the analysis results for this pull request branch will appear on this overview. Once you merge this pull request, the 'Security' tab will show more code scanning analysis results (for example, for the default branch). Depending on your configuration and choice of analysis tool, future pull requests will be annotated with code scanning analysis results. For more information about GitHub code scanning, check out the documentation.

@vilkinsons vilkinsons changed the title harpc implement tower based server H-3413: harpc implement tower-based server Oct 7, 2024
Cargo.toml Outdated Show resolved Hide resolved
libs/@local/harpc/server/src/delegate.rs Show resolved Hide resolved
libs/@local/harpc/server/src/router.rs Outdated Show resolved Hide resolved
libs/@local/harpc/server/src/router.rs Show resolved Hide resolved
libs/@local/harpc/server/src/router.rs Outdated Show resolved Hide resolved
libs/@local/harpc/server/src/serve.rs Outdated Show resolved Hide resolved
libs/@local/harpc/server/src/session.rs Outdated Show resolved Hide resolved
TimDiekmann
TimDiekmann previously approved these changes Oct 7, 2024
libs/@local/harpc/server/src/router.rs Show resolved Hide resolved
libs/@local/harpc/server/src/router.rs Show resolved Hide resolved
libs/@local/harpc/server/src/router.rs Show resolved Hide resolved
TimDiekmann
TimDiekmann previously approved these changes Oct 7, 2024
Copy link
Contributor

github-actions bot commented Oct 7, 2024

Benchmark results

@rust/graph-benches – Integrations

representative_read_multiple_entities

Function Value Mean Flame graphs
entity_by_property depths: DT=0, PT=2, ET=2, E=2 $$55.4 \mathrm{ms} \pm 429 \mathrm{μs}\left({\color{gray}1.01 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=2, E=2 $$50.8 \mathrm{ms} \pm 248 \mathrm{μs}\left({\color{gray}0.082 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=0, E=2 $$45.1 \mathrm{ms} \pm 262 \mathrm{μs}\left({\color{gray}2.49 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=255, PT=255, ET=255, E=255 $$68.5 \mathrm{ms} \pm 410 \mathrm{μs}\left({\color{gray}0.219 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=2, PT=2, ET=2, E=2 $$59.2 \mathrm{ms} \pm 268 \mathrm{μs}\left({\color{gray}-0.799 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=0, E=0 $$40.1 \mathrm{ms} \pm 274 \mathrm{μs}\left({\color{gray}-0.860 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=2, ET=2, E=2 $$95.2 \mathrm{ms} \pm 457 \mathrm{μs}\left({\color{gray}-2.761 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=2, E=2 $$90.6 \mathrm{ms} \pm 513 \mathrm{μs}\left({\color{gray}-2.055 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=0, E=2 $$80.4 \mathrm{ms} \pm 489 \mathrm{μs}\left({\color{gray}-3.500 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=255, PT=255, ET=255, E=255 $$108 \mathrm{ms} \pm 437 \mathrm{μs}\left({\color{gray}-1.420 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=2, PT=2, ET=2, E=2 $$99.0 \mathrm{ms} \pm 468 \mathrm{μs}\left({\color{gray}-2.872 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=0, E=0 $$42.6 \mathrm{ms} \pm 332 \mathrm{μs}\left({\color{gray}-0.802 \mathrm{\%}}\right) $$ Flame Graph

representative_read_entity

Function Value Mean Flame graphs
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1 $$17.0 \mathrm{ms} \pm 207 \mathrm{μs}\left({\color{gray}2.08 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1 $$15.5 \mathrm{ms} \pm 167 \mathrm{μs}\left({\color{lightgreen}-10.600 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1 $$17.2 \mathrm{ms} \pm 238 \mathrm{μs}\left({\color{lightgreen}-27.955 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1 $$15.9 \mathrm{ms} \pm 211 \mathrm{μs}\left({\color{lightgreen}-5.330 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1 $$17.2 \mathrm{ms} \pm 213 \mathrm{μs}\left({\color{lightgreen}-32.014 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1 $$16.7 \mathrm{ms} \pm 206 \mathrm{μs}\left({\color{gray}1.13 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1 $$17.5 \mathrm{ms} \pm 239 \mathrm{μs}\left({\color{lightgreen}-10.384 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1 $$16.7 \mathrm{ms} \pm 169 \mathrm{μs}\left({\color{gray}-2.595 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/page/v/2 $$16.6 \mathrm{ms} \pm 219 \mathrm{μs}\left({\color{gray}2.67 \mathrm{\%}}\right) $$ Flame Graph

representative_read_entity_type

Function Value Mean Flame graphs
get_entity_type_by_id Account ID: d4e16033-c281-4cde-aa35-9085bf2e7579 $$1.39 \mathrm{ms} \pm 3.59 \mathrm{μs}\left({\color{gray}-0.362 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_complete_zero_depth

Function Value Mean Flame graphs
entity_by_id 10 entities $$2.05 \mathrm{ms} \pm 11.1 \mathrm{μs}\left({\color{gray}-0.258 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 25 entities $$2.63 \mathrm{ms} \pm 73.3 \mathrm{μs}\left({\color{gray}-2.633 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 5 entities $$1.88 \mathrm{ms} \pm 6.02 \mathrm{μs}\left({\color{gray}-0.794 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 50 entities $$4.12 \mathrm{ms} \pm 40.1 \mathrm{μs}\left({\color{gray}-2.715 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$1.86 \mathrm{ms} \pm 11.9 \mathrm{μs}\left({\color{gray}-0.504 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_complete_one_depth

Function Value Mean Flame graphs
entity_by_id 10 entities $$50.8 \mathrm{ms} \pm 186 \mathrm{μs}\left({\color{gray}-0.119 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 25 entities $$73.3 \mathrm{ms} \pm 324 \mathrm{μs}\left({\color{gray}0.630 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 5 entities $$25.0 \mathrm{ms} \pm 133 \mathrm{μs}\left({\color{gray}0.407 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 50 entities $$275 \mathrm{ms} \pm 2.89 \mathrm{ms}\left({\color{lightgreen}-81.638 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$19.9 \mathrm{ms} \pm 78.9 \mathrm{μs}\left({\color{gray}-0.254 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_linkless

Function Value Mean Flame graphs
entity_by_id 10000 entities $$9.79 \mathrm{ms} \pm 172 \mathrm{μs}\left({\color{red}8.81 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$1.86 \mathrm{ms} \pm 7.23 \mathrm{μs}\left({\color{gray}-1.021 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 100 entities $$2.01 \mathrm{ms} \pm 11.3 \mathrm{μs}\left({\color{gray}1.50 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1000 entities $$2.73 \mathrm{ms} \pm 20.8 \mathrm{μs}\left({\color{lightgreen}-21.195 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$1.88 \mathrm{ms} \pm 7.31 \mathrm{μs}\left({\color{gray}-0.005 \mathrm{\%}}\right) $$ Flame Graph

Merged via the queue into main with commit b033a83 Oct 7, 2024
159 of 160 checks passed
@indietyp indietyp deleted the bm/harpc/server branch October 7, 2024 12:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/deps Relates to third-party dependencies (area) area/infra Relates to version control, CI, CD or IaC (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team type/legal Owned by the @legal team
Development

Successfully merging this pull request may close these issues.

3 participants