Package com.linkedin.venice.memory
Class InstanceSizeEstimator
java.lang.Object
com.linkedin.venice.memory.InstanceSizeEstimator
This utility class provides functions to measure the heap size of objects for a limited number of classes. Wherever
possible, the logic makes use of knowledge of the Venice code so that shared or static instances are ignored (i.e.,
assuming that their amortized cost is negligible). The code here should all be hot path friendly, and make no use of
reflection (except in static constants).
If more classes require heap size measurement, the preferred approach is NOT to add code into this class! Rather, the
preferred approach is to implement
Measurable and write the logic in Measurable.getHeapSize(). This
utility class is for cases where we wish to measure classes that we cannot modify, such as those coming from the JDK,
from third-party libraries, or from code-gen.-
Method Summary
Modifier and TypeMethodDescriptionstatic intgetByteArraySizeByLength(int length) static intWorks forMeasurableobjects and a small number of other types.static intgetSize(byte[] bytes) static intThis function is imprecise in a couple of ways.static intstatic intMeasure the heap usage ofKafkaMessageEnvelope.static intgetSize(ProducerMetadata producerMetadata) static intstatic intstatic intgetSize(ByteBuffer byteBuffer)
-
Method Details
-
getObjectSize
Works forMeasurableobjects and a small number of other types. Not intended as a generic utility for any instance type!- Throws:
IllegalArgumentException- when an unsupported type is passed.
-
getByteArraySizeByLength
public static int getByteArraySizeByLength(int length) -
getSize
public static int getSize(@Nonnull byte[] bytes) -
getSize
-
getSize
-
getSize
-
getSize
-
getSize
This function is imprecise in a couple of ways. TheControlMessage.controlMessageUnionfield is treated as shallow, which in some cases is false (e.g. if a compression dictionary were present), and theControlMessage.debugInfois ignored (i.e. treated as null). We can be more precise by looking at theControlMessage.controlMessageTypeand then providing the precise overhead based on each type, but we're skipping this work for now since, in our use case, control messages should be a negligible fraction of all messages, and therefore not that important to get exactly right. -
getSize
-
getSize
Measure the heap usage ofKafkaMessageEnvelope.
-