Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ISPN-14129 Memory used by a node and cache in the distribution endpoint #10329

Merged
merged 1 commit into from Oct 10, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -5,14 +5,16 @@
"127.0.0.1:44175"
],
"memory_entries": 0,
"total_entries": 0
"total_entries": 0,
"memory_used": 528512
},
{
"node_name":"NodeB",
"node_addresses": [
"127.0.0.1:44187"
],
"memory_entries": 0,
"total_entries": 0
"total_entries": 0,
"memory_used": 528512
}
]
Expand Up @@ -177,6 +177,7 @@ Each element in the list represents a node. The properties are:
* `node_addresses` is a list with all the node's physical addresses.
* `memory_entries` the number of entries the node holds in memory belonging to the cache.
* `total_entries` the number of entries the node has in memory and disk belonging to the cache.
* `memory_used` the value in bytes the eviction algorithm estimates the cache occupies. Returns -1 if eviction is not enabled.

[id='rest_v2_cache_mutable_attributes']
= Retrieving all mutable cache configuration attributes
Expand Down
11 changes: 11 additions & 0 deletions server/rest/proto.lock
Expand Up @@ -77,6 +77,17 @@
"value": "0"
}
]
},
{
"id": 5,
"name": "memoryUsed",
"type": "int64",
"options": [
{
"name": "default",
"value": "0"
}
]
}
]
},
Expand Down
Expand Up @@ -20,13 +20,15 @@ public class CacheDistributionInfo implements JsonSerialization, NodeDataDistrib
private final List<String> addresses;
private final long memoryEntries;
private final long totalEntries;
private final long memoryUsed;

@ProtoFactory
public CacheDistributionInfo(String name, List<String> addresses, long memoryEntries, long totalEntries) {
public CacheDistributionInfo(String name, List<String> addresses, long memoryEntries, long totalEntries, long memoryUsed) {
this.name = name;
this.addresses = addresses;
this.memoryEntries = memoryEntries;
this.totalEntries = totalEntries;
this.memoryUsed = memoryUsed;
}

@ProtoField(1)
Expand All @@ -51,20 +53,27 @@ public long totalEntries() {
return totalEntries;
}

@ProtoField(value = 5, defaultValue = "0")
public long memoryUsed() {
return memoryUsed;
}

@Override
public Json toJson() {
return Json.object()
.set("node_name", name)
.set("node_addresses", Json.array(addresses.toArray()))
.set("memory_entries", memoryEntries)
.set("total_entries", totalEntries);
.set("total_entries", totalEntries)
.set("memory_used", memoryUsed);
}

public static CacheDistributionInfo resolve(AdvancedCache<?, ?> cache) {
final Stats stats = cache.getStats();
final CacheManagerInfo manager = cache.getCacheManager().getCacheManagerInfo();
long inMemory = stats.getApproximateEntriesInMemory();
long total = stats.getApproximateEntries();
return new CacheDistributionInfo(manager.getNodeName(), manager.getPhysicalAddressesRaw(), inMemory, total);
return new CacheDistributionInfo(manager.getNodeName(), manager.getPhysicalAddressesRaw(), inMemory, total,
stats.getDataMemoryUsed());
}
}
Expand Up @@ -422,7 +422,8 @@ public void testCacheV2Stats() {

@Test
public void testCacheV2Distribution() {
String cacheJson = "{ \"distributed-cache\" : { \"statistics\":true } }";
String cacheJson = "{ \"distributed-cache\" : { \"statistics\":true, \"memory\" : {"
+ "\"storage\": \"OFF_HEAP\", \"max-size\": \"1MB\" } } }";
RestCacheClient cacheClient = client.cache("distributionCache");

RestEntity jsonEntity = RestEntity.create(APPLICATION_JSON, cacheJson);
Expand All @@ -441,11 +442,15 @@ public void testCacheV2Distribution() {

assertEquals(NUM_SERVERS, jsons.size());
Pattern pattern = Pattern.compile(this.getClass().getSimpleName() + "-Node[a-zA-Z]$");
Map<String, Long> previousSizes = new HashMap<>();
for (Json node : jsons) {
assertEquals(node.at("memory_entries").asInteger(), 2);
assertEquals(node.at("total_entries").asInteger(), 2);
assertEquals(node.at("node_addresses").asJsonList().size(), 1);
assertTrue(pattern.matcher(node.at("node_name").asString()).matches());
assertTrue(node.at("memory_used").asLong() > 0);

previousSizes.put(node.at("node_name").asString(), node.at("memory_used").asLong());
}

response = cacheClient.clear();
Expand All @@ -461,6 +466,12 @@ public void testCacheV2Distribution() {
for (Json node : jsons) {
assertEquals(node.at("memory_entries").asInteger(), 0);
assertEquals(node.at("total_entries").asInteger(), 0);

// Even though the cache was cleared, it still occupies some space.
assertTrue(node.at("memory_used").asLong() > 0);

// But less space than before.
assertTrue(node.at("memory_used").asLong() < previousSizes.get(node.at("node_name").asString()));
}
}

Expand Down