Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/cassandra.in.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ if [ -f "$CASSANDRA_HOME"/lib/jsr223/scala/scala-compiler.jar ] ; then
fi

# set JVM javaagent opts to avoid warnings/errors
JAVA_AGENT="$JAVA_AGENT -javaagent:$CASSANDRA_HOME/lib/jamm-0.3.2.jar"
JAVA_AGENT="$JAVA_AGENT -javaagent:$CASSANDRA_HOME/lib/jamm-0.4.0.jar"

# Added sigar-bin to the java.library.path CASSANDRA-7838
JAVA_OPTS="$JAVA_OPTS:-Djava.library.path=$CASSANDRA_HOME/lib/sigar-bin"
Expand Down
2 changes: 1 addition & 1 deletion build.xml
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@
<property name="jacoco.version" value="0.8.12"/>

<property name="byteman.version" value="4.0.23"/>
<property name="jamm.version" value="0.3.2"/>
<property name="jamm.version" value="0.4.0"/>
<property name="ecj.version" value="3.33.0"/>
<property name="ohc.version" value="0.5.1"/>
<property name="asm.version" value="7.1"/>
Expand Down
2 changes: 1 addition & 1 deletion conf/cassandra-env.sh
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ fi
JVM_OPTS="$JVM_OPTS -XX:CompileCommandFile=$CASSANDRA_CONF/hotspot_compiler"

# add the jamm javaagent
JVM_OPTS="$JVM_OPTS -javaagent:$CASSANDRA_HOME/lib/jamm-0.3.2.jar"
JVM_OPTS="$JVM_OPTS -javaagent:$CASSANDRA_HOME/lib/jamm-0.4.0.jar"

# set jvm HeapDumpPath with CASSANDRA_HEAPDUMP_DIR
if [ "x$CASSANDRA_HEAPDUMP_DIR" != "x" ]; then
Expand Down
2 changes: 1 addition & 1 deletion redhat/cassandra.in.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ CLASSPATH="$CLASSPATH:$EXTRA_CLASSPATH"


# set JVM javaagent opts to avoid warnings/errors
JAVA_AGENT="$JAVA_AGENT -javaagent:$CASSANDRA_HOME/lib/jamm-0.3.2.jar"
JAVA_AGENT="$JAVA_AGENT -javaagent:$CASSANDRA_HOME/lib/jamm-0.4.0.jar"


#
Expand Down
7 changes: 6 additions & 1 deletion src/java/org/apache/cassandra/audit/BinAuditLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,11 @@ public void log(AuditLogEntry auditLogEntry)
@VisibleForTesting
public static class Message extends BinLog.ReleaseableWriteMarshallable implements WeightedQueue.Weighable
{
/**
* The shallow size of a {@code Message} object.
*/
private static final long EMPTY_SIZE = ObjectSizes.measure(new Message(""));

private final String message;

public Message(String message)
Expand Down Expand Up @@ -128,7 +133,7 @@ public void release()
@Override
public int weight()
{
return Ints.checkedCast(ObjectSizes.sizeOf(message));
return Ints.checkedCast(EMPTY_SIZE + ObjectSizes.sizeOf(message));
}
}
}
2 changes: 1 addition & 1 deletion src/java/org/apache/cassandra/cql3/ColumnIdentifier.java
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ public long unsharedHeapSize()
public long unsharedHeapSizeExcludingData()
{
return EMPTY_SIZE
+ ObjectSizes.sizeOnHeapExcludingData(bytes)
+ ObjectSizes.sizeOnHeapExcludingDataOf(bytes)
+ ObjectSizes.sizeOf(text);
}

Expand Down
2 changes: 1 addition & 1 deletion src/java/org/apache/cassandra/db/BufferClustering.java
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public long unsharedHeapSizeExcludingData()
{
if (this == Clustering.EMPTY || this == Clustering.STATIC_CLUSTERING)
return 0;
return EMPTY_SIZE + ObjectSizes.sizeOnHeapExcludingData(values);
return EMPTY_SIZE + ObjectSizes.sizeOnHeapExcludingDataOf(values);
}

public static BufferClustering make(ByteBuffer... values)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ private static int estimateRowOverhead(final int count)
final Object val = new Object();
for (int i = 0 ; i < count ; i++)
partitions.put(cloner.clone(new BufferDecoratedKey(new LongToken(i), HeapCloner.instance.allocate(1))), val);
double avgSize = ObjectSizes.measureDeep(partitions) / (double) count;
double avgSize = ObjectSizes.measureDeepOmitShared(partitions) / (double) count;
rowOverhead = (int) ((avgSize - Math.floor(avgSize)) < 0.05 ? Math.floor(avgSize) : Math.ceil(avgSize));
rowOverhead -= ObjectSizes.measureDeep(new LongToken(0));
if (!(allocator instanceof NativeAllocator))
Expand Down
2 changes: 1 addition & 1 deletion src/java/org/apache/cassandra/db/rows/BufferCell.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,6 @@ public Cell<?> clone(ByteBufferCloner cloner)

