mirror of
https://github.com/wassname/ray.git
synced 2026-07-04 01:58:30 +08:00
Fix serve dependencies (#9192)
This commit is contained in:
@@ -2,12 +2,24 @@
|
||||
Example service that prints out http context.
|
||||
"""
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
from pygments import formatters, highlight, lexers
|
||||
|
||||
import requests
|
||||
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def pformat_color_json(d):
|
||||
"""Use pygments to pretty format and colorize dictionary"""
|
||||
formatted_json = json.dumps(d, sort_keys=True, indent=4)
|
||||
|
||||
colorful_json = highlight(formatted_json, lexers.JsonLexer(),
|
||||
formatters.TerminalFormatter())
|
||||
|
||||
return colorful_json
|
||||
|
||||
|
||||
def echo(flask_request):
|
||||
|
||||
@@ -5,13 +5,25 @@ come from either web (parsing Flask request) or python call.
|
||||
This actor can be called from HTTP as well as from Python.
|
||||
"""
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
from pygments import formatters, highlight, lexers
|
||||
|
||||
import requests
|
||||
|
||||
import ray
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def pformat_color_json(d):
|
||||
"""Use pygments to pretty format and colorize dictionary"""
|
||||
formatted_json = json.dumps(d, sort_keys=True, indent=4)
|
||||
|
||||
colorful_json = highlight(formatted_json, lexers.JsonLexer(),
|
||||
formatters.TerminalFormatter())
|
||||
|
||||
return colorful_json
|
||||
|
||||
|
||||
class MagicCounter:
|
||||
|
||||
@@ -5,13 +5,25 @@ The queries incoming to this actor are batched.
|
||||
This actor can be called from HTTP as well as from Python.
|
||||
"""
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
from pygments import formatters, highlight, lexers
|
||||
|
||||
import requests
|
||||
|
||||
import ray
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def pformat_color_json(d):
|
||||
"""Use pygments to pretty format and colorize dictionary"""
|
||||
formatted_json = json.dumps(d, sort_keys=True, indent=4)
|
||||
|
||||
colorful_json = highlight(formatted_json, lexers.JsonLexer(),
|
||||
formatters.TerminalFormatter())
|
||||
|
||||
return colorful_json
|
||||
|
||||
|
||||
class MagicCounter:
|
||||
|
||||
@@ -13,13 +13,25 @@ This shows that error is hidden from HTTP side but always visible when calling
|
||||
from Python.
|
||||
"""
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
from pygments import formatters, highlight, lexers
|
||||
|
||||
import requests
|
||||
|
||||
import ray
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def pformat_color_json(d):
|
||||
"""Use pygments to pretty format and colorize dictionary"""
|
||||
formatted_json = json.dumps(d, sort_keys=True, indent=4)
|
||||
|
||||
colorful_json = highlight(formatted_json, lexers.JsonLexer(),
|
||||
formatters.TerminalFormatter())
|
||||
|
||||
return colorful_json
|
||||
|
||||
|
||||
def echo(_):
|
||||
|
||||
@@ -1,47 +0,0 @@
|
||||
"""
|
||||
Example showing fixed packing policy. The outputs from
|
||||
v1 and v2 will be coming according to packing_num specified!
|
||||
This is a packed round robin example. First batch of packing_num
|
||||
(five in this example) queries would go to 'echo:v1' backend and
|
||||
then next batch of packing_num queries would go to 'echo:v2'
|
||||
backend.
|
||||
"""
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def echo_v1(_):
|
||||
return "v1"
|
||||
|
||||
|
||||
def echo_v2(_):
|
||||
return "v2"
|
||||
|
||||
|
||||
# specify the router policy as FixedPacking with packing num as 5
|
||||
serve.init(
|
||||
queueing_policy=serve.RoutePolicy.FixedPacking,
|
||||
policy_kwargs={"packing_num": 5})
|
||||
|
||||
# create first backend
|
||||
serve.create_backend("echo:v1", echo_v1)
|
||||
|
||||
# create service backed by the first backend
|
||||
serve.create_endpoint("my_endpoint", backend="echo:v1", route="/echo")
|
||||
|
||||
# create second backend
|
||||
serve.create_backend("echo:v2", echo_v2)
|
||||
|
||||
# split the service between the two backends
|
||||
serve.set_traffic("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)
|
||||
@@ -2,13 +2,26 @@
|
||||
Full example of ray.serve module
|
||||
"""
|
||||
|
||||
import json
|
||||
import time
|
||||
|
||||
from pygments import formatters, highlight, lexers
|
||||
|
||||
import requests
|
||||
|
||||
import ray
|
||||
import ray.serve as serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def pformat_color_json(d):
|
||||
"""Use pygments to pretty format and colorize dictionary"""
|
||||
formatted_json = json.dumps(d, sort_keys=True, indent=4)
|
||||
|
||||
colorful_json = highlight(formatted_json, lexers.JsonLexer(),
|
||||
formatters.TerminalFormatter())
|
||||
|
||||
return colorful_json
|
||||
|
||||
|
||||
# initialize ray serve system.
|
||||
serve.init()
|
||||
|
||||
@@ -1,41 +0,0 @@
|
||||
"""
|
||||
Example showing round robin policy. The outputs from
|
||||
v1 and v2 will be (almost) interleaved as queries get processed.
|
||||
"""
|
||||
import time
|
||||
|
||||
import requests
|
||||
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def echo_v1(_):
|
||||
return "v1"
|
||||
|
||||
|
||||
def echo_v2(_):
|
||||
return "v2"
|
||||
|
||||
|
||||
# specify the router policy as RoundRobin
|
||||
serve.init(queueing_policy=serve.RoutePolicy.RoundRobin)
|
||||
|
||||
# create first backend
|
||||
serve.create_backend("echo:v1", echo_v1)
|
||||
|
||||
# create a service backend by the first backend
|
||||
serve.create_endpoint("my_endpoint", backend="echo:v1", route="/echo")
|
||||
|
||||
# create second backend
|
||||
serve.create_backend("echo:v2", echo_v2)
|
||||
|
||||
# split the service between the two backends
|
||||
serve.set_traffic("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)
|
||||
@@ -2,12 +2,24 @@
|
||||
Example of traffic splitting. We will first use echo:v1. Then v1 and v2
|
||||
will split the incoming traffic evenly.
|
||||
"""
|
||||
import json
|
||||
import time
|
||||
|
||||
from pygments import formatters, highlight, lexers
|
||||
|
||||
import requests
|
||||
|
||||
from ray import serve
|
||||
from ray.serve.utils import pformat_color_json
|
||||
|
||||
|
||||
def pformat_color_json(d):
|
||||
"""Use pygments to pretty format and colorize dictionary"""
|
||||
formatted_json = json.dumps(d, sort_keys=True, indent=4)
|
||||
|
||||
colorful_json = highlight(formatted_json, lexers.JsonLexer(),
|
||||
formatters.TerminalFormatter())
|
||||
|
||||
return colorful_json
|
||||
|
||||
|
||||
def echo_v1(_):
|
||||
|
||||
@@ -10,7 +10,6 @@ import io
|
||||
import os
|
||||
|
||||
import requests
|
||||
from pygments import formatters, highlight, lexers
|
||||
|
||||
import ray
|
||||
from ray.serve.constants import HTTP_PROXY_TIMEOUT
|
||||
@@ -79,16 +78,6 @@ class ServeEncoder(json.JSONEncoder):
|
||||
return super().default(o)
|
||||
|
||||
|
||||
def pformat_color_json(d):
|
||||
"""Use pygments to pretty format and colroize dictionary"""
|
||||
formatted_json = json.dumps(d, sort_keys=True, indent=4)
|
||||
|
||||
colorful_json = highlight(formatted_json, lexers.JsonLexer(),
|
||||
formatters.TerminalFormatter())
|
||||
|
||||
return colorful_json
|
||||
|
||||
|
||||
def block_until_http_ready(http_endpoint,
|
||||
backoff_time_s=1,
|
||||
timeout=HTTP_PROXY_TIMEOUT):
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@ if "RAY_USE_NEW_GCS" in os.environ and os.environ["RAY_USE_NEW_GCS"] == "on":
|
||||
extras = {
|
||||
"debug": [],
|
||||
"dashboard": ["requests", "gpustat"],
|
||||
"serve": ["uvicorn", "flask", "blist"],
|
||||
"serve": ["uvicorn", "flask", "blist", "requests"],
|
||||
"tune": ["tabulate", "tensorboardX", "pandas"]
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user