Skip to main content
Version: 6.0-SNAPSHOT

Reading Map Metrics

By default, you can read metrics for a given map, such as the primary and backup entry count, last update time, and locked entry count on each member of your cluster. You can access these statistics for the entire map, for the map entries on a specific cluster member, or specific map entries.

Getting Statistics about All Map Entries​

To get statistics for all map entries that are owned by a member, use the getLocalMapStats() method of the Java member API (embedded mode). This method returns data only if the statistics-enabled element is set to true, which is the default.

note

If you disable map statistics, statistics will not be available via the API, or in Hazelcast Management Center.

xml
<hazelcast>
...
<map name="myMap">
<statistics-enabled>true</statistics-enabled>
</map>
...
</hazelcast>
java
LocalMapStats mapStatistics = myMap.getLocalMapStats();
System.out.println( "Number of entries owned by this member = "
+ mapStatistics.getOwnedEntryCount() );
note

If you need cluster-wide map statistics, you can get the local map statistics from all members of the cluster and combine them. Alternatively, you can see all map statistics in Hazelcast Management Center.

Getting Statistics about a Specific Map Entry​

To get statistics for a specific map entry, you can use the getEntryView(key) method of one of the following available client libraries. To use this method, the map must have its per-entry-stats-enabled element set to true.

This method returns the following statistics:

StatisticDescription
costCost (in bytes) of the entry.
creationTimeCreation time of the entry.
expirationTimeExpiration time of the entry.
hitsNumber of hits of the entry.
keyKey of the entry.
lastAccessTimeLast access time for the entry.
lastStoredTimeLast time the value was saved to a MapStore.
lastUpdateTimeLast time the value was updated.
maxIdleLast set max idle time in milliseconds.
ttlLast set time-to-live in milliseconds.
valueValue of the entry.
versionVersion of the entry.
xml
<hazelcast>
...
<map name="myMap">
<per-entry-stats-enabled>true</per-entry-stats-enabled>
</map>
...
</hazelcast>
java
HazelcastInstance hz = Hazelcast.newHazelcastInstance();

EntryView entry = hz.getMap( "quotes" ).getEntryView( "key" );

System.out.println ( "size in memory : " + entry.getCost() );
System.out.println ( "creationTime : " + entry.getCreationTime() );
System.out.println ( "expirationTime : " + entry.getExpirationTime() );
System.out.println ( "number of hits : " + entry.getHits() );
System.out.println ( "lastAccessedTime: " + entry.getLastAccessTime() );
System.out.println ( "lastUpdateTime : " + entry.getLastUpdateTime() );
System.out.println ( "version : " + entry.getVersion() );
System.out.println ( "key : " + entry.getKey() );
System.out.println ( "value : " + entry.getValue() );

Detect oversized entries​

The size of an entry is the size of its serialized key plus the size of its serialized value. An oversized entry is a map entry whose size is above the map's oversized entry threshold. Large entries can cause memory pressure and slow down migrations and WAN replication. Hazelcast reports writes of oversized entries in three map metrics and in a warning log.

Set the oversized entry threshold​

Each map has its own threshold, in bytes. The default is 1048576 bytes (1 MB). To disable tracking for a map, set the threshold to 0. Hazelcast tracks oversized entries only when statistics are enabled for the map, which is the default.

The following example sets the threshold of the myMap map to 512 KB:

xml
<hazelcast>
...
<map name="myMap">
<oversized-entry-threshold-bytes>524288</oversized-entry-threshold-bytes>
</map>
...
</hazelcast>

To set the threshold for every map that has no configuration of its own, set it in the default map configuration. See The Default (Fallback) Map Configuration.

Hazelcast disables tracking for its internal maps whose names start with __jet., and for the __sql.catalog map.

Writes that Hazelcast measures​

Hazelcast measures each write that stores a value in the map:

  • Put and set operations, including putAll()
  • Entry processor results
  • Transactional writes
  • Merges, including entries that a cluster receives through WAN replication
  • Values that a MapStore or MapLoader loads into the map

Hazelcast does not measure setTtl(), because it does not write a new value.

Limitations of the OBJECT in-memory format​

For a map with the OBJECT in-memory format, the serialized size of an entry can differ significantly from the heap memory that the entry uses.

Hazelcast does not measure some writes to an OBJECT map, to avoid serializing values that exist only as objects:

  • Entry processor results, unless WAN replication is enabled for the map
  • Values that a MapLoader loads when a read misses the map
  • Puts to a map that has a map interceptor or a PostProcessingMapStore

For details on in-memory formats, see Setting the In-Memory Format of Map Entries.

Read the oversized entry metrics​

Hazelcast reports oversized entries in the following map metrics, which are also available from LocalMapStats:

MetricLocalMapStats methodUnitDescription
map.oversizedEntriesSeengetOversizedEntriesSeen()CountNumber of writes of an oversized entry
map.lastOversizedEntrySizegetLastOversizedEntrySize()BytesSize of the most recent oversized entry, or 0 if none was written
map.lastOversizedEntryTimegetLastOversizedEntryTime()Milliseconds since the epochTime of the most recent oversized write, or 0 if none was written

The metrics count writes, not the entries that the map stores. Writing the same oversized entry twice increases the count by two. Removing an oversized entry does not decrease the count or reset the size and time of the most recent oversized entry.

Each member reports the oversized entries written to the partitions that it owns. Hazelcast keeps the values with each partition. They move with a partition when it migrates to another member, and when a backup replica is promoted after a member leaves the cluster.

If several oversized entries are written between two metric collections, the size and time show only the last of them. For example, if entries of 2 MB, 10 MB, and 2 MB are written in that order, the size shows 2 MB, and the 10 MB entry is not reported. The count increases by three.

Find oversized entries in the log​

When an oversized entry is written to a primary replica, the member logs a warning. The warning gives the entry, key, and value sizes, the map name, the partition ID, and the threshold.

Each member logs this warning at most once every 30 minutes for each map. Writes to backup replicas do not log a warning.