public long unsharedHeapSizeExcludingData()
{
return EMPTY_SIZE + ObjectSizes.sizeOnHeapExcludingData(value) + (path == null ? 0 : path.unsharedHeapSizeExcludingData());
return EMPTY_SIZE + ObjectSizes.sizeOnHeapExcludingDataOf(value) + (path == null ? 0 : path.unsharedHeapSizeExcludingData());
}
}
2 changes: 1 addition & 1 deletion src/java/org/apache/cassandra/db/rows/CellPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ public CellPath clone(ByteBufferCloner cloner)

public long unsharedHeapSizeExcludingData()
{
return EMPTY_SIZE + ObjectSizes.sizeOnHeapExcludingData(value);
return EMPTY_SIZE + ObjectSizes.sizeOnHeapExcludingDataOf(value);
}
}

Expand Down
5 changes: 3 additions & 2 deletions src/java/org/apache/cassandra/db/tries/InMemoryTrie.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.apache.cassandra.utils.ObjectSizes;
import org.apache.cassandra.utils.concurrent.OpOrder;
import org.github.jamm.MemoryLayoutSpecification;
import org.github.jamm.MemoryMeterStrategy;

/**
* In-memory trie built for fast modification and reads executing concurrently with writes from a single mutator thread.
Expand Down Expand Up @@ -1705,7 +1706,7 @@ private long usedBufferSpace()

private long usedObjectSpace()
{
return (contentCount - objectAllocator.indexCountInPipeline()) * MemoryLayoutSpecification.SPEC.getReferenceSize();
return (contentCount - objectAllocator.indexCountInPipeline()) * MemoryMeterStrategy.MEMORY_LAYOUT.getReferenceSize();
}

/**
Expand All @@ -1731,7 +1732,7 @@ public long unusedReservedOnHeapMemory()
AtomicReferenceArray<T> contentArray = contentArrays[leadBit];
int contentOverhead = ((contentArray != null ? contentArray.length() : 0) - ofs);
contentOverhead += objectAllocator.indexCountInPipeline();
contentOverhead *= MemoryLayoutSpecification.SPEC.getReferenceSize();
contentOverhead *= MemoryMeterStrategy.MEMORY_LAYOUT.getReferenceSize();

return bufferOverhead + contentOverhead;
}
Expand Down
91 changes: 66 additions & 25 deletions src/java/org/apache/cassandra/fql/FullQueryLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -84,9 +84,6 @@ public class FullQueryLogger implements QueryEvents.Listener
private static final int EMPTY_LIST_SIZE = Ints.checkedCast(ObjectSizes.measureDeep(new ArrayList<>(0)));
private static final int EMPTY_BYTEBUF_SIZE;

private static final int OBJECT_HEADER_SIZE = MemoryLayoutSpecification.SPEC.getObjectHeaderSize();
private static final int OBJECT_REFERENCE_SIZE = MemoryLayoutSpecification.SPEC.getReferenceSize();

public static final FullQueryLogger instance = new FullQueryLogger();

volatile BinLog binLog;
Expand Down Expand Up @@ -331,6 +328,11 @@ public void executeSuccess(CQLStatement statement, String query, QueryOptions op

public static class Query extends AbstractLogEntry
{
/**
* The shallow size of a {@code Query} object.
*/
private static final long EMPTY_SIZE = ObjectSizes.measure(new Query());

private final String query;

public Query(String query, QueryOptions queryOptions, QueryState queryState, long queryStartTime)
Expand All @@ -339,6 +341,14 @@ public Query(String query, QueryOptions queryOptions, QueryState queryState, lon
this.query = query;
}

/**
* Constructor only use to compute this class shallow size.
*/
private Query()
{
this.query = null;
}

@Override
protected String type()
{
Expand All @@ -355,12 +365,21 @@ public void writeMarshallablePayload(WireOut wire)
@Override
public int weight()
{
return Ints.checkedCast(ObjectSizes.sizeOf(query)) + super.weight();
// Object deep size = Object' shallow size + query field deep size + deep size of the parent fields
return Ints.checkedCast(EMPTY_SIZE + ObjectSizes.sizeOf(query) + super.fieldsSize());
}
}

