public virtual void TestSimpleByteArrays() { MemoryMXBean memoryMXBean = ManagementFactory.MemoryMXBean; object[][] all = new object[0][]; try { while (true) { // Check the current memory consumption and provide the estimate. CauseGc(); MemoryUsage mu = memoryMXBean.HeapMemoryUsage; long estimated = ShallowSizeOf(all); if (estimated > 50 * RamUsageEstimator.ONE_MB) { break; } Console.WriteLine(string.format(Locale.ROOT, "%10s\t%10s\t%10s", RamUsageEstimator.humanReadableUnits(mu.Used), RamUsageEstimator.humanReadableUnits(mu.Max), RamUsageEstimator.humanReadableUnits(estimated))); // Make another batch of objects. object[] seg = new object[10000]; all = Arrays.copyOf(all, all.Length + 1); all[all.Length - 1] = seg; for (int i = 0; i < seg.Length; i++) { seg[i] = new sbyte[Random().Next(7)]; } } } catch (System.OutOfMemoryException e) { // Release and quit. } }
public virtual void TestChainedEstimation() { MemoryMXBean memoryMXBean = ManagementFactory.MemoryMXBean; Random rnd = Random(); Entry first = new Entry(); try { while (true) { // Check the current memory consumption and provide the estimate. long jvmUsed = memoryMXBean.HeapMemoryUsage.Used; long estimated = RamUsageEstimator.sizeOf(first); Console.WriteLine(string.format(Locale.ROOT, "%10d, %10d", jvmUsed, estimated)); // Make a batch of objects. for (int i = 0; i < 5000; i++) { first.CreateNext(new sbyte[rnd.Next(1024)]); } } } catch (System.OutOfMemoryException e) { // Release and quit. } }
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in C#: //ORIGINAL LINE: public long estimatedSize(org.neo4j.diagnostics.DiagnosticsReporterProgress progress) throws java.io.IOException public long estimatedSize(DiagnosticsReporterProgress progress) { MemoryMXBean bean = ManagementFactory.getPlatformMXBean(_outerInstance.mBeanServer, typeof(MemoryMXBean)); long totalMemory = bean.HeapMemoryUsage.Committed + bean.NonHeapMemoryUsage.Committed; // We first write raw to disk then write to archive, 5x compression is a reasonable worst case estimation return(( long )(totalMemory * 1.2)); }
private void DoMemoryUpdates() { MemoryMXBean memoryMXBean = ManagementFactory.GetMemoryMXBean(); MemoryUsage memNonHeap = memoryMXBean.GetNonHeapMemoryUsage(); MemoryUsage memHeap = memoryMXBean.GetHeapMemoryUsage(); Runtime runtime = Runtime.GetRuntime(); metrics.SetMetric("memNonHeapUsedM", memNonHeap.GetUsed() / M); metrics.SetMetric("memNonHeapCommittedM", memNonHeap.GetCommitted() / M); metrics.SetMetric("memHeapUsedM", memHeap.GetUsed() / M); metrics.SetMetric("memHeapCommittedM", memHeap.GetCommitted() / M); metrics.SetMetric("maxMemoryM", runtime.MaxMemory() / M); }
public virtual void TestLargeSetOfByteArrays() { MemoryMXBean memoryMXBean = ManagementFactory.MemoryMXBean; CauseGc(); long before = memoryMXBean.HeapMemoryUsage.Used; object[] all = new object[1000000]; for (int i = 0; i < all.Length; i++) { all[i] = new sbyte[Random().Next(3)]; } CauseGc(); long after = memoryMXBean.HeapMemoryUsage.Used; Console.WriteLine("mx: " + RamUsageEstimator.humanReadableUnits(after - before)); Console.WriteLine("rue: " + RamUsageEstimator.humanReadableUnits(ShallowSizeOf(all))); Guard = all; }