Skip to content

Commit

Permalink
[#9023] Reduce memory usage for AgentInfo query
Browse files Browse the repository at this point in the history
  • Loading branch information
emeroad committed Jul 7, 2022
1 parent 9e99ecb commit 986ccd9
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,9 @@ public interface AgentInfoDao {
AgentInfo getAgentInfo(String agentId, long agentStartTime, int deltaTimeInMilliSeconds);

List<AgentInfo> getAgentInfos(List<String> agentIds, long timestamp);

/**
* No ServerMetaData, No JvmInfo
*/
List<AgentInfo> getSimpleAgentInfos(List<String> agentIds, long timestamp);
}
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ private Scan createScanForInitialAgentInfo(String agentId) {
public AgentInfo getAgentInfo(final String agentId, final long timestamp) {
Objects.requireNonNull(agentId, "agentId");

Scan scan = createScan(agentId, timestamp);
Scan scan = createScan(agentId, timestamp, AgentInfoColumn.all());

TableName agentInfoTableName = tableNameProvider.getTableName(DESCRIPTOR.getTable());
return this.hbaseOperations2.find(agentInfoTableName, scan, agentInfoResultsExtractor);
Expand Down Expand Up @@ -141,32 +141,41 @@ public AgentInfo getAgentInfo(String agentId, long agentStartTime, int deltaTime
final long startTime = agentStartTime - deltaTimeInMilliSeconds;
final long endTime = agentStartTime + deltaTimeInMilliSeconds;

Scan scan = createScan(agentId, startTime, endTime);
Scan scan = createScan(agentId, startTime, endTime, AgentInfoColumn.all());

TableName agentInfoTableName = tableNameProvider.getTableName(DESCRIPTOR.getTable());
return this.hbaseOperations2.find(agentInfoTableName, scan, agentInfoResultsExtractor);
}

@Override
public List<AgentInfo> getAgentInfos(List<String> agentIds, long timestamp) {
return getAgentInfos0(agentIds, timestamp, AgentInfoColumn.all());
}


public List<AgentInfo> getSimpleAgentInfos(List<String> agentIds, long timestamp) {
return getAgentInfos0(agentIds, timestamp, AgentInfoColumn.identifier());
}

public List<AgentInfo> getAgentInfos0(List<String> agentIds, long timestamp, AgentInfoColumn column) {
if (CollectionUtils.isEmpty(agentIds)) {
return Collections.emptyList();
}

List<Scan> scans = new ArrayList<>(agentIds.size());
for (String agentId : agentIds) {
scans.add(createScan(agentId, timestamp));
scans.add(createScan(agentId, timestamp, column));
}

TableName agentInfoTableName = tableNameProvider.getTableName(DESCRIPTOR.getTable());
return this.hbaseOperations2.findParallel(agentInfoTableName, scans, agentInfoResultsExtractor);
}

private Scan createScan(String agentId, long currentTime) {
return createScan(agentId, currentTime, Long.MAX_VALUE);
private Scan createScan(String agentId, long currentTime, AgentInfoColumn column) {
return createScan(agentId, currentTime, Long.MAX_VALUE, column);
}

private Scan createScan(String agentId, long startTime, long endTime) {
private Scan createScan(String agentId, long startTime, long endTime, AgentInfoColumn column) {
Scan scan = new Scan();

byte[] startKeyBytes;
Expand All @@ -181,12 +190,41 @@ private Scan createScan(String agentId, long startTime, long endTime) {

scan.withStartRow(startKeyBytes);
scan.withStopRow(endKeyBytes);
scan.addFamily(DESCRIPTOR.getName());

final byte[] family = DESCRIPTOR.getName();
if (column.identifier) {
scan.addColumn(family, DESCRIPTOR.QUALIFIER_IDENTIFIER);
}
if (column.serverMetaData) {
scan.addColumn(family, DESCRIPTOR.QUALIFIER_SERVER_META_DATA);
}
if (column.jvm) {
scan.addColumn(family, DESCRIPTOR.QUALIFIER_JVM);
}

scan.setMaxVersions(1);
scan.setCaching(SCANNER_CACHING);

return scan;
}

private static class AgentInfoColumn {
private final boolean identifier;
private final boolean serverMetaData;
private final boolean jvm;

public AgentInfoColumn(boolean identifier, boolean serverMetaData, boolean jvm) {
this.identifier = identifier;
this.serverMetaData = serverMetaData;
this.jvm = jvm;
}

public static AgentInfoColumn all() {
return new AgentInfoColumn(true, true, true);
}

public static AgentInfoColumn identifier() {
return new AgentInfoColumn(true, false, false);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ private ApplicationAgentHostList getApplicationAgentHostList0(int offset, int li
String applicationName = applicationNameList.get(i);

List<String> agentIdList = getAgentIdList(applicationName, durationDays);
List<AgentInfo> agentInfoList = this.agentInfoDao.getAgentInfos(agentIdList, timeStamp);
List<AgentInfo> agentInfoList = this.agentInfoDao.getSimpleAgentInfos(agentIdList, timeStamp);
builder.addAgentInfo(applicationName, agentInfoList);
}
return builder.build();
Expand Down Expand Up @@ -248,7 +248,7 @@ public List<AgentInfo> getAgentsByApplicationNameWithoutStatus0(String applicati
}

List<String> agentIds = this.applicationIndexDao.selectAgentIds(applicationName);
List<AgentInfo> agentInfos = this.agentInfoDao.getAgentInfos(agentIds, timestamp);
List<AgentInfo> agentInfos = this.agentInfoDao.getSimpleAgentInfos(agentIds, timestamp);

return agentInfos.stream()
.filter(Objects::nonNull)
Expand Down
23 changes: 1 addition & 22 deletions web/src/main/java/com/navercorp/pinpoint/web/vo/AgentInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,6 @@ public String getPorts() {
return ports;
}

public void setPorts(String ports) {
this.ports = ports;
}

public short getServiceTypeCode() {
return serviceTypeCode;
Expand All @@ -139,49 +136,30 @@ public int getPid() {
return pid;
}

public void setPid(int pid) {
this.pid = pid;
}

public String getVmVersion() {
return vmVersion;
}

public void setVmVersion(String vmVersion) {
this.vmVersion = vmVersion;
}

public String getAgentVersion() {
return agentVersion;
}

public void setAgentVersion(String agentVersion) {
this.agentVersion = agentVersion;
}

public ServerMetaDataBo getServerMetaData() {
return serverMetaData;
}

public void setServerMetaData(ServerMetaDataBo serverMetaData) {
this.serverMetaData = serverMetaData;
}

public JvmInfoBo getJvmInfo() {
return jvmInfo;
}

public void setJvmInfo(JvmInfoBo jvmInfo) {
this.jvmInfo = jvmInfo;
}

public long getInitialStartTimestamp() {
return initialStartTimestamp;
}

public void setInitialStartTimestamp(long initialStartTimestamp) {
this.initialStartTimestamp = initialStartTimestamp;
}

public boolean isContainer() {
return container;
Expand Down Expand Up @@ -232,6 +210,7 @@ public String toString() {
sb.append(", pid=").append(pid);
sb.append(", vmVersion='").append(vmVersion).append('\'');
sb.append(", agentVersion='").append(agentVersion).append('\'');
sb.append(", serverMetaData='").append(serverMetaData).append('\'');
sb.append(", jvmInfo=").append(jvmInfo);
sb.append(", initialStartTimestamp=").append(initialStartTimestamp);
sb.append(", container=").append(container);
Expand Down

0 comments on commit 986ccd9

Please sign in to comment.