Skip to content

Commit

Permalink
IGNITE-5461 Added collecting of memory metrics.
Browse files Browse the repository at this point in the history
  • Loading branch information
akuznetsov-os committed Jun 16, 2017
1 parent 57bfba7 commit 29c2693
Show file tree
Hide file tree
Showing 7 changed files with 287 additions and 22 deletions.
Expand Up @@ -71,9 +71,6 @@ public class VisorCache extends VisorDataTransferObject {
/** Number of backup entries in cache. */ /** Number of backup entries in cache. */
private long backupSize; private long backupSize;


/** Number of cache entries stored in heap memory. */
private long onHeapEntriesCnt;

/** Number of partitions. */ /** Number of partitions. */
private int partitions; private int partitions;


Expand Down Expand Up @@ -112,8 +109,6 @@ public VisorCache(IgniteEx ignite, GridCacheAdapter ca) throws IgniteCheckedExce
partitions = ca.affinity().partitions(); partitions = ca.affinity().partitions();
near = cctx.isNear(); near = cctx.isNear();


onHeapEntriesCnt = 0; // TODO GG-11148 How to get this metric?

metrics = new VisorCacheMetrics(ignite, name); metrics = new VisorCacheMetrics(ignite, name);
} }


Expand All @@ -131,7 +126,6 @@ public VisorCache history() {
c.nearSize = nearSize; c.nearSize = nearSize;
c.backupSize = backupSize; c.backupSize = backupSize;
c.primarySize = primarySize; c.primarySize = primarySize;
c.onHeapEntriesCnt = onHeapEntriesCnt;
c.partitions = partitions; c.partitions = partitions;
c.metrics = metrics; c.metrics = metrics;
c.near = near; c.near = near;
Expand Down Expand Up @@ -211,13 +205,6 @@ public long getPrimarySize() {
return primarySize; return primarySize;
} }


/**
* @return Number of cache entries stored in heap memory.
*/
public long getOnHeapEntriesCount() {
return onHeapEntriesCnt;
}

