-
Notifications
You must be signed in to change notification settings - Fork 800
Add Async I/O Support #1435
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
Add Async I/O Support #1435
Conversation
This commit adds support for async I/O that mirrors the support added to elasticsearch-py in elastic/elasticsearch-py#1203. Changes: * A new `client` argument was added to `elasticsearch_dsl.connections.create_connection` to allow users to provide the `elasticsearch._async.AsyncElasticsearch` as their preferred client class. Passing `AsyncElasticsearch` will enable asynchronous behavior in `elasticsearch_dsl`. * Async versions of the `FacetedSearch`, `Index`, `Mapping`, `Search`, and `UpdateByQuery` classes have been added to elasticsearch_dsl._async. The paths for these classes mirror the paths for their sync versions. These classes defer to their respective sync classes for all methods that don't perform I/O. * Async versions of `Document.get`, `Document.init`, `Document.mget`, `Document.delete`, `Document.save`, and `Document.update` have been added to the `Document` class with the following names: * `Document.delete` -> `Document.delete_async` * `Document.get` -> `Document.get_async` * `Document.init` -> `Document.init_async` * `Document.mget` -> `Document.mget_async` * `Document.save` -> `Document.save_async` * `Document.update` -> `Document.update_async` * Where possible, the existing methods have been refactored to re-use their existing implementation instead of creating duplication. Closes #1355.
💚 CLA has been signed |
@sethmlarson This commit is missing tests and maybe some other stuff too, which I'm happy to add, but first I wanted to get a 👍 or 👎 on whether this approach seems like it's going in the right direction and see if you have any early feedback. |
Just an FYI I've seen this PR and have reviewing it on my todo list. Thanks for getting this started. |
@sethmlarson Would it help if I broke this PR into a series of smaller PRs? |
Hello, I have read this PR and I approve it.... :D |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this PR! Going to prefix this review with letting you know I'll have a lot more time to allocate to Elasticsearch-DSL after Elastic Stack 7.10 has been released. For now I have the following comments:
- I'd like to integrate unasync along with clever
unasync.Rule.additional_replacements
usage somehow into this PR if possible so that supporting sync and async together only requires changing code in one place. - If we're doing
AsyncDocument
, etc then we don't need theasync_
prefix on functions. The class name namespaces all functions within the class to potentially be async.
More detailed review of this PR will come eventually.
Sounds good. Just to clarify a few things:
Other thoughts:
|
@lolripgg I actually want to use We keep the existing sync code where it is, make a copy as you've done here with everything under For testing I'd like to test each class the same way we do now, maybe we can do something with unasync there too if it becomes too unruly? |
Can you provide an example of how |
@lolripgg When I try to add ur repo in requirements.txt using Am I doing this wrong? |
@zikphil Try running |
@lolripgg The _async package for ES is here. When I explore site-packages and I go to elasticsearch I see the _async folder there. After installing ur repo, I see all the changes you have made to init.py of elasticsearch-dsl but the _async folder is not in the main folder. https://imgur.com/a/ceF0kZq |
Oh. That's probably because |
|
@zikphil Give it a try now and let me know how it goes. |
@lolripgg Is it normal that there are no more AsyncDocument class?
Running this gives me:
|
@zikphil Yeah. That was intentional, but I'm on the fence about the decision. They're still available as |
Imo having the Async prefix on the classes is best so they can be imported in |
Sounds good. I’ll include that in the next round of changes.
…On Fri, Oct 23, 2020 at 2:43 PM Seth Michael Larson < ***@***.***> wrote:
I think having the Async prefix on the classes is best so they can be
imported in *all*.
—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
<#1435 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AA7H5LACIH55MLGP2PDOOL3SMHTHHANCNFSM4SFIX2PQ>
.
|
I believe we should stay as close as possible to the method used by |
Closing this in favor of #1480 |
NOTE: This commit message is outdated and will be updated before merging.
This commit adds support for async I/O that mirrors the support added to
elasticsearch-py in elastic/elasticsearch-py#1203.
Changes:
client
argument was added toelasticsearch_dsl.connections.create_connection
to allow users to provide theelasticsearch._async.AsyncElasticsearch
as their preferred client class. PassingAsyncElasticsearch
will enable asynchronous behavior inelasticsearch_dsl
.FacetedSearch
,Index
,Mapping
,Search
, andUpdateByQuery
classes have been added to elasticsearch_dsl._async. The paths for these classes mirror the paths for their sync versions. These classes defer to their respective sync classes for all methods that don't perform I/O.Document.delete
,.get
,.init
,.mget
,.save
, and.update
have been added to theAsyncDocument
class:Document.delete
->AsyncDocument.delete_async
Document.get
->AsyncDocument.get_async
Document.init
->AsyncDocument.init_async
Document.mget
->AsyncDocument.mget_async
Document.save
->AsyncDocument.save_async
Document.update
->AsyncDocument.update_async
delete_async
overasync def delete
? Because I felt that async calls should be optional, even when usingAsyncDocument
. Ideally, these functions would exist directly on theDocument
class, but theasync
/await
syntax was introduced in Python 3.6 and causes problems for lower versions. Putting theasync
/await
features in a separate file and including that file conditionally based on the Python version solves these problems.Closes #1355.