Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 避免字符串和MetricNode对象的转换,减少内存占用 #3464

Open
brucelwl opened this issue Oct 27, 2024 · 0 comments
Open

[BUG] 避免字符串和MetricNode对象的转换,减少内存占用 #3464

brucelwl opened this issue Oct 27, 2024 · 0 comments

Comments

@brucelwl
Copy link

while ((line = reader.readLine()) != null) {
MetricNode node = MetricNode.fromFatString(line);
long currentSecond = node.getTimestamp() / 1000;

55行没必要为了获取时间戳而将字符串转成MetricNode对象, 直接通过字符串截取就行,

int timestampIndex = s.indexOf("|");
String timestamp = Long.parseLong(s.substring(0, timestampIndex));

StringBuilder sb = new StringBuilder();
for (MetricNode node : list) {
sb.append(node.toThinString()).append("\n");
}

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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant