Package com.linkedin.venice.memory
Class InstanceSizeEstimator
- java.lang.Object
-
- com.linkedin.venice.memory.InstanceSizeEstimator
-
public class InstanceSizeEstimator extends java.lang.Object
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 implementMeasurable
and write the logic inMeasurable.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
All Methods Static Methods Concrete Methods Modifier and Type Method Description static int
getByteArraySizeByLength(int length)
static int
getObjectSize(java.lang.Object o)
Works forMeasurable
objects and a small number of other types.static int
getSize(byte[] bytes)
static int
getSize(ControlMessage cm)
This function is imprecise in a couple of ways.static int
getSize(Delete delete)
static int
getSize(KafkaMessageEnvelope kme)
Measure the heap usage ofKafkaMessageEnvelope
.static int
getSize(ProducerMetadata producerMetadata)
static int
getSize(Put put)
static int
getSize(Update update)
static int
getSize(java.nio.ByteBuffer byteBuffer)
-
-
-
Method Detail
-
getObjectSize
public static int getObjectSize(@Nonnull java.lang.Object o)
Works forMeasurable
objects and a small number of other types. Not intended as a generic utility for any instance type!- Throws:
java.lang.IllegalArgumentException
- when an unsupported type is passed.
-
getByteArraySizeByLength
public static int getByteArraySizeByLength(int length)
-
getSize
public static int getSize(@Nonnull byte[] bytes)
-
getSize
public static int getSize(java.nio.ByteBuffer byteBuffer)
-
getSize
public static int getSize(@Nonnull ProducerMetadata producerMetadata)
-
getSize
public static int getSize(@Nonnull Put put)
-
getSize
public static int getSize(@Nonnull Delete delete)
-
getSize
public static int getSize(@Nonnull ControlMessage cm)
This function is imprecise in a couple of ways. TheControlMessage.controlMessageUnion
field is treated as shallow, which in some cases is false (e.g. if a compression dictionary were present), and theControlMessage.debugInfo
is ignored (i.e. treated as null). We can be more precise by looking at theControlMessage.controlMessageType
and 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
public static int getSize(@Nonnull Update update)
-
getSize
public static int getSize(KafkaMessageEnvelope kme)
Measure the heap usage ofKafkaMessageEnvelope
.
-
-