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

Optimize unary handlers with persistent connections to P2P daemon #328

Merged
merged 99 commits into from
Aug 24, 2021

Conversation

dvmazur
Copy link
Collaborator

@dvmazur dvmazur commented Jul 18, 2021

This PR implements unary handlers over a persistent daemon connection.

The daemon part (Golang): learning-at-home/go-libp2p-daemon#3

@dvmazur dvmazur self-assigned this Jul 18, 2021
@codecov
Copy link

codecov bot commented Jul 18, 2021

Codecov Report

Merging #328 (f730559) into master (f97b742) will increase coverage by 0.17%.
The diff coverage is 96.77%.

@@            Coverage Diff             @@
##           master     #328      +/-   ##
==========================================
+ Coverage   83.22%   83.40%   +0.17%     
==========================================
  Files          66       66              
  Lines        6002     6139     +137     
==========================================
+ Hits         4995     5120     +125     
- Misses       1007     1019      +12     
Impacted Files Coverage Δ
hivemind/p2p/p2p_daemon_bindings/datastructures.py 73.58% <50.00%> (-0.46%) ⬇️
hivemind/p2p/p2p_daemon_bindings/control.py 92.54% <96.19%> (+2.94%) ⬆️
hivemind/dht/__init__.py 91.50% <100.00%> (+0.22%) ⬆️
hivemind/dht/protocol.py 93.05% <100.00%> (ø)
hivemind/p2p/p2p_daemon.py 94.69% <100.00%> (-2.32%) ⬇️
hivemind/p2p/p2p_daemon_bindings/p2pclient.py 100.00% <100.00%> (ø)
hivemind/p2p/servicer.py 94.52% <100.00%> (-0.08%) ⬇️

@borzunov borzunov changed the title Unary handlers Optimize unary handlers with persistent connections to the daemon Jul 19, 2021
@borzunov borzunov changed the title Optimize unary handlers with persistent connections to the daemon Optimize unary handlers with persistent connections to P2P daemon Jul 19, 2021
@dvmazur dvmazur requested a review from borzunov July 19, 2021 16:09
Copy link
Member

@justheuristic justheuristic left a comment

Choose a reason for hiding this comment

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

  • in DaemonConnector create_persistent_connection, await an ok message from daemon to ensure that it was created successfully before returning connection
  • add a test that attempts to call: (1) non-existing unary handler (2) existing handler with wrong protobuf types (3) self-dial [non-]existing handler. Ensure that it raises error instead of hanging
  • p2pd: do not send ok (p2pd->pyclient) on receiving unary response
  • update p2pd versions (merge libp2p master into ours) - libp2p/go-libp2p-daemon@193eab6
  • print warning on any unexpected messages over persistent connection

@@ -131,6 +131,7 @@ async def add_p2p_handlers(self, p2p: P2P, wrapper: Any = None, *, namespace: Op
getattr(servicer, handler.method_name),
handler.request_type,
stream_input=handler.stream_input,
Copy link
Member

Choose a reason for hiding this comment

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

Nitpicking: should we create them asynchronously via gather

Copy link
Member

Choose a reason for hiding this comment

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

upd: this is definitely not a bottleneck, feel free to ignore/resolve

Copy link
Member

Choose a reason for hiding this comment

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

I support this because it may improve startup time. Good catch!

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done!

@dvmazur
Copy link
Collaborator Author

dvmazur commented Aug 23, 2021

Just in case, the build_and_test_p2pd job is expected to fail, as the release used in setup.py points to the master branch of p2pd.

Copy link
Member

@borzunov borzunov left a comment

Choose a reason for hiding this comment

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

Approving this. We have also decided to revert the first change from learning-at-home/go-libp2p-daemon#11 in a future PR (it is unnecessary but increases startup time).

@dvmazur dvmazur merged commit 4890a75 into master Aug 24, 2021
@dvmazur dvmazur deleted the unary-handlers branch August 24, 2021 15:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add handler cancelling support for unary handlers
4 participants