Skip to content
Merged
Show file tree
Hide file tree
Changes from 101 commits
Commits
Show all changes
103 commits
Select commit Hold shift + click to select a range
6c262c6
Init commit for async plasma client
suquark May 8, 2018
8609a0c
Create an eventloop model for ray/plasma
suquark Jun 4, 2018
2ed2d8d
Implement a poll-like selector base on `ray.wait`. Huge improvements.
suquark Jun 4, 2018
c8fd938
Allow choosing workers & selectors
suquark Jun 4, 2018
4d17096
remove original design
suquark Jun 4, 2018
bbef768
initial implementation of epoll-like selector for plasma
suquark Jun 5, 2018
b95c891
Add a param for `worker` used in `PlasmaSelectorEventLoop`
suquark Jun 7, 2018
08995f1
Allow accepting a `Future` which returns object_id
suquark Jun 8, 2018
13747bf
Do not need `io.py` anymore
suquark Jun 8, 2018
747e65a
Create a basic testing model
suquark Jun 8, 2018
4e954a1
fix: `ray.wait` returns tuple of lists
suquark Jun 8, 2018
80e8b3c
fix a few bugs
suquark Jun 8, 2018
f127927
improving performance & bug fixing
suquark Jun 10, 2018
e4849b0
add test
suquark Jun 12, 2018
abdbbb7
several improvements & fixing
suquark Jun 12, 2018
47de57d
fix relative import
suquark Jun 12, 2018
1e83886
[async] change code format, remove old files
suquark Jun 13, 2018
a85d640
[async] Create context wrapper for the eventloop
suquark Jun 14, 2018
1753282
[async] fix: context should return a value
suquark Jun 18, 2018
ba99e03
[async] Implement futures grouping
suquark Jun 18, 2018
04b33e0
[async] Fix bugs & replace old functions
suquark Jun 18, 2018
203400c
[async] Fix bugs found in tests
suquark Jun 18, 2018
64ad596
[async] Implement `PlasmaEpoll`
suquark Jun 18, 2018
bd1c6a9
[async] Make test faster, add tests for epoll
suquark Jun 18, 2018
6f8e2e9
[async] Fix code format
suquark Jun 19, 2018
9cd12a1
[async] Add comments for main code.
suquark Jun 25, 2018
5bd2584
[async] Fix import path.
suquark Jun 25, 2018
a3e599a
[async] Fix test.
suquark Jun 26, 2018
e489e9f
[async] Compatibility.
suquark Jun 26, 2018
2554cd9
[async] less verbose to not annoy the CI.
suquark Jun 26, 2018
6b080d3
[async] Add test for new API
suquark Jun 27, 2018
60b0f05
[async] Allow showing debug info in some of the test.
suquark Jun 28, 2018
e09f840
[async] Fix test.
suquark Jun 28, 2018
6db4ce3
[async] Proper shutdown.
suquark Jun 28, 2018
40b5392
[async] Lint~
suquark Jun 28, 2018
734d1c7
[async] Move files to experimental and create API
suquark Jul 5, 2018
c107284
[async] Use async/await syntax
suquark Jul 5, 2018
ecc2743
[async] Fix names & styles
suquark Jul 5, 2018
c5648ce
[async] comments
suquark Jul 5, 2018
e0ae7a1
[async] bug fixing & use pytest
suquark Jul 5, 2018
91bdd93
[async] bug fixing & change tests
suquark Jul 6, 2018
739f43f
[async] use logger
suquark Jul 6, 2018
6c0a5fd
[async] add tests
suquark Jul 6, 2018
ad25009
[async] lint
suquark Jul 7, 2018
7db7c3d
[async] type checking
suquark Jul 11, 2018
9b16b04
[async] add more tests
suquark Jul 14, 2018
a9b9690
[async] fix bugs on waiting a future while timeout. Add more docs.
suquark Jul 14, 2018
997bcc0
[async] Formal docs.
suquark Jul 14, 2018
60e57f6
[async] Add typing info since these codes are compatible with py3.5+.
suquark Jul 14, 2018
f6a80bd
[async] Documents.
suquark Jul 15, 2018
292431f
[async] Lint.
suquark Jul 15, 2018
f516ad1
[async] Fix deprecated call.
suquark Jul 15, 2018
0ed39ba
[async] Fix deprecated call.
suquark Jul 15, 2018
64782aa
[async] Implement a more reasonable way for dealing with pending inputs.
suquark Jul 15, 2018
9ecb798
[async] Fix docs
suquark Jul 16, 2018
7af1814
[async] Lint
suquark Jul 16, 2018
4e61498
[async] Fix bug: Type for time
suquark Jul 17, 2018
bbe0d2d
[async] Set our eventloop as the default eventloop so that we can get…
suquark Sep 12, 2018
b76810b
[async] Update test & docs.
suquark Sep 13, 2018
03de3d3
[async] Lint.
suquark Sep 13, 2018
fad1ca4
[async] Temporarily print more debug info.
suquark Sep 13, 2018
f63a855
[async] Use `Poll` as a default option.
suquark Sep 14, 2018
b94542f
[async] Limit resources.
suquark Sep 14, 2018
8412461
new async implementation for Ray
suquark Nov 22, 2018
363a0b6
implement linked list
suquark Nov 23, 2018
1057d57
bug fix
suquark Nov 23, 2018
519fd9d
update
suquark Nov 24, 2018
27453b0
support seamless async operations
suquark Nov 24, 2018
cce0078
update
suquark Nov 24, 2018
08046f9
update API
suquark Nov 24, 2018
29bceac
fix tests
suquark Nov 27, 2018
e5d42f5
lint
suquark Nov 27, 2018
22b2a14
bug fix
suquark Nov 28, 2018
3e6d1e8
refactor names
suquark Nov 28, 2018
d9e10ce
improve doc
suquark Nov 29, 2018
50a3ee9
properly shutdown async_api
suquark Nov 29, 2018
b19cf71
doc
suquark Nov 29, 2018
9c05c1e
Change the table on the index page.
suquark Nov 29, 2018
0dbca21
Adjust table size.
suquark Nov 29, 2018
a2b6826
Only keeps `as_future`.
suquark Nov 30, 2018
4d2bfec
change how we init connection
suquark Nov 30, 2018
c35d1b1
init connection in `ray.worker.connect`
suquark Dec 1, 2018
7ad33a9
doc
suquark Dec 1, 2018
e8d21b8
fix
suquark Dec 4, 2018
4f4ea6b
Move initialization code into the module.
suquark Dec 4, 2018
a82b9c3
Fix docs & code
suquark Dec 5, 2018
37fdc47
Update pyarrow version.
suquark Dec 6, 2018
46f90ca
lint
suquark Dec 6, 2018
8ba9a78
Restore index.rst
suquark Dec 6, 2018
38e32ba
Add known issues.
suquark Dec 6, 2018
d96fb62
Merge branch 'master' of github.com:suquark/ray
suquark Dec 6, 2018
4563b0a
Apply suggestions from code review
ericl Dec 6, 2018
5fd5d8a
rename
suquark Dec 6, 2018
0a9b217
Update async_api.rst
ericl Dec 6, 2018
a8e24b8
Update async_api.py
ericl Dec 6, 2018
a238cd6
Update async_api.rst
ericl Dec 6, 2018
837cbdd
Update async_api.py
ericl Dec 6, 2018
4d8ab75
Update worker.py
ericl Dec 6, 2018
d2bf03a
Update async_api.rst
ericl Dec 6, 2018
7f0b61c
fix tests
suquark Dec 6, 2018
9a78bb9
lint
suquark Dec 6, 2018
ce0fead
lint
suquark Dec 6, 2018
8af2703
replace the magic number
suquark Dec 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,9 @@ script:
- python -m pytest -v python/ray/rllib/test/test_optimizers.py
- python -m pytest -v python/ray/rllib/test/test_evaluators.py