/** /**
* @return Number of partitions. * @return Number of partitions.
*/ */
Expand Down Expand Up @@ -250,7 +237,6 @@ public boolean isNear() {
out.writeInt(nearSize); out.writeInt(nearSize);
out.writeLong(primarySize); out.writeLong(primarySize);
out.writeLong(backupSize); out.writeLong(backupSize);
out.writeLong(onHeapEntriesCnt);
out.writeInt(partitions); out.writeInt(partitions);
out.writeBoolean(near); out.writeBoolean(near);
out.writeObject(metrics); out.writeObject(metrics);
Expand All @@ -267,7 +253,6 @@ public boolean isNear() {
nearSize = in.readInt(); nearSize = in.readInt();
primarySize = in.readLong(); primarySize = in.readLong();
backupSize = in.readLong(); backupSize = in.readLong();
onHeapEntriesCnt = in.readLong();
partitions = in.readInt(); partitions = in.readInt();
near = in.readBoolean(); near = in.readBoolean();
metrics = (VisorCacheMetrics)in.readObject(); metrics = (VisorCacheMetrics)in.readObject();
Expand Down
Expand Up @@ -157,6 +157,9 @@ public class VisorCacheMetrics extends VisorDataTransferObject {
/** Number of cached rolled back DHT transaction IDs. */ /** Number of cached rolled back DHT transaction IDs. */
private int txDhtRolledbackVersionsSize; private int txDhtRolledbackVersionsSize;


/** Number of cache entries stored in heap memory. */
private long heapEntriesCnt;

/** Memory size allocated in off-heap. */ /** Memory size allocated in off-heap. */
private long offHeapAllocatedSize; private long offHeapAllocatedSize;


Expand Down Expand Up @@ -259,6 +262,7 @@ public VisorCacheMetrics(IgniteEx ignite, String cacheName) {
txDhtCommittedVersionsSize = m.getTxDhtCommittedVersionsSize(); txDhtCommittedVersionsSize = m.getTxDhtCommittedVersionsSize();
txDhtRolledbackVersionsSize = m.getTxDhtRolledbackVersionsSize(); txDhtRolledbackVersionsSize = m.getTxDhtRolledbackVersionsSize();


heapEntriesCnt = m.getHeapEntriesCount();
offHeapAllocatedSize = m.getOffHeapAllocatedSize(); offHeapAllocatedSize = m.getOffHeapAllocatedSize();
offHeapEntriesCnt = m.getOffHeapEntriesCount(); offHeapEntriesCnt = m.getOffHeapEntriesCount();


Expand Down Expand Up @@ -560,6 +564,13 @@ public int getTxDhtRolledbackVersionsSize() {
return txDhtRolledbackVersionsSize; return txDhtRolledbackVersionsSize;
} }


/**
* @return Number of entries in heap memory.
*/
public long getHeapEntriesCount() {
return heapEntriesCnt;
}

/** /**
* @return Memory size allocated in off-heap. * @return Memory size allocated in off-heap.
*/ */
Expand Down Expand Up @@ -653,6 +664,7 @@ public long getRebalancingBytesRate() {
out.writeInt(txDhtCommittedVersionsSize); out.writeInt(txDhtCommittedVersionsSize);
out.writeInt(txDhtRolledbackVersionsSize); out.writeInt(txDhtRolledbackVersionsSize);


out.writeLong(heapEntriesCnt);
out.writeLong(offHeapAllocatedSize); out.writeLong(offHeapAllocatedSize);
out.writeLong(offHeapEntriesCnt); out.writeLong(offHeapEntriesCnt);


Expand Down Expand Up @@ -708,6 +720,7 @@ public long getRebalancingBytesRate() {
txDhtCommittedVersionsSize = in.readInt(); txDhtCommittedVersionsSize = in.readInt();
txDhtRolledbackVersionsSize = in.readInt(); txDhtRolledbackVersionsSize = in.readInt();


heapEntriesCnt = in.readLong();
offHeapAllocatedSize = in.readLong(); offHeapAllocatedSize = in.readLong();
offHeapEntriesCnt = in.readLong(); offHeapEntriesCnt = in.readLong();


Expand Down
@@ -0,0 +1,175 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.apache.ignite.internal.visor.cache;

import java.io.IOException;
import java.io.ObjectInput;
import java.io.ObjectOutput;
import org.apache.ignite.MemoryMetrics;
import org.apache.ignite.internal.util.typedef.internal.S;
import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.internal.visor.VisorDataTransferObject;

/**
* Data transfer object for {@link MemoryMetrics}
*/
public class VisorMemoryMetrics extends VisorDataTransferObject {
/** */
private static final long serialVersionUID = 0L;

/** */
private String name;

/** */
private long totalAllocatedPages;

/** */
private float allocationRate;

/** */
private float evictionRate;

/** */
private float largeEntriesPagesPercentage;

/** */
private float pagesFillFactor;

/** */
private long dirtyPages;

/** */
private float pageReplaceRate;

/** */
private long physicalMemoryPages;

/**
* Default constructor.
*/
public VisorMemoryMetrics() {
// No-op.
}

/**
* @param m Metrics instance to create DTO.
*/
public VisorMemoryMetrics(MemoryMetrics m) {
name = m.getName();
totalAllocatedPages = m.getTotalAllocatedPages();
allocationRate = m.getAllocationRate();
evictionRate = m.getEvictionRate();
largeEntriesPagesPercentage = m.getLargeEntriesPagesPercentage();
pagesFillFactor = m.getPagesFillFactor();
dirtyPages = m.getDirtyPages();
pageReplaceRate = m.getPagesReplaceRate();
physicalMemoryPages = m.getPhysicalMemoryPages();
}

/**
* @return Name of the memory region.
*/
public String getName() {
return name;
}

/**
* @return Total number of allocated pages.
*/
public long getTotalAllocatedPages() {
return totalAllocatedPages;
}

/**
* @return Number of allocated pages per second.
*/
public float getAllocationRate() {
return allocationRate;
}

/** {@inheritDoc} */
public float getEvictionRate() {
return evictionRate;
}

/**
* @return Number of evicted pages per second.
*/
public float getLargeEntriesPagesPercentage() {
return largeEntriesPagesPercentage;
}

/**
* @return Percentage of pages fully occupied by large entities.
*/
public float getPagesFillFactor() {
return pagesFillFactor;
}

/**
* @return Current number of dirty pages.
*/
public long getDirtyPages() {
return dirtyPages;
}

/**
* @return Pages per second replace rate.
*/
public float getPagesReplaceRate() {
return pageReplaceRate;
}

/**
* @return Total number of pages loaded to RAM.
*/
public long getPhysicalMemoryPages() {
return physicalMemoryPages;
}

/** {@inheritDoc} */
@Override protected void writeExternalData(ObjectOutput out) throws IOException {
U.writeString(out, name);
out.writeLong(totalAllocatedPages);
out.writeFloat(allocationRate);
out.writeFloat(evictionRate);
out.writeFloat(largeEntriesPagesPercentage);
out.writeFloat(pagesFillFactor);
out.writeLong(dirtyPages);
out.writeFloat(pageReplaceRate);
out.writeLong(physicalMemoryPages);
}

/** {@inheritDoc} */
@Override protected void readExternalData(byte protoVer, ObjectInput in) throws IOException, ClassNotFoundException {
name = U.readString(in);
totalAllocatedPages = in.readLong();
allocationRate = in.readFloat();
evictionRate = in.readFloat();
largeEntriesPagesPercentage = in.readFloat();
pagesFillFactor = in.readFloat();
dirtyPages = in.readLong();
pageReplaceRate = in.readFloat();
physicalMemoryPages = in.readLong();
}

/** {@inheritDoc} */
@Override public String toString() {
return S.toString(VisorMemoryMetrics.class, this);
}
}
Expand Up @@ -18,8 +18,10 @@
package org.apache.ignite.internal.visor.node; package org.apache.ignite.internal.visor.node;


import java.util.Collection; import java.util.Collection;
import java.util.List;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import org.apache.ignite.IgniteFileSystem; import org.apache.ignite.IgniteFileSystem;
import org.apache.ignite.MemoryMetrics;
import org.apache.ignite.cluster.ClusterNode; import org.apache.ignite.cluster.ClusterNode;
import org.apache.ignite.configuration.FileSystemConfiguration; import org.apache.ignite.configuration.FileSystemConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration; import org.apache.ignite.configuration.IgniteConfiguration;
Expand All @@ -33,6 +35,7 @@
import org.apache.ignite.internal.util.typedef.internal.U; import org.apache.ignite.internal.util.typedef.internal.U;
import org.apache.ignite.internal.visor.VisorJob; import org.apache.ignite.internal.visor.VisorJob;
import org.apache.ignite.internal.visor.cache.VisorCache; import org.apache.ignite.internal.visor.cache.VisorCache;
import org.apache.ignite.internal.visor.cache.VisorMemoryMetrics;
import org.apache.ignite.internal.visor.compute.VisorComputeMonitoringHolder; import org.apache.ignite.internal.visor.compute.VisorComputeMonitoringHolder;
import org.apache.ignite.internal.visor.igfs.VisorIgfs; import org.apache.ignite.internal.visor.igfs.VisorIgfs;
import org.apache.ignite.internal.visor.igfs.VisorIgfsEndpoint; import org.apache.ignite.internal.visor.igfs.VisorIgfsEndpoint;
Expand Down Expand Up @@ -115,8 +118,8 @@ protected void events(VisorNodeDataCollectorJobResult res, VisorNodeDataCollecto


events0(res, arg.getEventsOrderKey(), arg.getEventsThrottleCounterKey(), arg.isTaskMonitoringEnabled()); events0(res, arg.getEventsOrderKey(), arg.getEventsThrottleCounterKey(), arg.isTaskMonitoringEnabled());
} }
catch (Exception eventsEx) { catch (Exception e) {
res.setEventsEx(eventsEx); res.setEventsEx(e);
} }
} }


Expand Down Expand Up @@ -144,6 +147,23 @@ private boolean proxyCache(String cacheName) {
return !(discovery.cacheAffinityNode(locNode, cacheName) || discovery.cacheNearNode(locNode, cacheName)); return !(discovery.cacheAffinityNode(locNode, cacheName) || discovery.cacheNearNode(locNode, cacheName));
} }


/**
* Collect memory metrics.
*
* @param res Job result.
*/
protected void memoryMetrics(VisorNodeDataCollectorJobResult res) {
try {
List<VisorMemoryMetrics> memoryMetrics = res.getMemoryMetrics();

for (MemoryMetrics m : ignite.memoryMetrics())
memoryMetrics.add(new VisorMemoryMetrics(m));
}
catch (Exception e) {
res.setMemoryMetricsEx(e);
}
}

/** /**
* Collect caches. * Collect caches.
* *
Expand All @@ -156,6 +176,8 @@ protected void caches(VisorNodeDataCollectorJobResult res, VisorNodeDataCollecto


GridCacheProcessor cacheProc = ignite.context().cache(); GridCacheProcessor cacheProc = ignite.context().cache();


List<VisorCache> resCaches = res.getCaches();

for (String cacheName : cacheProc.cacheNames()) { for (String cacheName : cacheProc.cacheNames()) {
if (proxyCache(cacheName)) if (proxyCache(cacheName))
continue; continue;
Expand All @@ -169,7 +191,7 @@ protected void caches(VisorNodeDataCollectorJobResult res, VisorNodeDataCollecto
if (ca == null || !ca.context().started()) if (ca == null || !ca.context().started())
continue; continue;


res.getCaches().add(new VisorCache(ignite, ca)); resCaches.add(new VisorCache(ignite, ca));
} }
catch(IllegalStateException | IllegalArgumentException e) { catch(IllegalStateException | IllegalArgumentException e) {
if (debug && ignite.log() != null) if (debug && ignite.log() != null)
Expand All @@ -182,8 +204,8 @@ protected void caches(VisorNodeDataCollectorJobResult res, VisorNodeDataCollecto
} }
} }
} }
catch (Exception cachesEx) { catch (Exception e) {
res.setCachesEx(cachesEx); res.setCachesEx(e);
} }
} }


Expand Down Expand Up @@ -222,8 +244,8 @@ protected void igfs(VisorNodeDataCollectorJobResult res) {
} }
} }
} }
catch (Exception igfssEx) { catch (Exception e) {
res.setIgfssEx(igfssEx); res.setIgfssEx(e);
} }
} }


Expand Down Expand Up @@ -257,6 +279,11 @@ protected VisorNodeDataCollectorJobResult run(VisorNodeDataCollectorJobResult re
if (debug) if (debug)
start0 = log(ignite.log(), "Collected events", getClass(), start0); start0 = log(ignite.log(), "Collected events", getClass(), start0);


memoryMetrics(res);

if (debug)
start0 = log(ignite.log(), "Collected memory metrics", getClass(), start0);

caches(res, arg); caches(res, arg);


if (debug) if (debug)
Expand Down

0 comments on commit 29c2693

Please sign in to comment.