You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by "songxiaosheng (via GitHub)" <gi...@apache.org> on 2023/07/11 00:47:12 UTC
[GitHub] [dubbo] songxiaosheng commented on a diff in pull request #12680: Performance opt
songxiaosheng commented on code in PR #12680:
URL: https://github.com/apache/dubbo/pull/12680#discussion_r1259021368
##########
dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/MethodStatComposite.java:
##########
@@ -55,11 +54,16 @@ public void initWrapper(List<MetricsKeyWrapper> metricsKeyWrappers) {
metricsKeyWrappers.forEach(appKey -> methodNumStats.put(appKey, new ConcurrentHashMap<>()));
}
- public void incrementMethodKey(MetricsKeyWrapper wrapper, Invocation invocation, int size) {
+ public void incrementMethodKey(MetricsKeyWrapper wrapper, MethodMetric methodMetric, int size) {
if (!methodNumStats.containsKey(wrapper)) {
return;
}
- methodNumStats.get(wrapper).computeIfAbsent(new MethodMetric(getApplicationModel(), invocation), k -> new AtomicLong(0L)).getAndAdd(size);
+ AtomicLong stat = methodNumStats.get(wrapper).get(methodMetric);
+ if (stat == null) {
Review Comment:
这个if是否多余了,直接调用putIfAbsent获取(数据不存在会自动添加)
##########
dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/RtStatComposite.java:
##########
@@ -82,41 +90,144 @@ private List<LongContainer<? extends Number>> initStats(MetricsPlaceValue placeV
}
public void calcApplicationRt(String registryOpType, Long responseTime) {
- for (LongContainer container : rtStats.stream().filter(longContainer -> longContainer.specifyType(registryOpType)).collect(Collectors.toList())) {
- Number current = (Number) ConcurrentHashMapUtils.computeIfAbsent(container, new ApplicationMetric(getApplicationModel()), container.getInitFunc());
+ ApplicationMetric key = new ApplicationMetric(getApplicationModel());
+ for (LongContainer container : rtStats.get(registryOpType)) {
+ Number current = (Number) container.get(key);
+ if (current == null) {
Review Comment:
这个if逻辑应该也可以缩减到一行代码
##########
dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/MethodStatComposite.java:
##########
@@ -55,11 +54,16 @@ public void initWrapper(List<MetricsKeyWrapper> metricsKeyWrappers) {
metricsKeyWrappers.forEach(appKey -> methodNumStats.put(appKey, new ConcurrentHashMap<>()));
}
- public void incrementMethodKey(MetricsKeyWrapper wrapper, Invocation invocation, int size) {
+ public void incrementMethodKey(MetricsKeyWrapper wrapper, MethodMetric methodMetric, int size) {
if (!methodNumStats.containsKey(wrapper)) {
return;
}
- methodNumStats.get(wrapper).computeIfAbsent(new MethodMetric(getApplicationModel(), invocation), k -> new AtomicLong(0L)).getAndAdd(size);
+ AtomicLong stat = methodNumStats.get(wrapper).get(methodMetric);
+ if (stat == null) {
Review Comment:
这个if是否多余了,直接调用putIfAbsent获取(数据不存在会自动添加)
##########
dubbo-metrics/dubbo-metrics-api/src/main/java/org/apache/dubbo/metrics/data/RtStatComposite.java:
##########
@@ -82,41 +90,144 @@ private List<LongContainer<? extends Number>> initStats(MetricsPlaceValue placeV
}
public void calcApplicationRt(String registryOpType, Long responseTime) {
- for (LongContainer container : rtStats.stream().filter(longContainer -> longContainer.specifyType(registryOpType)).collect(Collectors.toList())) {
- Number current = (Number) ConcurrentHashMapUtils.computeIfAbsent(container, new ApplicationMetric(getApplicationModel()), container.getInitFunc());
+ ApplicationMetric key = new ApplicationMetric(getApplicationModel());
+ for (LongContainer container : rtStats.get(registryOpType)) {
+ Number current = (Number) container.get(key);
+ if (current == null) {
Review Comment:
这个if逻辑应该也可以缩减到一行代码
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org