Perf: cache metrics id and entity id (#7201)
There are a lot of calls to `Metrics.id()` and `ISource.getEntityId`, which calculates the id by manipulating strings in every single call, producing many garbage objects. In this patch, I cache the id and only calculate the id if it's requested for the first time.
This commit is contained in:
parent
84a7fe30c8
commit
f5b7c3e32d
|
|
@ -48,6 +48,7 @@ Release Notes.
|
|||
* Performance: trim useless metadata fields in Envoy ALS metadata to improve performance.
|
||||
* Fix: slowDBAccessThreshold dynamic config error when not configured.
|
||||
* Performance: cache regex pattern and result, optimize string concatenation in Envy ALS analyzer.
|
||||
* Performance: cache metrics id and entity id in `Metrics` and `ISource`.
|
||||
|
||||
#### UI
|
||||
* Fix the date component for log conditions.
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ import org.apache.skywalking.oap.server.core.remote.grpc.proto.RemoteData;
|
|||
public class MockMetrics extends Metrics {
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return "mock-metrics";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
public String id() {
|
||||
protected String id0() {
|
||||
StringBuilder splitJointId = new StringBuilder(String.valueOf(getTimeBucket()));
|
||||
<#list fieldsFromSource as sourceField>
|
||||
<#if sourceField.isID()>
|
||||
|
|
|
|||
|
|
@ -429,7 +429,7 @@ public class RunningRuleTest {
|
|||
private int value;
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -486,7 +486,7 @@ public class RunningRuleTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -538,7 +538,7 @@ public class RunningRuleTest {
|
|||
private DataTable value;
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class EndpointTraffic extends Metrics {
|
|||
private String name = Const.EMPTY_STRING;
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
// Downgrade the time bucket to day level only.
|
||||
// supportDownSampling == false for this entity.
|
||||
return IDManager.EndpointID.buildId(
|
||||
|
|
|
|||
|
|
@ -121,7 +121,7 @@ public class InstanceTraffic extends Metrics {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return IDManager.ServiceInstanceID.buildId(serviceId, name);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ public class NetworkAddressAlias extends Metrics {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return IDManager.NetworkAddressAliasDefine.buildId(address);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class EndpointRelationServerSideMetrics extends Metrics {
|
|||
private String entityId;
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
String splitJointId = String.valueOf(getTimeBucket());
|
||||
splitJointId += Const.ID_CONNECTOR + entityId;
|
||||
return splitJointId;
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class ServiceInstanceRelationClientSideMetrics extends Metrics {
|
|||
private String entityId;
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getTimeBucket() + Const.ID_CONNECTOR + entityId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -72,7 +72,7 @@ public class ServiceInstanceRelationServerSideMetrics extends Metrics {
|
|||
private String entityId;
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getTimeBucket() + Const.ID_CONNECTOR + entityId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class ServiceRelationClientSideMetrics extends Metrics {
|
|||
private String entityId;
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getTimeBucket() + Const.ID_CONNECTOR + entityId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -62,7 +62,7 @@ public class ServiceRelationServerSideMetrics extends Metrics {
|
|||
private String entityId;
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getTimeBucket() + Const.ID_CONNECTOR + entityId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public class ServiceTraffic extends Metrics {
|
|||
private String group;
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return IDManager.ServiceID.buildId(name, nodeType);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -138,7 +138,7 @@ public abstract class HistogramFunction extends Metrics implements AcceptableVal
|
|||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getTimeBucket() + Const.ID_CONNECTOR + entityId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -246,7 +246,7 @@ public abstract class PercentileFunction extends Metrics implements AcceptableVa
|
|||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getTimeBucket() + Const.ID_CONNECTOR + entityId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -148,7 +148,7 @@ public abstract class AvgFunction extends Metrics implements AcceptableValue<Lon
|
|||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getTimeBucket() + Const.ID_CONNECTOR + entityId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -167,7 +167,7 @@ public abstract class AvgHistogramFunction extends Metrics implements Acceptable
|
|||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getTimeBucket() + Const.ID_CONNECTOR + entityId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -318,7 +318,7 @@ public abstract class AvgHistogramPercentileFunction extends Metrics implements
|
|||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getTimeBucket() + Const.ID_CONNECTOR + entityId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -150,7 +150,7 @@ public abstract class AvgLabeledFunction extends Metrics implements AcceptableVa
|
|||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getTimeBucket() + Const.ID_CONNECTOR + entityId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -129,7 +129,7 @@ public abstract class LatestFunction extends Metrics implements AcceptableValue<
|
|||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getTimeBucket() + Const.ID_CONNECTOR + entityId;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public abstract class SumFunction extends Metrics implements AcceptableValue<Lon
|
|||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getTimeBucket() + Const.ID_CONNECTOR + getEntityId();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -131,4 +131,16 @@ public abstract class Metrics extends StreamData implements StorageData {
|
|||
private boolean isDayBucket() {
|
||||
return TimeBucket.isDayBucket(timeBucket);
|
||||
}
|
||||
|
||||
private volatile String id;
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
if (id == null) {
|
||||
id = id0();
|
||||
}
|
||||
return id;
|
||||
}
|
||||
|
||||
protected abstract String id0();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class Event extends Metrics implements ISource, WithMetadata, LongValueHo
|
|||
public static final String END_TIME = "end_time";
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return getUuid();
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE
|
|||
@ScopeDeclaration(id = SERVICE, name = "Service", catalog = SERVICE_CATALOG_NAME)
|
||||
@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class)
|
||||
public class Service extends Source {
|
||||
private volatile String entityId;
|
||||
|
||||
@Override
|
||||
public int scope() {
|
||||
return DefaultScopeDefine.SERVICE;
|
||||
|
|
@ -38,7 +40,10 @@ public class Service extends Source {
|
|||
|
||||
@Override
|
||||
public String getEntityId() {
|
||||
return IDManager.ServiceID.buildId(name, nodeType);
|
||||
if (entityId == null) {
|
||||
entityId = IDManager.ServiceID.buildId(name, nodeType);
|
||||
}
|
||||
return entityId;
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ import static org.apache.skywalking.oap.server.core.source.DefaultScopeDefine.SE
|
|||
@ScopeDeclaration(id = SERVICE_INSTANCE, name = "ServiceInstance", catalog = SERVICE_INSTANCE_CATALOG_NAME)
|
||||
@ScopeDefaultColumn.VirtualColumnDefinition(fieldName = "entityId", columnName = "entity_id", isID = true, type = String.class)
|
||||
public class ServiceInstance extends Source {
|
||||
private volatile String entityId;
|
||||
|
||||
@Override
|
||||
public int scope() {
|
||||
return DefaultScopeDefine.SERVICE_INSTANCE;
|
||||
|
|
@ -38,7 +40,10 @@ public class ServiceInstance extends Source {
|
|||
|
||||
@Override
|
||||
public String getEntityId() {
|
||||
return IDManager.ServiceInstanceID.buildId(serviceId, name);
|
||||
if (entityId == null) {
|
||||
entityId = IDManager.ServiceInstanceID.buildId(serviceId, name);
|
||||
}
|
||||
return entityId;
|
||||
}
|
||||
|
||||
@Getter
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ public class ApdexMetricsTest {
|
|||
public class ApdexMetricsImpl extends ApdexMetrics {
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -56,7 +56,7 @@ public class CountMetricsTest {
|
|||
|
||||
public class CountMetricsImpl extends CountMetrics {
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -88,7 +88,7 @@ public class HeatMapMetricsTest {
|
|||
public class HistogramMetricsMocker extends HistogramMetrics {
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -52,7 +52,7 @@ public class LongAvgMetricsTest {
|
|||
public class LongAvgMetricsImpl extends LongAvgMetrics {
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -54,7 +54,7 @@ public class MaxLongMetricsTest {
|
|||
public class MaxLongMetricsImpl extends MaxLongMetrics {
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,7 +73,7 @@ public class MetricsTest {
|
|||
public class MetricsMocker extends Metrics {
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ public class MinLongMetricsTest {
|
|||
public class MinLongMetricsImpl extends MinLongMetrics {
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -67,7 +67,7 @@ public class PercentMetricsTest {
|
|||
public class PercentMetricsImpl extends PercentMetrics {
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -118,7 +118,7 @@ public class PercentileMetricsTest {
|
|||
public class PercentileMetricsMocker extends PercentileMetrics {
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ public class PxxMetricsTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
public String id() {
|
||||
protected String id0() {
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue