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-3432: harpc: Expose background task #5394

Merged
merged 2 commits into from
Oct 15, 2024
Merged

H-3432: harpc: Expose background task #5394

merged 2 commits into from
Oct 15, 2024

Conversation

indietyp
Copy link
Member

🌟 What is the purpose of this PR?

This adds an ergonomic way to spawn and create the background task that's required to operate without leaking memory.

Primarily it makes the use of tokio::sync::broadcast an implementation detail, thought that might make sense, as the user shouldn't care what we use under the hood. It's just a stream of events.

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:

  • do not affect the execution graph

@github-actions github-actions bot added area/deps Relates to third-party dependencies (area) area/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team labels Oct 13, 2024
Copy link
Contributor

Benchmark results

@rust/graph-benches – Integrations

representative_read_entity

Function Value Mean Flame graphs
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/organization/v/1 $$16.4 \mathrm{ms} \pm 192 \mathrm{μs}\left({\color{red}22.3 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/book/v/1 $$16.3 \mathrm{ms} \pm 207 \mathrm{μs}\left({\color{gray}1.03 \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 175 \mathrm{μs}\left({\color{lightgreen}-32.377 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/block/v/1 $$16.2 \mathrm{ms} \pm 190 \mathrm{μs}\left({\color{lightgreen}-32.196 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/uk-address/v/1 $$16.1 \mathrm{ms} \pm 179 \mathrm{μs}\left({\color{gray}-1.883 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/playlist/v/1 $$17.9 \mathrm{ms} \pm 201 \mathrm{μs}\left({\color{red}10.5 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/building/v/1 $$16.5 \mathrm{ms} \pm 171 \mathrm{μs}\left({\color{gray}-2.676 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/song/v/1 $$16.0 \mathrm{ms} \pm 197 \mathrm{μs}\left({\color{gray}-1.846 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id entity type ID: https://blockprotocol.org/@alice/types/entity-type/person/v/1 $$16.8 \mathrm{ms} \pm 214 \mathrm{μs}\left({\color{lightgreen}-6.704 \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.41 \mathrm{ms} \pm 6.65 \mathrm{μs}\left({\color{gray}0.821 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_complete_zero_depth

Function Value Mean Flame graphs
entity_by_id 50 entities $$4.02 \mathrm{ms} \pm 22.8 \mathrm{μs}\left({\color{gray}-0.753 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$2.06 \mathrm{ms} \pm 9.08 \mathrm{μs}\left({\color{gray}-0.252 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 25 entities $$2.69 \mathrm{ms} \pm 75.4 \mathrm{μs}\left({\color{lightgreen}-11.541 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$1.84 \mathrm{ms} \pm 11.8 \mathrm{μs}\left({\color{gray}0.204 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 5 entities $$1.88 \mathrm{ms} \pm 10.0 \mathrm{μs}\left({\color{gray}-0.139 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_linkless

Function Value Mean Flame graphs
entity_by_id 1000 entities $$2.74 \mathrm{ms} \pm 14.2 \mathrm{μs}\left({\color{lightgreen}-6.559 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 100 entities $$2.04 \mathrm{ms} \pm 7.89 \mathrm{μs}\left({\color{gray}1.02 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$1.85 \mathrm{ms} \pm 9.93 \mathrm{μs}\left({\color{gray}-4.463 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10000 entities $$9.43 \mathrm{ms} \pm 152 \mathrm{μs}\left({\color{gray}4.70 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$1.88 \mathrm{ms} \pm 14.1 \mathrm{μs}\left({\color{gray}0.226 \mathrm{\%}}\right) $$ Flame Graph

representative_read_multiple_entities

Function Value Mean Flame graphs
entity_by_property depths: DT=2, PT=2, ET=2, E=2 $$60.4 \mathrm{ms} \pm 417 \mathrm{μs}\left({\color{gray}0.752 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=255, PT=255, ET=255, E=255 $$69.0 \mathrm{ms} \pm 409 \mathrm{μs}\left({\color{gray}-0.506 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=0, E=0 $$40.7 \mathrm{ms} \pm 415 \mathrm{μs}\left({\color{gray}-0.616 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=0, E=2 $$44.8 \mathrm{ms} \pm 438 \mathrm{μs}\left({\color{gray}-0.306 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=2, ET=2, E=2 $$55.6 \mathrm{ms} \pm 392 \mathrm{μs}\left({\color{gray}-0.455 \mathrm{\%}}\right) $$ Flame Graph
entity_by_property depths: DT=0, PT=0, ET=2, E=2 $$51.7 \mathrm{ms} \pm 418 \mathrm{μs}\left({\color{gray}-0.463 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=2, PT=2, ET=2, E=2 $$99.4 \mathrm{ms} \pm 435 \mathrm{μs}\left({\color{gray}-0.636 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=255, PT=255, ET=255, E=255 $$109 \mathrm{ms} \pm 744 \mathrm{μs}\left({\color{gray}0.205 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=0, E=0 $$43.4 \mathrm{ms} \pm 217 \mathrm{μs}\left({\color{gray}0.430 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=0, E=2 $$81.1 \mathrm{ms} \pm 582 \mathrm{μs}\left({\color{gray}-0.385 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=2, ET=2, E=2 $$95.0 \mathrm{ms} \pm 364 \mathrm{μs}\left({\color{gray}-0.934 \mathrm{\%}}\right) $$ Flame Graph
link_by_source_by_property depths: DT=0, PT=0, ET=2, E=2 $$92.1 \mathrm{ms} \pm 502 \mathrm{μs}\left({\color{gray}0.946 \mathrm{\%}}\right) $$ Flame Graph

scaling_read_entity_complete_one_depth

Function Value Mean Flame graphs
entity_by_id 50 entities $$275 \mathrm{ms} \pm 1.64 \mathrm{ms}\left({\color{lightgreen}-30.833 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 10 entities $$51.0 \mathrm{ms} \pm 242 \mathrm{μs}\left({\color{gray}-0.642 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 25 entities $$73.1 \mathrm{ms} \pm 497 \mathrm{μs}\left({\color{gray}0.836 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 1 entities $$19.8 \mathrm{ms} \pm 88.2 \mathrm{μs}\left({\color{gray}-0.039 \mathrm{\%}}\right) $$ Flame Graph
entity_by_id 5 entities $$24.7 \mathrm{ms} \pm 126 \mathrm{μs}\left({\color{gray}-0.574 \mathrm{\%}}\right) $$ Flame Graph

@vilkinsons vilkinsons changed the title harpc: expose background task H-3432: harpc: Expose background task Oct 13, 2024
Copy link
Member

@TimDiekmann TimDiekmann left a comment

Choose a reason for hiding this comment

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

Why is clean-up needed at all, why the session storage cannot be cleaned up after a session was terminated?

@indietyp
Copy link
Member Author

this is for session termination, but we have no way to indicate to that a session has been terminated inline. so the net layer has a stream, with events, the only event (currently) is whenever a session is terminated. That is then relayed to this task which removes the session.

Another way this is often solved is through timing (e.g. 60 seconds of inactivity) but I wanted to avoid that approach.

@indietyp indietyp added this pull request to the merge queue Oct 15, 2024
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Oct 15, 2024
@TimDiekmann TimDiekmann added this pull request to the merge queue Oct 15, 2024
Merged via the queue into main with commit 1f8ab0e Oct 15, 2024
161 checks passed
@TimDiekmann TimDiekmann deleted the bm/harpc/net-spawn branch October 15, 2024 11:55
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/libs Relates to first-party libraries/crates/packages (area) type/eng > backend Owned by the @backend team
Development

Successfully merging this pull request may close these issues.

2 participants