class_docstr: Efficiently estimates the Ray serialized size of a stream of items.
  
  For efficiency, this only samples a fraction of the added items for real
  Ray-serialization.
class_docstr_tok: ["Efficiently","estimates","the","Ray","serialized","size","of","a","stream","of","items",".","For","efficiency",",","this","only","samples","a","fraction","of","the","added","items","for","real","Ray-serialization","."]
code: def _real_size(self, item: Any) -> int:
      is_client = ray.util.client.ray.is_connected()
      # In client mode, fallback to using Ray cloudpickle instead of the
      # real serializer.
      if is_client:
          return len(cloudpickle.dumps(item))
  
      # We're using an internal Ray API, and have to ensure it's
      # initialized # by calling a public API.
      global _ray_initialized
      if not _ray_initialized:
          _ray_initialized = True
          ray.put(None)
      return (
          ray._private.worker.global_worker.get_serialization_context()
          .serialize(item)
          .total_bytes
      )
  
file_path: ray/python/ray/data/_internal/size_estimator.py
imports: from typing import Any, List
  import ray
  from ray import cloudpickle
label_desc: Use image node_id 5 for calling the SizeEstimator obj's underlying member method code with example usage: obj._real_size(item) and returns: ray, len