I’m working on a small research project to investigate differences in performance for similar workloads on Ray Serve vs simply scheduling ray.remote tasks.
I have a very simple function that evaluates mathematical functions, and I generate a few random functions that force computation (recursive fibonacci and factorial functions).
The code in Ray Serve looks roughly like this (please disregard the obvious security vulnerability :):
@serve.deployment(num_replicas=8)
def evaluar(request):
def fib(n):
if n<= 1:
return n
else:
return fib(n-1)+ fib(n-2)
def fac(n):
res = 1
for i in range (1,n+1):
res*= i
return res
op = request.url.path.split("evaluar/")[-1]
return eval(op)
evaluar.deploy()
async def loadtest_async(num_operaciones=200):
async with aiohttp.ClientSession() as session:
for _ in range(num_operaciones):
op = generate_operation()
deploy_url = f'http://127.0.0.1:8000/evaluar/{op}'
async with session.get(deploy_url) as resp:
deploy_url = await resp.json()
asyncio.run(loadtest_async())
I run a similar workload, except that the remote calls are done directly using ray.remote calls, instead of scheduling the computation with Ray Serve. Something like this:
@ray.remote
def evaluador(op):
def fib(n):
if n<= 1:
return n
else:
return fib(n-1)+ fib(n-2)
def fac(n):
res = 1
for i in range (1,n+1):
res*= i
return res
return eval(op)
ray.get([ray_evaluador.remote(generate_operation()) for _ in range(200)])
When running each workloadin ray, I see that the CPU usage is very different for each workload:
- The first workload (with Ray Serve) reaches CPU usage average of less than 10%
- The second workload (direct Ray Remote calls) reaches very high CPU usage above 90% on all cores
What could explain this difference?
Note: I’m running this on my laptop with 8 threads.