tcalmant / jsonrpclib

A Python (2 & 3) JSON-RPC over HTTP that mirrors the syntax of xmlrpclib (aka jsonrpclib-pelix)
https://jsonrpclib-pelix.readthedocs.io/
Apache License 2.0
53 stars 24 forks source link

Try to implement an async version #37

Open tcalmant opened 5 years ago

tcalmant commented 5 years ago

It would be interesting to implement an asyncio-based version of the library, as it undeniably increases performances in most I/O cases.

This would require a big refactoring of the project, in order to share as most code as possible between the sync & async versions of the transport and protocol layers.

It is necessary to decide if the project will depend on a third-party library to handle this or if it will use the Python 3.4+ API & syntax. Note: the library has to stay compatible with Python 2 (at least for some years), which means all of the Python 3 syntax would be in a specific module, loaded when possible.

You can vote for or against this proposal.

tcalmant commented 5 years ago

First try to implement an asyncio server is a success, using aiohttp as the underlying HTTP server.

Here are the tasks to implement the asynchronous server:

For an asynchronous client:

tcalmant commented 5 years ago

The first version of the asynchronous request handler has been pushed on the protocol_extract branch.

A draft of documentation have also been pushed, with a snippet to start the server with aiohttp.

tcalmant commented 5 years ago

And I finally found the time to make an aiohttp version of ServerProxy (called AsyncServerProxy). It is available on the protocol_extract branch.

The usage is pretty straightforward: you just need to use await in front of all calls to the server.

The dependency on aiohttp is somehow limited, as I mimic the Transport model of the xmlrpclib model. Maybe I'll put the aiohttp specific code in another module in order to avoid a hard dependency on this library.

Documentation and unit tests are still to be written. Please comment with to this issue if you try the asynchronous mode and find good or bad.

tcalmant commented 5 years ago

Protocol unit tests from the synchronous client and server are now also applied on their asynchronous versions.

Next steps will be:

tcalmant commented 5 years ago

aiohttp specific code has been moved to a new impl subpackage. It should now be possible to create a new provider with another library (I don't know a lot of equivalents).

I've also added some type hints and potentially fixed a bug in the class converter (when copying the LocalClasses dictionary)

Documentation is still a draft, available as the protocol_extract version.