Reuse code of checking large pickles (#2291)

This commit is contained in:
Hao Chen
2018-06-29 10:51:23 +08:00
committed by Robert Nishihara
parent cd63804768
commit 20c0ecb522
3 changed files with 43 additions and 41 deletions
+25
View File
@@ -268,3 +268,28 @@ def merge_dicts(d1, d2):
d = d1.copy()
d.update(d2)
return d
def check_oversized_pickle(pickled, name, obj_type, worker):
"""Send a warning message if the pickled object is too large.
Args:
pickled: the pickled object.
name: name of the pickled object.
obj_type: type of the pickled object, can be 'function',
'remote function', 'actor', or 'object'.
worker: the worker used to send warning message.
"""
length = len(pickled)
if length <= ray_constants.PICKLE_OBJECT_WARNING_SIZE:
return
warning_message = (
"Warning: The {} {} has size {} when pickled. "
"It will be stored in Redis, which could cause memory issues. "
"This may mean that its definition uses a large array or other object."
).format(obj_type, name, length)
push_error_to_driver(
worker,
ray_constants.PICKLING_LARGE_OBJECT_PUSH_ERROR,
warning_message,
driver_id=worker.task_driver_id.id())