Sentinel
Sentinel copied to clipboard
[BUG] 避免字符串和MetricNode对象的转换,减少内存占用
https://github.com/alibaba/Sentinel/blob/195150bc745927429e9f14f501907310b46d702f/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricsReader.java#L54-L56
55行没必要为了获取时间戳而将字符串转成MetricNode对象, 直接通过字符串截取就行,
int timestampIndex = s.indexOf("|");
String timestamp = Long.parseLong(s.substring(0, timestampIndex));
https://github.com/alibaba/Sentinel/blob/195150bc745927429e9f14f501907310b46d702f/sentinel-transport/sentinel-transport-common/src/main/java/com/alibaba/csp/sentinel/command/handler/SendMetricCommandHandler.java#L97-L100
SendMetricCommandHandler中为了得到ThinString, 又将MetricNode转成字符串, MetricNode成了冗余转换, 会增加内存占用
不如直接采用FatString字符串分割
int timestampIndex = s.indexOf("|");
String timestamp = s.substring(0, timestampIndex);
int i = s.indexOf("|", timestampIndex + 20);
String metric = s.substring(i);
System.out.println(timestamp + metric);