You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@servicecomb.apache.org by ya...@apache.org on 2019/09/09 15:43:12 UTC
[servicecomb-java-chassis] branch master updated: [SCB-1475] ServiceCombServerStats.getFailedRate and getSuccessRate may arise an exception of java.lang.ArithmeticException: / by zero under concurrency scenarios
This is an automated email from the ASF dual-hosted git repository.
yaohaishi pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/servicecomb-java-chassis.git
The following commit(s) were added to refs/heads/master by this push:
new e351e6d [SCB-1475] ServiceCombServerStats.getFailedRate and getSuccessRate may arise an exception of java.lang.ArithmeticException: / by zero under concurrency scenarios
e351e6d is described below
commit e351e6df66d93aace7d8187963d533efe1590d2b
Author: Liu Huaizhou <li...@163.com>
AuthorDate: Mon Sep 2 16:53:24 2019 +0800
[SCB-1475] ServiceCombServerStats.getFailedRate and getSuccessRate may arise an exception of java.lang.ArithmeticException: / by zero under concurrency scenarios
---
.../servicecomb/loadbalance/ServiceCombServerStats.java | 14 ++++++++------
1 file changed, 8 insertions(+), 6 deletions(-)
diff --git a/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/ServiceCombServerStats.java b/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/ServiceCombServerStats.java
index b41e2da..5c50c74 100644
--- a/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/ServiceCombServerStats.java
+++ b/handlers/handler-loadbalance/src/main/java/org/apache/servicecomb/loadbalance/ServiceCombServerStats.java
@@ -147,17 +147,19 @@ public class ServiceCombServerStats {
}
public int getSuccessRate() {
- if (totalRequests.get() == 0L) {
- return 0;
- }
- return (int) (successRequests.get() * 100 / totalRequests.get());
+ return calcRequestRate(successRequests);
}
public int getFailedRate() {
- if (totalRequests.get() == 0L) {
+ return calcRequestRate(failedRequests);
+ }
+
+ private int calcRequestRate(AtomicLong requestCnt) {
+ long totalReqs = totalRequests.get();
+ if (totalReqs == 0L) {
return 0;
}
- return (int) (failedRequests.get() * 100 / totalRequests.get());
+ return (int) (requestCnt.get() * 100 / totalReqs);
}
public boolean isIsolated() {