public static class Batch extends AbstractLogEntry
{
/**
* The shallow size of a {@code Batch} object (which includes primitive fields).
*/
private static final long EMPTY_SIZE = ObjectSizes.measure(new Batch());

/**
* The weight is pre-computed in the constructor and represent the object deep size.
*/
private final int weight;
private final BatchStatement.Type batchType;
private final List<String> queries;
Expand All @@ -379,25 +398,37 @@ public Batch(BatchStatement.Type batchType,
this.values = values;
this.batchType = batchType;

int weight = super.weight();

// weight, queries, values, batch type
weight += Integer.BYTES + // cached weight
2 * EMPTY_LIST_SIZE + // queries + values lists
3 * OBJECT_REFERENCE_SIZE; // batchType and two lists references
// We assume that all the lists are ArrayLists and that the size of each underlying array is the one of the list
// (which is obviously wrong but not worst than the previous computation that was ignoring part of the arrays size in the computation).
long queriesSize = EMPTY_LIST_SIZE + ObjectSizes.sizeOfReferenceArray(queries.size());

for (String query : queries)
weight += ObjectSizes.sizeOf(checkNotNull(query)) + OBJECT_REFERENCE_SIZE;
queriesSize += ObjectSizes.sizeOf(checkNotNull(query));

long valuesSize = EMPTY_LIST_SIZE + ObjectSizes.sizeOfReferenceArray(values.size());
for (List<ByteBuffer> subValues : values)
{
weight += EMPTY_LIST_SIZE + OBJECT_REFERENCE_SIZE;

for (ByteBuffer value : subValues)
weight += ObjectSizes.sizeOnHeapOf(value) + OBJECT_REFERENCE_SIZE;
valuesSize += EMPTY_LIST_SIZE + ObjectSizes.sizeOfReferenceArray(subValues.size());
for (ByteBuffer subValue : subValues)
valuesSize += ObjectSizes.sizeOnHeapOf(subValue);
}

this.weight = weight;
// No need to add the batch type which is an enum.
this.weight = Ints.checkedCast(EMPTY_SIZE // Shallow size object
+ super.fieldsSize() // deep size of the parent fields (non-primitives as they are included in the shallow size)
+ queriesSize // deep size queries field
+ valuesSize); // deep size values field
}

/**
* Constructor only use to compute this class shallow size.
*/
private Batch()
{
this.weight = 0;
this.batchType = null;
this.queries = null;
this.values = null;
}

@Override
Expand Down Expand Up @@ -482,6 +513,18 @@ private static abstract class AbstractLogEntry extends BinLog.ReleaseableWriteMa
}
}

/**
* Constructor only use to compute sub-classes shallow size.
*/
private AbstractLogEntry()
{
this.queryStartTime = 0;
this.protocolVersion = 0;
this.queryOptionsBuffer = null;
this.generatedTimestamp = 0;
this.generatedNowInSeconds = 0;
this.keyspace = null;
}
@Override
protected long version()
{
Expand All @@ -507,16 +550,14 @@ public void release()
queryOptionsBuffer.release();
}

@Override
public int weight()
/**
* Returns the sum of the non-primitive fields' deep sizes.
* @return the sum of the non-primitive fields' deep sizes.
*/
protected long fieldsSize()
{
return OBJECT_HEADER_SIZE
+ Long.BYTES // queryStartTime
+ Integer.BYTES // protocolVersion
+ OBJECT_REFERENCE_SIZE + EMPTY_BYTEBUF_SIZE + queryOptionsBuffer.capacity() // queryOptionsBuffer
+ Long.BYTES // generatedTimestamp
+ Integer.BYTES // generatedNowInSeconds
+ OBJECT_REFERENCE_SIZE + Ints.checkedCast(ObjectSizes.sizeOf(keyspace)); // keyspace
return EMPTY_BYTEBUF_SIZE + queryOptionsBuffer.capacity() // queryOptionsBuffer
+ ObjectSizes.sizeOf(keyspace); // keyspace
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.carrotsearch.hppc.IntLongMap;
import org.apache.cassandra.index.sai.disk.io.IndexInputReader;
import org.apache.cassandra.io.util.FileHandle;
import org.apache.cassandra.utils.ObjectSizes;
import org.github.jamm.MemoryLayoutSpecification;

import static com.google.common.base.Preconditions.checkArgument;
Expand Down Expand Up @@ -57,13 +58,6 @@ class BKDPostingsIndex
}
}

public long memoryUsage()
{
// IntLongHashMap uses two arrays: one for keys, one for values.
return MemoryLayoutSpecification.sizeOfArray(index.size(), 4L)
+ MemoryLayoutSpecification.sizeOfArray(index.size(), 8L);
}

/**
* Returns <tt>true</tt> if given node ID has an auxiliary posting list.
*/
Expand Down
Loading
Loading