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 int
getByteArraySizeByLength
(int length) static int
Works forMeasurable
objects and a small number of other types.static int
getSize
(byte[] bytes) static int
This function is imprecise in a couple of ways.static int
static int
Measure the heap usage ofKafkaMessageEnvelope
.static int
getSize
(ProducerMetadata producerMetadata) static int
static int
static int
getSize
(ByteBuffer byteBuffer)
-
Method Details
-
getObjectSize
Works forMeasurable
objects 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.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
-
getSize
Measure the heap usage ofKafkaMessageEnvelope
.
-