Open brucelwl opened 1 month ago
https://github.com/alibaba/Sentinel/blob/195150bc745927429e9f14f501907310b46d702f/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricsReader.java#L54-L56
55行没必要为了获取时间戳而将字符串转成MetricNode对象, 直接通过字符串截取就行,
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字符串分割
ThinString
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);
https://github.com/alibaba/Sentinel/blob/195150bc745927429e9f14f501907310b46d702f/sentinel-core/src/main/java/com/alibaba/csp/sentinel/node/metric/MetricsReader.java#L54-L56
55行没必要为了获取时间戳而将字符串转成
MetricNode
对象, 直接通过字符串截取就行,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
字符串分割