def init(): ray.init(num_cpus=4) async_api.init() asyncio.get_event_loop().set_debug(False) yield async_api.shutdown() ray.shutdown()
def init(): os.environ["RAY_FORCE_DIRECT"] = "0" ray.init(num_cpus=4) async_api.init() asyncio.get_event_loop().set_debug(False) yield async_api.shutdown() ray.shutdown()
async def test_asyncio_get(ray_start_regular_shared, event_loop): loop = event_loop asyncio.set_event_loop(loop) loop.set_debug(True) # This is needed for async plasma from ray.experimental.async_api import init init() # Test Async Plasma @ray.remote def task(): return 1 assert await ray.async_compat.get_async(task.remote()) == 1 @ray.remote def task_throws(): 1 / 0 with pytest.raises(ray.exceptions.RayTaskError): await ray.async_compat.get_async(task_throws.remote()) # Test actor calls. str_len = 200 * 1024 @ray.remote class Actor: def echo(self, i): return i def big_object(self): # 100Kb is the limit for direct call return "a" * (str_len) def throw_error(self): 1 / 0 actor = Actor.remote() actor_call_future = ray.async_compat.get_async(actor.echo.remote(2)) assert await actor_call_future == 2 promoted_to_plasma_future = ray.async_compat.get_async( actor.big_object.remote()) assert await promoted_to_plasma_future == "a" * str_len with pytest.raises(ray.exceptions.RayTaskError): await ray.async_compat.get_async(actor.throw_error.remote())
) catalog_scrapper = CatalogScrapper(catalog) producer = asyncio.create_task(catalog.run()) consumer = asyncio.create_task(catalog_scrapper.run()) await asyncio.wait([producer, consumer]) from .pages import MissingPageDownloader, WatchPageScrapper pages = MissingPageDownloader( encoding=const.HTML_ENCODING, parallel_downloads=const.PAGES_PARALLEL_CONNECTIONS, retry_after=const.RETRY_AFTER, results_queue_maxsize=const.PAGES_PARSE_QUEUE, ) pages_scrapper = WatchPageScrapper(pages) producer = asyncio.create_task(pages.run()) consumer = asyncio.create_task(pages_scrapper.run()) await asyncio.wait([producer, consumer]) if __name__ == '__main__': import asyncio from ray.experimental import async_api as ray_async import ray ray.init(memory=1 / 2 * 1024 * 1024 * 1024, object_store_memory=1 / 2 * 1024 * 1024 * 1024) ray_async.init() asyncio.get_event_loop().run_until_complete(main())
) asyncio.set_event_loop_policy(uvloop.EventLoopPolicy()) previous_time = time.perf_counter() def log_with_timestamp(msg): global previous_time now = time.perf_counter() print(f"[delta_ms={(now-previous_time)*1000}] {msg}") previous_time = now ray.init() async_api.init() # Creating QueryFrontend batchsize = 1 query_frontend = QueryFrontend.remote(batchsize) query_frontend.loop.remote(query_frontend) register_actor("query_frontend", query_frontend) n_replicas = 3 query_frontend.add_model.remote("preprocess", ArmadaPreprocessModel) for i in range(n_replicas): query_frontend.add_model.remote(f"squeezenet_{i}", ArmadaSqueezenetModel) query_frontend.add_model.remote("ensemble", ArmadaAverageEnsembleModel) input_image = np.random.randn(1, 224, 224, 3)