Skip to content

Instantly share code, notes, and snippets.

@tueda
Created September 13, 2024 02:53
Show Gist options
  • Save tueda/ad0aed286bc0e08fa50c2f3f5a0d5784 to your computer and use it in GitHub Desktop.
Save tueda/ad0aed286bc0e08fa50c2f3f5a0d5784 to your computer and use it in GitHub Desktop.
import time
import ray
delay = 0.01
context = ray.init()
num_cpus = ray.available_resources()["CPU"]
def busy_wait(duration):
time_perf_counter = time.perf_counter
start_time = time_perf_counter()
while (time_perf_counter() - start_time) < duration:
pass
@ray.remote
def f():
busy_wait(delay)
return 1
@ray.remote
def g():
return sum(ray.get([f.remote() for _ in range(200)]))
print(sum(ray.get([g.remote() for _ in range(500)])) * delay / num_cpus)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment