Unverified Commit 04bbf38e authored by Tyler Michael Smith's avatar Tyler Michael Smith Committed by GitHub
Browse files

[Core] Use os.sched_yield in ShmRingBuffer instead of time.sleep (#9994)


Signed-off-by: default avatarTyler Michael Smith <tyler@neuralmagic.com>
parent 8f0a9ca8
import os
import pickle import pickle
import time import time
from contextlib import contextmanager from contextlib import contextmanager
...@@ -18,12 +19,6 @@ from vllm.utils import get_ip, get_open_port, is_valid_ipv6_address ...@@ -18,12 +19,6 @@ from vllm.utils import get_ip, get_open_port, is_valid_ipv6_address
VLLM_RINGBUFFER_WARNING_INTERVAL = envs.VLLM_RINGBUFFER_WARNING_INTERVAL VLLM_RINGBUFFER_WARNING_INTERVAL = envs.VLLM_RINGBUFFER_WARNING_INTERVAL
# time to wait if the queue is full or empty
# if we sleep for too short, it will consume too much CPU
# if we sleep for too long, it will slow down the writer/reader
# 0.1 us is a good balance
RINGBUFFER_SLEEP_INTERVAL = 1e-7
logger = init_logger(__name__) logger = init_logger(__name__)
...@@ -333,8 +328,8 @@ class MessageQueue: ...@@ -333,8 +328,8 @@ class MessageQueue:
# if this block is not ready to write, # if this block is not ready to write,
# we need to wait until it is read by all readers # we need to wait until it is read by all readers
# wait for a while # Release the processor to other threads
time.sleep(RINGBUFFER_SLEEP_INTERVAL) os.sched_yield()
# if we wait for a long time, we should warn the user # if we wait for a long time, we should warn the user
if (time.monotonic() - start_time > if (time.monotonic() - start_time >
...@@ -387,8 +382,8 @@ class MessageQueue: ...@@ -387,8 +382,8 @@ class MessageQueue:
# if this block is not ready, # if this block is not ready,
# we need to wait until it is written # we need to wait until it is written
# wait for a while # Release the processor to other threads
time.sleep(RINGBUFFER_SLEEP_INTERVAL) os.sched_yield()
# if we wait for a long time, we should warn the user # if we wait for a long time, we should warn the user
if (time.monotonic() - start_time > if (time.monotonic() - start_time >
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment