Gemfire地区大小

时间:2017-10-18 20:24:38

标签: gemfire

我正在尝试在Gemfire缓存中找到某个区域的大小。我检查过Region的java api。 size方法仅返回条目计数。我确信必须有一些方法来计算区域大小,根据它占用的内存量,因为Gemfire Pulse数据视图显示了每个区域的内存使用情况。有人可以帮忙吗?

由于

2 个答案:

答案 0 :(得分:2)

如果你在总堆之后,在gfsh中,做一个垃圾收集,它会告诉你分布式系统在" GC"之后的确切内存量。柱。如下:

gfsh>连 gfsh> GC



           Member ID/Name             | HeapSize (MB) Before GC | HeapSize(MB) After GC | Time Taken for GC in ms
------------------------------------- | ----------------------- | --------------------- | -----------------------
192.168.0.10(server1:40981)<v1>:52393 | 1698                    | 120                   | 14
192.168.0.10(server2:43759)<v2>:9599  | 2250                    | 78                    | 15
&#13;
&#13;
&#13;

要获取分区区域的大小,请在所有节点上的函数中运行以下命令:

&#13;
&#13;
Region<?,?> primaryDataSet = PartitionRegionHelper.getLocalData(region);
regionSize = primaryDataSet.size();
&#13;
&#13;
&#13;

对于复制区域,在其中一个节点上运行以下代码(所有代码均未显示为空格)。您必须循环遍历所有或一个条目的样本以获得平均记录的大小并将其乘以#条目。在插入时不计算每行的大小是设计的,因为它会减慢插入时间:

&#13;
&#13;
	/**
	 * Sizes numEntries of a replicated or local region, or all the entries if
	 * numEntries is 0.
	 * 
	 * @param numberOfSamples
	 *            Number of entries to size. If the value is 0, all the entries are
	 *            sized.
	 */
	private Map<String, Long> sizeReplicatedOrLocalRegion(Region<?,?> region, long numberOfSamples) {
		regionTypeInd = 1L;
		Set<?> entries = region.entrySet();
		regionSize = entries.size();
		if (numberOfSamples == 0) {
			numberOfSamples = entries.size();
		} else if (numberOfSamples > regionSize) {
			numberOfSamples = regionSize;
		}

		int count = 0;
		for (Iterator<?> i = entries.iterator(); i.hasNext();) {
			if (count == numberOfSamples) {
				break;
			}
			LocalRegion.NonTXEntry entry = (LocalRegion.NonTXEntry) i.next();
			RegionEntry re = entry.getRegionEntry();
			dumpSizes(entry, re);
			count++;
		}

		dumpTotalAndAverageSizes(numberOfSamples);
		Map<String, Long> results = packageResults(numberOfSamples);
		clearTotals();
		return results;
	}

	private void dumpSizes(Region.Entry<?,?> entry, RegionEntry re) {
		int deserializedRegionEntrySizeBefore = ReflectionObjectSizer.getInstance().sizeof(re);
		int serializedValueSize = calculateSerializedValueSize(entry, re);
		int deserializedKeySize = ReflectionObjectSizer.getInstance().sizeof(entry.getKey());
		Object value = entry.getValue();
		int deserializedValueSize;
		if (value instanceof PdxInstance) {
			Object actualObj = ((PdxInstance) value).getObject();
			deserializedValueSize = sizeObject(actualObj);
		} else {
			deserializedValueSize = sizeObject(value);
		}
		int deserializedRegionEntrySizeAfter = ReflectionObjectSizer.getInstance().sizeof(re);
		this.totalDeserializedRegionEntrySizeBefore += deserializedRegionEntrySizeBefore;
		this.totalDeserializedKeySize += deserializedKeySize;
		this.totalDeserializedValueSize += deserializedValueSize;
		this.totalSerializedValueSize += serializedValueSize;
		this.totalDeserializedRegionEntrySizeAfter += deserializedRegionEntrySizeAfter;
		log("RegionEntry (key = " + re.getKey() + ") size: " + deserializedRegionEntrySizeBefore + " (serialized), "
				+ deserializedRegionEntrySizeAfter + " (deserialized). Key size: " + deserializedKeySize
				+ ". Value size: " + serializedValueSize + " (serialized), " + deserializedValueSize
				+ "(deserialized).");
		
		String histStats = "";
		try {
			histStats = histObject(re);
		} catch (IllegalArgumentException | IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		log("Hist Stats=" + histStats);
	}

	private int calculateSerializedValueSize(Region.Entry<?,?> entry, RegionEntry re) {
		Object valueInVm = re.getValue(null);
		int serializedValueSize = 0;
		if (valueInVm instanceof CachedDeserializable) {
			// Value is a wrapper
			Object cdValue = ((CachedDeserializable) valueInVm).getValue();
			if (cdValue instanceof byte[]) {
				// The wrapper wraps a serialized domain object
				serializedValueSize = ((byte[]) cdValue).length;
			} else {
				// The wrapper wraps a deserialized domain object
				serializedValueSize = ReflectionObjectSizer.getInstance().sizeof(cdValue);
			}
		} else {
			// Value is a domain object
			serializedValueSize = ReflectionObjectSizer.getInstance().sizeof(valueInVm);
		}

		return serializedValueSize;
	}

	private Map<String, Long> packageResults(long totalSamples) {
		Map<String, Long> results = new HashMap<>();

		results.put("Average RegionEntry size (serialized)", avgDeserializedRegionEntrySizeBefore);
		results.put("Average RegionEntry size (deserialized)", avgDeserializedRegionEntrySizeAfter);
		results.put("Average Key size", avgDeserializedKeySize);
		results.put("Average Value size (serialized)", avgSerializedValueSize);
		results.put("Average Value size (deserialized)", avgDeserializedValueSize);
		results.put("Total RegionEntry size (serialized)", this.totalDeserializedRegionEntrySizeBefore);
		results.put("Total RegionEntry size (deserialized)", this.totalDeserializedRegionEntrySizeAfter);
		results.put("Total Key size", this.totalDeserializedKeySize);
		results.put("Total Value size (serialized)", this.totalSerializedValueSize);
		results.put("Total Value size (deserialized)", this.totalDeserializedValueSize);
		results.put("_Region Type indicator", regionTypeInd);
		results.put("_Total Sampled Entries", (long) totalSamples);
		results.put("_Total Entries", (long) regionSize);

		return results;
	}
&#13;
&#13;
&#13;

答案 1 :(得分:0)