# Python3.5+ only. Otherwise we will get `SyntaxError` regardless of how we set the tester.
- python -c 'import sys;exit(sys.version_info>=(3,5))' || python -m pytest -v python/ray/experimental/test/async_test.py

- python -m pytest -v python/ray/test/test_global_state.py
- python -m pytest -v python/ray/test/test_queue.py
- python -m pytest -v python/ray/test/test_ray_init.py
Expand Down
4 changes: 2 additions & 2 deletions cmake/Modules/ArrowExternalProject.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
# - PLASMA_SHARED_LIB

set(arrow_URL https://github.com/apache/arrow.git)
# The PR for this commit is https://github.com/apache/arrow/pull/3061. We
# The PR for this commit is https://github.com/apache/arrow/pull/3093. We
# include the link here to make it easier to find the right commit because
# Arrow often rewrites git history and invalidates certain commits.
set(arrow_TAG a667fca3b71772886bb2595986266d2039823dcc)
set(arrow_TAG 187b98ed338d4995317dae9efd19870c532192cb)

set(ARROW_INSTALL_PREFIX ${CMAKE_CURRENT_BINARY_DIR}/external/arrow-install)
set(ARROW_HOME ${ARROW_INSTALL_PREFIX})
Expand Down
87 changes: 87 additions & 0 deletions doc/source/async_api.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
Async API (Experimental)
========================

Since Python 3.5, it is possible to write concurrent code using the ``async/await`` `syntax <https://docs.python.org/3/library/asyncio.html>`__.

This document describes Ray's support for asyncio, which enables integration with popular async frameworks (e.g., aiohttp, aioredis, etc.) for high performance web and prediction serving.

Starting Ray
------------

You must initialize Ray first.

Please refer to `Starting Ray`_ for instructions.

.. _`Starting Ray`: http://ray.readthedocs.io/en/latest/tutorial.html#starting-ray


Converting Ray objects into asyncio futures
-------------------------------------------

Ray object IDs can be converted into asyncio futures with ``ray.experimental.async_api``.

.. code-block:: python

import asyncio
import time
import ray
from ray.experimental import async_api

@ray.remote
def f():
time.sleep(1)
return {'key1': ['value']}

ray.init()
future = async_api.as_future(f.remote())
asyncio.get_event_loop().run_until_complete(future) # {'key1': ['value']}


.. autofunction:: ray.experimental.async_api.as_future


Example Usage
-------------

+----------------------------------------+-----------------------------------------------------+
| **Basic Python** | **Distributed with Ray** |
+----------------------------------------+-----------------------------------------------------+
| .. code-block:: python | .. code-block:: python |
| | |
| # Execute f serially. | # Execute f in parallel. |
| | |
| | |
| def f(): | @ray.remote |
| time.sleep(1) | def f(): |
| return 1 | time.sleep(1) |
| | return 1 |
| | |
| | ray.init() |
| results = [f() for i in range(4)] | results = ray.get([f.remote() for i in range(4)]) |
+----------------------------------------+-----------------------------------------------------+
| **Async Python** | **Async Ray** |
+----------------------------------------+-----------------------------------------------------+
| .. code-block:: python | .. code-block:: python |
| | |
| # Execute f asynchronously. | # Execute f asynchronously with Ray/asyncio. |
| | |
| | from ray.experimental import async_api |
| | |
| | @ray.remote |
| async def f(): | def f(): |
| await asyncio.sleep(1) | time.sleep(1) |
| return 1 | return 1 |
| | |
| | ray.init() |
| loop = asyncio.get_event_loop() | loop = asyncio.get_event_loop() |
| tasks = [f() for i in range(4)] | tasks = [async_api.as_future(f.remote()) |
| | for i in range(4)] |
| results = loop.run_until_complete( | results = loop.run_until_complete( |
| asyncio.gather(tasks)) | asyncio.gather(tasks)) |
+----------------------------------------+-----------------------------------------------------+


Known Issues
------------

Async API support is experimental, and we are working to improve its performance. Please `let us know <https://github.com/ray-project/ray/issues>`__ any issues you encounter.
1 change: 1 addition & 0 deletions doc/source/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Ray comes with libraries that accelerate deep learning and reinforcement learnin
actors.rst
using-ray-with-gpus.rst
webui.rst
async_api.rst

.. toctree::
:maxdepth: 1
Expand Down
62 changes: 62 additions & 0 deletions python/ray/experimental/async_api.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
# Note: asyncio is only compatible with Python 3

import asyncio
import ray
from ray.experimental.async_plasma import PlasmaProtocol, PlasmaEventHandler

handler = None
transport = None
protocol = None


async def _async_init():
global handler, transport, protocol
if handler is None:
worker = ray.worker.global_worker
loop = asyncio.get_event_loop()
worker.plasma_client.subscribe()
rsock = worker.plasma_client.get_notification_socket()
handler = PlasmaEventHandler(loop, worker)
transport, protocol = await loop.create_connection(
lambda: PlasmaProtocol(worker.plasma_client, handler), sock=rsock)


def init():
"""
Initialize synchronously.
"""
loop = asyncio.get_event_loop()
if loop.is_running():
raise Exception("You must initialize the Ray async API by calling "
"async_api.init() or async_api.as_future(obj) before "
"the event loop starts.")
else:
asyncio.get_event_loop().run_until_complete(_async_init())


def as_future(object_id):
"""Turn an object_id into a Future object.

Args:
object_id: A Ray object_id.

Returns:
PlasmaObjectFuture: A future object that waits the object_id.
"""
if handler is None:
init()
return handler.as_future(object_id)


def shutdown():
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this

"""Manually shutdown the async API.

Cancels all related tasks and all the socket transportation.
"""
global handler, transport, protocol
if handler is not None:
handler.close()
transport.close()
handler = None
transport = None
protocol = None
Loading