python-sdk icon indicating copy to clipboard operation
python-sdk copied to clipboard

Add support for async gRPC in Dapr SDK

Open youngbupark opened this issue 5 years ago • 9 comments

Describe the proposal

grpc_asyncio is still WIP. We may need to support it later when grpc_asyncio is stable. https://grpc.github.io/grpc/python/grpc_asyncio.html

Update: grpc_asyncio is now available, however we should publish an asynchronous Dapr Python SDK as a separate SDK, or at least sub package - like dapr.aio (from dapr.aio.clients import DaprClient)

There were concerns from several users about the performance overhead of calling asynchronous methods and running them in a synchronous context, so simply switching over to grpc.aio is not an option unfortunately.

youngbupark avatar Jul 10 '20 22:07 youngbupark

Awesome proposal @youngbupark ! Really loving all the async await implementation work, it makes everything so much easier!

One question from my side: I see a lot of libraries that did not implement async / await yet... currently I need to use a patched asyncio with run_until_complete (e.g. asyncio.get_event_loop().run_until_complete(self.proxy.SimActionSample())) to make calls synchronous for these libraries to work with (Python and AI...).

Might it be interesting to introduce this to the SDK as well, or is it more interesting to have it in the documentation somewhere?

XavierGeerinck avatar Jul 16 '20 07:07 XavierGeerinck

Thanks for the proposal, this will unify a lot of things on the Python SDK. Any update on this @youngbupark ?appreciate it.

omidb avatar Aug 18 '21 22:08 omidb

I don't think @youngbupark is looking at these issues any more ... @wcs1only @artursouza for their opinion instead.

CodeMonkeyLeet avatar Aug 19 '21 00:08 CodeMonkeyLeet

This work seems to be about using grpc_asyncio for all gRPC communication in the SDK.

artursouza avatar Aug 20 '21 00:08 artursouza

right now, it's really not easy to write an app to connect and interact with Actors or invoke a method on service or binding. Some are using async and some are not. It would be great to see an example app that does multiple things such as communication with actors, using pubsub and invoke methods to examine the opportunities to make Python sdk more streamlined.

omidb avatar Aug 20 '21 21:08 omidb

Interested in working on this issue

avvijeet avatar Aug 29 '21 15:08 avvijeet

This issue has been automatically marked as stale because it has not had activity in the last 60 days. It will be closed in the next 7 days unless it is tagged (pinned, good first issue, help wanted or triaged/resolved) or other activity occurs. Thank you for your contributions.

dapr-bot avatar Mar 03 '22 00:03 dapr-bot

This issue has been automatically closed because it has not had activity in the last 67 days. If this issue is still valid, please ping a maintainer and ask them to label it as pinned, good first issue, help wanted or triaged/resolved. Thank you for your contributions.

dapr-bot avatar Mar 10 '22 00:03 dapr-bot

Proposal:

Create a copy of the Dapr gRPC clients (dapr.clients.grpc) within a new package dapr.aio.clients and migrate these to grpc.aio.

Also create matching unit tests.

Ensure existing integration tests pass when they are updated to import from dapr.aio.clients import DaprClient instead. This can be verified with tox -e examples

berndverst avatar Oct 15 '22 20:10 berndverst

Something to consider is how we (re-)organize the tutorials, so we have the same mechanism of tutorials acting as integration tests for the SDK but covering the async API.

tmacam avatar Oct 18 '22 21:10 tmacam

Previous work in progress that could be used for reference but likely needs changing: https://github.com/berndverst/python-sdk/tree/asyncgrpc

These unit tests from the GRPC library might be helpful: https://github.com/grpc/grpc/tree/master/src/python/grpcio_tests/tests_aio/unit

berndverst avatar Oct 18 '22 21:10 berndverst

I finally figured out how to implement this. I'll include it in this upcoming release.

berndverst avatar Apr 15 '23 00:04 berndverst