mirror of
https://github.com/wassname/ray.git
synced 2026-07-27 11:26:41 +08:00
[Object Spilling] Delete spilled objects when references are gone out of scope. (#12341)
This commit is contained in:
@@ -54,6 +54,7 @@ from ray.includes.common cimport (
|
||||
CTaskType,
|
||||
CPlacementStrategy,
|
||||
CRayFunction,
|
||||
CWorkerType,
|
||||
move,
|
||||
LANGUAGE_CPP,
|
||||
LANGUAGE_JAVA,
|
||||
@@ -631,6 +632,46 @@ cdef void restore_spilled_objects_handler(
|
||||
job_id=None)
|
||||
|
||||
|
||||
cdef void delete_spilled_objects_handler(
|
||||
const c_vector[c_string]& object_urls,
|
||||
CWorkerType worker_type) nogil:
|
||||
with gil:
|
||||
urls = []
|
||||
size = object_urls.size()
|
||||
for i in range(size):
|
||||
urls.append(object_urls[i])
|
||||
try:
|
||||
# Get proctitle.
|
||||
if <int> worker_type == <int> WORKER_TYPE_SPILL_WORKER:
|
||||
original_proctitle = (
|
||||
ray_constants.WORKER_PROCESS_TYPE_SPILL_WORKER_IDLE)
|
||||
proctitle = (
|
||||
ray_constants.WORKER_PROCESS_TYPE_SPILL_WORKER_DELETE)
|
||||
elif <int> worker_type == <int> WORKER_TYPE_RESTORE_WORKER:
|
||||
original_proctitle = (
|
||||
ray_constants.WORKER_PROCESS_TYPE_RESTORE_WORKER_IDLE)
|
||||
proctitle = (
|
||||
ray_constants.WORKER_PROCESS_TYPE_RESTORE_WORKER_DELETE)
|
||||
else:
|
||||
assert False, ("This line shouldn't be reachable.")
|
||||
|
||||
# Delete objects.
|
||||
with ray.worker._changeproctitle(
|
||||
proctitle,
|
||||
original_proctitle):
|
||||
external_storage.delete_spilled_objects(urls)
|
||||
except Exception:
|
||||
exception_str = (
|
||||
"An unexpected internal error occurred while the IO worker "
|
||||
"was deleting spilled objects.")
|
||||
logger.exception(exception_str)
|
||||
ray.utils.push_error_to_driver(
|
||||
ray.worker.global_worker,
|
||||
"delete_spilled_objects_error",
|
||||
traceback.format_exc() + exception_str,
|
||||
job_id=None)
|
||||
|
||||
|
||||
# This function introduces ~2-7us of overhead per call (i.e., it can be called
|
||||
# up to hundreds of thousands of times per second).
|
||||
cdef void get_py_stack(c_string* stack_out) nogil:
|
||||
@@ -739,6 +780,7 @@ cdef class CoreWorker:
|
||||
options.gc_collect = gc_collect
|
||||
options.spill_objects = spill_objects_handler
|
||||
options.restore_spilled_objects = restore_spilled_objects_handler
|
||||
options.delete_spilled_objects = delete_spilled_objects_handler
|
||||
options.get_lang_stack = get_py_stack
|
||||
options.ref_counting_enabled = True
|
||||
options.is_local_mode = local_mode
|
||||
@@ -1473,6 +1515,10 @@ cdef class CoreWorker:
|
||||
def force_spill_objects(self, object_refs):
|
||||
cdef c_vector[CObjectID] object_ids
|
||||
object_ids = ObjectRefsToVector(object_refs)
|
||||
assert not RayConfig.instance().automatic_object_deletion_enabled(), (
|
||||
"Automatic object deletion is not supported for"
|
||||
"force_spill_objects yet. Please set"
|
||||
"automatic_object_deletion_enabled: False in Ray's system config.")
|
||||
with nogil:
|
||||
check_status(CCoreWorkerProcess.GetCoreWorker()
|
||||
.SpillObjects(object_ids))
|
||||
|
||||
Reference in New Issue
Block a user