mirror of
https://github.com/wassname/ray.git
synced 2026-07-01 07:09:33 +08:00
5f88823c49
* Commit and format files * address stylistic concerns * Replcae "Usage" by "Example" in doc * Rename srv to serve * Add serve to CI process; Fix 3.5 compat * Improve determine_tests_to_run.py * Quick cosmetic for determien_tests * Address comments * Address comments * Address comment * Fix typos and grammar Co-Authored-By: Edward Oakes <ed.nmi.oakes@gmail.com> * Update python/ray/experimental/serve/global_state.py Co-Authored-By: Edward Oakes <ed.nmi.oakes@gmail.com> * Use __init__ for Query and WorkIntent class * Remove dataclasses dependency * Rename oid to object_id for clarity * Rename produce->enqueue_request, consume->dequeue_request * Address last round of comment
42 lines
932 B
Python
42 lines
932 B
Python
"""
|
|
Example of traffic splitting. We will first use echo:v1. Then v1 and v2
|
|
will split the incoming traffic evenly.
|
|
"""
|
|
import time
|
|
|
|
import requests
|
|
|
|
from ray.experimental import serve
|
|
from ray.experimental.serve.utils import pformat_color_json
|
|
|
|
|
|
def echo_v1(_):
|
|
return "v1"
|
|
|
|
|
|
def echo_v2(_):
|
|
return "v2"
|
|
|
|
|
|
serve.init(blocking=True)
|
|
|
|
serve.create_endpoint("my_endpoint", "/echo", blocking=True)
|
|
serve.create_backend(echo_v1, "echo:v1")
|
|
serve.link("my_endpoint", "echo:v1")
|
|
|
|
for _ in range(3):
|
|
resp = requests.get("http://127.0.0.1:8000/echo").json()
|
|
print(pformat_color_json(resp))
|
|
|
|
print("...Sleeping for 2 seconds...")
|
|
time.sleep(2)
|
|
|
|
serve.create_backend(echo_v2, "echo:v2")
|
|
serve.split("my_endpoint", {"echo:v1": 0.5, "echo:v2": 0.5})
|
|
while True:
|
|
resp = requests.get("http://127.0.0.1:8000/echo").json()
|
|
print(pformat_color_json(resp))
|
|
|
|
print("...Sleeping for 2 seconds...")
|
|
time.sleep(2)
|